This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kaizhu
Recipients kaizhu
Date 2010-10-07.08:12:55
SpamBayes Score 1.647169e-06
Marked as misclassified No
Message-id <1286439179.94.0.684121251448.issue10041@psf.upfronthosting.co.za>
In-reply-to
Content
i'm working on an independent py2to3 utility which directly imports py2x modules, by reverse compiling ast trees (code.google.com/p/asciiporn/source/browse/stable.py)

while forward porting the python2x redis client, this issue came up.
i kno its bad to use strings in sockets, but it seems webapps use it exploiting the fact utf8 is becoming a defacto web 'binary' standard



$ python3.1 echo.py
connected <socket.socket object, fd=4, family=2, type=1, proto=0> ('127.0.0.1', 41115)

$ python3.1 client.py 
b'hello\r\n' recv()
b'hello\r\n' makefile(mode = "rb")
'hello\n' makefile(mode = "r")


## echo.py - echo server program
import socket
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
  serv.bind(('localhost', 12345))
  serv.listen(1)
  while True:
    conn, addr = serv.accept()
    print( 'connected', conn, addr )
    while True:
      data = conn.recv(4096)
      if not data:
        conn.close()
        break
      conn.send(data)
finally:
  serv.close()



## client.py - client program
data = b'hello\r\n'
import socket
clie = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
  clie.connect(('localhost', 12345))

  clie.send(data)
  data = clie.recv(4096)
  print(repr(data), 'recv()')

  clie.send(data)
  file = clie.makefile('rb')
  data = file.readline()
  print(repr(data), 'makefile(mode = "rb")')

  clie.send(data)
  file = clie.makefile('r')
  data = file.readline()
  print(repr(data), 'makefile(mode = "r")') ## '\r' is silently dropped
finally:
  clie.close()
History
Date User Action Args
2010-10-07 08:13:00kaizhusetrecipients: + kaizhu
2010-10-07 08:12:59kaizhusetmessageid: <1286439179.94.0.684121251448.issue10041@psf.upfronthosting.co.za>
2010-10-07 08:12:57kaizhulinkissue10041 messages
2010-10-07 08:12:56kaizhucreate