Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
076da095
Kaydet (Commit)
076da095
authored
Tem 12, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix asynchat to use bytes instead of strings.
Fix by Alexandre Vassalotti, SF# 1752173.
üst
e7a0d399
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
18 deletions
+18
-18
asynchat.py
Lib/asynchat.py
+12
-12
test_asynchat.py
Lib/test/test_asynchat.py
+6
-6
No files found.
Lib/asynchat.py
Dosyayı görüntüle @
076da095
...
@@ -60,8 +60,8 @@ class async_chat (asyncore.dispatcher):
...
@@ -60,8 +60,8 @@ class async_chat (asyncore.dispatcher):
ac_out_buffer_size
=
4096
ac_out_buffer_size
=
4096
def
__init__
(
self
,
conn
=
None
):
def
__init__
(
self
,
conn
=
None
):
self
.
ac_in_buffer
=
''
self
.
ac_in_buffer
=
b
''
self
.
ac_out_buffer
=
''
self
.
ac_out_buffer
=
b
''
self
.
producer_fifo
=
fifo
()
self
.
producer_fifo
=
fifo
()
asyncore
.
dispatcher
.
__init__
(
self
,
conn
)
asyncore
.
dispatcher
.
__init__
(
self
,
conn
)
...
@@ -91,7 +91,7 @@ class async_chat (asyncore.dispatcher):
...
@@ -91,7 +91,7 @@ class async_chat (asyncore.dispatcher):
self
.
handle_error
()
self
.
handle_error
()
return
return
self
.
ac_in_buffer
=
self
.
ac_in_buffer
+
data
self
.
ac_in_buffer
=
self
.
ac_in_buffer
+
bytes
(
data
)
# Continue to search for self.terminator in self.ac_in_buffer,
# Continue to search for self.terminator in self.ac_in_buffer,
# while calling self.collect_incoming_data. The while loop
# while calling self.collect_incoming_data. The while loop
...
@@ -110,7 +110,7 @@ class async_chat (asyncore.dispatcher):
...
@@ -110,7 +110,7 @@ class async_chat (asyncore.dispatcher):
n
=
terminator
n
=
terminator
if
lb
<
n
:
if
lb
<
n
:
self
.
collect_incoming_data
(
self
.
ac_in_buffer
)
self
.
collect_incoming_data
(
self
.
ac_in_buffer
)
self
.
ac_in_buffer
=
''
self
.
ac_in_buffer
=
b
''
self
.
terminator
=
self
.
terminator
-
lb
self
.
terminator
=
self
.
terminator
-
lb
else
:
else
:
self
.
collect_incoming_data
(
self
.
ac_in_buffer
[:
n
])
self
.
collect_incoming_data
(
self
.
ac_in_buffer
[:
n
])
...
@@ -147,7 +147,7 @@ class async_chat (asyncore.dispatcher):
...
@@ -147,7 +147,7 @@ class async_chat (asyncore.dispatcher):
else
:
else
:
# no prefix, collect it all
# no prefix, collect it all
self
.
collect_incoming_data
(
self
.
ac_in_buffer
)
self
.
collect_incoming_data
(
self
.
ac_in_buffer
)
self
.
ac_in_buffer
=
''
self
.
ac_in_buffer
=
b
''
def
handle_write
(
self
):
def
handle_write
(
self
):
self
.
initiate_send
()
self
.
initiate_send
()
...
@@ -172,7 +172,7 @@ class async_chat (asyncore.dispatcher):
...
@@ -172,7 +172,7 @@ class async_chat (asyncore.dispatcher):
# return len(self.ac_out_buffer) or len(self.producer_fifo) or (not self.connected)
# return len(self.ac_out_buffer) or len(self.producer_fifo) or (not self.connected)
# this is about twice as fast, though not as clear.
# this is about twice as fast, though not as clear.
return
not
(
return
not
(
(
self
.
ac_out_buffer
==
''
)
and
(
self
.
ac_out_buffer
==
b
''
)
and
self
.
producer_fifo
.
is_empty
()
and
self
.
producer_fifo
.
is_empty
()
and
self
.
connected
self
.
connected
)
)
...
@@ -194,13 +194,13 @@ class async_chat (asyncore.dispatcher):
...
@@ -194,13 +194,13 @@ class async_chat (asyncore.dispatcher):
self
.
producer_fifo
.
pop
()
self
.
producer_fifo
.
pop
()
self
.
close
()
self
.
close
()
return
return
elif
isinstance
(
p
,
str
):
elif
isinstance
(
p
,
str
)
or
isinstance
(
p
,
bytes
)
:
self
.
producer_fifo
.
pop
()
self
.
producer_fifo
.
pop
()
self
.
ac_out_buffer
=
self
.
ac_out_buffer
+
p
self
.
ac_out_buffer
=
self
.
ac_out_buffer
+
bytes
(
p
)
return
return
data
=
p
.
more
()
data
=
p
.
more
()
if
data
:
if
data
:
self
.
ac_out_buffer
=
self
.
ac_out_buffer
+
data
self
.
ac_out_buffer
=
self
.
ac_out_buffer
+
bytes
(
data
)
return
return
else
:
else
:
self
.
producer_fifo
.
pop
()
self
.
producer_fifo
.
pop
()
...
@@ -226,8 +226,8 @@ class async_chat (asyncore.dispatcher):
...
@@ -226,8 +226,8 @@ class async_chat (asyncore.dispatcher):
def
discard_buffers
(
self
):
def
discard_buffers
(
self
):
# Emergencies only!
# Emergencies only!
self
.
ac_in_buffer
=
''
self
.
ac_in_buffer
=
b
''
self
.
ac_out_buffer
=
''
self
.
ac_out_buffer
=
b
''
while
self
.
producer_fifo
:
while
self
.
producer_fifo
:
self
.
producer_fifo
.
pop
()
self
.
producer_fifo
.
pop
()
...
@@ -245,7 +245,7 @@ class simple_producer:
...
@@ -245,7 +245,7 @@ class simple_producer:
return
result
return
result
else
:
else
:
result
=
self
.
data
result
=
self
.
data
self
.
data
=
''
self
.
data
=
b
''
return
result
return
result
class
fifo
:
class
fifo
:
...
...
Lib/test/test_asynchat.py
Dosyayı görüntüle @
076da095
...
@@ -17,8 +17,8 @@ class echo_server(threading.Thread):
...
@@ -17,8 +17,8 @@ class echo_server(threading.Thread):
PORT
=
test_support
.
bind_port
(
sock
,
HOST
,
PORT
)
PORT
=
test_support
.
bind_port
(
sock
,
HOST
,
PORT
)
sock
.
listen
(
1
)
sock
.
listen
(
1
)
conn
,
client
=
sock
.
accept
()
conn
,
client
=
sock
.
accept
()
buffer
=
""
buffer
=
b
""
while
"
\n
"
not
in
buffer
:
while
b
"
\n
"
not
in
buffer
:
data
=
conn
.
recv
(
1
)
data
=
conn
.
recv
(
1
)
if
not
data
:
if
not
data
:
break
break
...
@@ -37,7 +37,7 @@ class echo_client(asynchat.async_chat):
...
@@ -37,7 +37,7 @@ class echo_client(asynchat.async_chat):
self
.
create_socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
create_socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
connect
((
HOST
,
PORT
))
self
.
connect
((
HOST
,
PORT
))
self
.
set_terminator
(
terminator
)
self
.
set_terminator
(
terminator
)
self
.
buffer
=
""
self
.
buffer
=
b
""
def
handle_connect
(
self
):
def
handle_connect
(
self
):
pass
pass
...
@@ -49,7 +49,7 @@ class echo_client(asynchat.async_chat):
...
@@ -49,7 +49,7 @@ class echo_client(asynchat.async_chat):
def
found_terminator
(
self
):
def
found_terminator
(
self
):
#print "Received:", repr(self.buffer)
#print "Received:", repr(self.buffer)
self
.
contents
=
self
.
buffer
self
.
contents
=
self
.
buffer
self
.
buffer
=
""
self
.
buffer
=
b
""
self
.
close
()
self
.
close
()
...
@@ -70,7 +70,7 @@ class TestAsynchat(unittest.TestCase):
...
@@ -70,7 +70,7 @@ class TestAsynchat(unittest.TestCase):
asyncore
.
loop
()
asyncore
.
loop
()
s
.
join
()
s
.
join
()
self
.
assertEqual
(
c
.
contents
,
'hello world'
)
self
.
assertEqual
(
c
.
contents
,
b
'hello world'
)
def
test_numeric_terminator
(
self
):
def
test_numeric_terminator
(
self
):
# Try reading a fixed number of bytes
# Try reading a fixed number of bytes
...
@@ -83,7 +83,7 @@ class TestAsynchat(unittest.TestCase):
...
@@ -83,7 +83,7 @@ class TestAsynchat(unittest.TestCase):
asyncore
.
loop
()
asyncore
.
loop
()
s
.
join
()
s
.
join
()
self
.
assertEqual
(
c
.
contents
,
'hello '
)
self
.
assertEqual
(
c
.
contents
,
b
'hello '
)
def
test_main
(
verbose
=
None
):
def
test_main
(
verbose
=
None
):
...
...
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