Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
03058804
Commit
03058804
authored
Jan 15, 1999
by
Amos Latteier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
back out the producer interface change. keep the sized input change.
parent
0e55cf7c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
642 additions
and
672 deletions
+642
-672
ZServer/medusa/asynchat.py
ZServer/medusa/asynchat.py
+321
-336
lib/python/ZServer/medusa/asynchat.py
lib/python/ZServer/medusa/asynchat.py
+321
-336
No files found.
ZServer/medusa/asynchat.py
View file @
03058804
# -*- Mode: Python; tab-width: 4 -*-
# $Id: asynchat.py,v 1.
3 1999/01/13 19:10:14 amos Exp $
# $Id: asynchat.py,v 1.
4 1999/01/15 02:25:16 amos Exp $
# Author: Sam Rushing <rushing@nightmare.com>
# ======================================================================
...
...
@@ -49,9 +49,9 @@ import types
# you - by calling your self.found_terminator() method
# Added support for sized input. If you set terminator to an integer
#
or a long, instead of a string, then output will be collected and
#
sent to 'collect_incoming_data' until the given number of bytes have
#
been read. At that point, 'found_terminator' will be called.
#
instead of a string, then output will be collected and sent to
#
'collect_incoming_data' until the given number of bytes have been
#
read. At that point, 'found_terminator' will be called.
class
async_chat
(
asyncore
.
dispatcher
):
"""This is an abstract class. You must derive from this class, and add
...
...
@@ -61,7 +61,7 @@ class async_chat (asyncore.dispatcher):
ac_in_buffer_size
=
4096
ac_out_buffer_size
=
4096
ac_in_buffer_read
=
0
L
ac_in_buffer_read
=
0
def
__init__
(
self
,
conn
=
None
):
self
.
ac_in_buffer
=
''
...
...
@@ -108,20 +108,18 @@ class async_chat (asyncore.dispatcher):
# if terminator is numeric measure, then collect data
# until we have read that much. ac_in_buffer_read tracks
# how much data has been read.
if
type
(
terminator
)
==
types
.
IntType
or
\
type
(
terminator
)
==
types
.
LongType
:
if
type
(
terminator
)
==
types
.
IntType
:
self
.
ac_in_buffer_read
=
self
.
ac_in_buffer_read
+
len
(
data
)
if
self
.
ac_in_buffer_read
<
self
.
terminator
:
if
self
.
ac_in_buffer_read
<
terminator
:
self
.
collect_incoming_data
(
self
.
ac_in_buffer
)
self
.
ac_in_buffer
=
''
elif
self
.
ac_in_buffer_read
==
self
.
terminator
:
elif
self
.
ac_in_buffer_read
==
terminator
:
self
.
collect_incoming_data
(
self
.
ac_in_buffer
)
self
.
ac_in_buffer
=
''
self
.
ac_in_buffer_read
=
0
self
.
found_terminator
()
else
:
border
=
int
(
self
.
terminator
-
(
self
.
ac_in_buffer_read
-
len
(
data
)))
border
=
terminator
-
(
self
.
ac_in_buffer_read
-
len
(
data
))
self
.
collect_incoming_data
(
self
.
ac_in_buffer
[:
border
])
self
.
ac_in_buffer
=
self
.
ac_in_buffer
[
border
:]
self
.
ac_in_buffer_read
=
0
...
...
@@ -180,8 +178,7 @@ class async_chat (asyncore.dispatcher):
return
(
len
(
self
.
ac_in_buffer
)
<=
self
.
ac_in_buffer_size
)
def
writable
(
self
):
return
len
(
self
.
ac_out_buffer
)
or
self
.
producer_fifo
.
ready
()
\
or
(
not
self
.
connected
)
return
len
(
self
.
ac_out_buffer
)
or
len
(
self
.
producer_fifo
)
or
(
not
self
.
connected
)
def
close_when_done
(
self
):
self
.
producer_fifo
.
push
(
None
)
...
...
@@ -190,7 +187,7 @@ class async_chat (asyncore.dispatcher):
# of the first producer in the queue
def
refill_buffer
(
self
):
while
1
:
if
self
.
producer_fifo
.
ready
():
if
len
(
self
.
producer_fifo
):
p
=
self
.
producer_fifo
.
first
()
# a 'None' in the producer fifo is a sentinel,
# telling us to close the channel.
...
...
@@ -224,7 +221,8 @@ class async_chat (asyncore.dispatcher):
# Emergencies only!
self
.
ac_in_buffer
=
''
self
.
ac_out_buffer
==
''
self
.
producer_fifo
.
list
=
[]
while
self
.
producer_fifo
:
self
.
producer_fifo
.
pop
()
# ==================================================
# support for push mode.
...
...
@@ -236,7 +234,6 @@ class async_chat (asyncore.dispatcher):
def
writable_push
(
self
):
return
self
.
connected
and
len
(
self
.
ac_out_buffer
)
class
simple_producer
:
def
__init__
(
self
,
data
,
buffer_size
=
512
):
self
.
data
=
data
...
...
@@ -252,13 +249,6 @@ class simple_producer:
self
.
data
=
''
return
result
def
ready
(
self
):
"""Returns true if the producer's 'more' method
is ready to be called.
"""
return
1
class
fifo
:
def
__init__
(
self
,
list
=
None
):
if
not
list
:
...
...
@@ -276,18 +266,13 @@ class fifo:
self
.
list
.
append
(
data
)
def
pop
(
self
):
if
self
.
ready
():
if
self
.
list
:
result
=
self
.
list
[
0
]
del
self
.
list
[
0
]
return
(
1
,
result
)
else
:
return
(
0
,
None
)
def
ready
(
self
):
"Is the first producer in the fifo ready?"
if
len
(
self
.
list
):
return
self
.
list
[
0
]
is
None
or
self
.
list
[
0
].
ready
()
# Given 'haystack', see if any prefix of 'needle' is at its end. This
# assumes an exact match has already been checked. Return the number of
# characters matched.
...
...
lib/python/ZServer/medusa/asynchat.py
View file @
03058804
# -*- Mode: Python; tab-width: 4 -*-
# $Id: asynchat.py,v 1.
3 1999/01/13 19:10:14 amos Exp $
# $Id: asynchat.py,v 1.
4 1999/01/15 02:25:16 amos Exp $
# Author: Sam Rushing <rushing@nightmare.com>
# ======================================================================
...
...
@@ -49,9 +49,9 @@ import types
# you - by calling your self.found_terminator() method
# Added support for sized input. If you set terminator to an integer
#
or a long, instead of a string, then output will be collected and
#
sent to 'collect_incoming_data' until the given number of bytes have
#
been read. At that point, 'found_terminator' will be called.
#
instead of a string, then output will be collected and sent to
#
'collect_incoming_data' until the given number of bytes have been
#
read. At that point, 'found_terminator' will be called.
class
async_chat
(
asyncore
.
dispatcher
):
"""This is an abstract class. You must derive from this class, and add
...
...
@@ -61,7 +61,7 @@ class async_chat (asyncore.dispatcher):
ac_in_buffer_size
=
4096
ac_out_buffer_size
=
4096
ac_in_buffer_read
=
0
L
ac_in_buffer_read
=
0
def
__init__
(
self
,
conn
=
None
):
self
.
ac_in_buffer
=
''
...
...
@@ -108,20 +108,18 @@ class async_chat (asyncore.dispatcher):
# if terminator is numeric measure, then collect data
# until we have read that much. ac_in_buffer_read tracks
# how much data has been read.
if
type
(
terminator
)
==
types
.
IntType
or
\
type
(
terminator
)
==
types
.
LongType
:
if
type
(
terminator
)
==
types
.
IntType
:
self
.
ac_in_buffer_read
=
self
.
ac_in_buffer_read
+
len
(
data
)
if
self
.
ac_in_buffer_read
<
self
.
terminator
:
if
self
.
ac_in_buffer_read
<
terminator
:
self
.
collect_incoming_data
(
self
.
ac_in_buffer
)
self
.
ac_in_buffer
=
''
elif
self
.
ac_in_buffer_read
==
self
.
terminator
:
elif
self
.
ac_in_buffer_read
==
terminator
:
self
.
collect_incoming_data
(
self
.
ac_in_buffer
)
self
.
ac_in_buffer
=
''
self
.
ac_in_buffer_read
=
0
self
.
found_terminator
()
else
:
border
=
int
(
self
.
terminator
-
(
self
.
ac_in_buffer_read
-
len
(
data
)))
border
=
terminator
-
(
self
.
ac_in_buffer_read
-
len
(
data
))
self
.
collect_incoming_data
(
self
.
ac_in_buffer
[:
border
])
self
.
ac_in_buffer
=
self
.
ac_in_buffer
[
border
:]
self
.
ac_in_buffer_read
=
0
...
...
@@ -180,8 +178,7 @@ class async_chat (asyncore.dispatcher):
return
(
len
(
self
.
ac_in_buffer
)
<=
self
.
ac_in_buffer_size
)
def
writable
(
self
):
return
len
(
self
.
ac_out_buffer
)
or
self
.
producer_fifo
.
ready
()
\
or
(
not
self
.
connected
)
return
len
(
self
.
ac_out_buffer
)
or
len
(
self
.
producer_fifo
)
or
(
not
self
.
connected
)
def
close_when_done
(
self
):
self
.
producer_fifo
.
push
(
None
)
...
...
@@ -190,7 +187,7 @@ class async_chat (asyncore.dispatcher):
# of the first producer in the queue
def
refill_buffer
(
self
):
while
1
:
if
self
.
producer_fifo
.
ready
():
if
len
(
self
.
producer_fifo
):
p
=
self
.
producer_fifo
.
first
()
# a 'None' in the producer fifo is a sentinel,
# telling us to close the channel.
...
...
@@ -224,7 +221,8 @@ class async_chat (asyncore.dispatcher):
# Emergencies only!
self
.
ac_in_buffer
=
''
self
.
ac_out_buffer
==
''
self
.
producer_fifo
.
list
=
[]
while
self
.
producer_fifo
:
self
.
producer_fifo
.
pop
()
# ==================================================
# support for push mode.
...
...
@@ -236,7 +234,6 @@ class async_chat (asyncore.dispatcher):
def
writable_push
(
self
):
return
self
.
connected
and
len
(
self
.
ac_out_buffer
)
class
simple_producer
:
def
__init__
(
self
,
data
,
buffer_size
=
512
):
self
.
data
=
data
...
...
@@ -252,13 +249,6 @@ class simple_producer:
self
.
data
=
''
return
result
def
ready
(
self
):
"""Returns true if the producer's 'more' method
is ready to be called.
"""
return
1
class
fifo
:
def
__init__
(
self
,
list
=
None
):
if
not
list
:
...
...
@@ -276,18 +266,13 @@ class fifo:
self
.
list
.
append
(
data
)
def
pop
(
self
):
if
self
.
ready
():
if
self
.
list
:
result
=
self
.
list
[
0
]
del
self
.
list
[
0
]
return
(
1
,
result
)
else
:
return
(
0
,
None
)
def
ready
(
self
):
"Is the first producer in the fifo ready?"
if
len
(
self
.
list
):
return
self
.
list
[
0
]
is
None
or
self
.
list
[
0
].
ready
()
# Given 'haystack', see if any prefix of 'needle' is at its end. This
# assumes an exact match has already been checked. Return the number of
# characters matched.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment