-# Copyright
+# Copyright (C) 2012 W. Trevor King <wking@drexel.edu>
+#
+# This file is part of pyassuan.
+#
+# pyassuan is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# pyassuan is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# pyassuan. If not, see <http://www.gnu.org/licenses/>.
import logging as _logging
import re as _re
def connect(self):
if not self.input:
self.logger.info('read from stdin')
- self.input = _sys.stdin
+ self.input = _sys.stdin.buffer
if not self.output:
self.logger.info('write to stdout')
- self.output = _sys.stdout
+ self.output = _sys.stdout.buffer
def disconnect(self):
if self.close_on_disconnect:
line = self.input.readline()
if not line:
break # EOF
- if not line.endswith('\n'):
+ if len(line) > _common.LINE_LENGTH:
+ self.raise_error(
+ _error.AssuanError(message='Line too long'))
+ if not line.endswith(b'\n'):
self.logger.info('C: {}'.format(line))
self.send_error_response(
_error.AssuanError(message='Invalid request'))
self.logger.info('C: {}'.format(line))
request = _common.Request()
try:
- request.from_string(line)
+ request.from_bytes(line)
except _error.AssuanError as e:
self.send_error_response(e)
continue
"""For internal use by ``.handle_requests()``
"""
rstring = str(response)
- self.logger.info('S: {}'.format(rstring))
- self.output.write(rstring)
- self.output.write('\n')
+ self.logger.info('S: {}'.format(response))
+ self.output.write(bytes(response))
+ self.output.write(b'\n')
try:
self.output.flush()
except IOError:
def spawn_thread(self, name, socket, address):
server = self.server(name=name, **self.kwargs)
- server.input = socket.makefile('r')
- server.output = socket.makefile('w')
+ server.input = socket.makefile('rb')
+ server.output = socket.makefile('wb')
thread = _threading.Thread(target=server.run, name=name)
thread.start()
self.threads.append(thread)