Ejemplo n.º 1
0
def get_input_data():
    content_length = request.headers.get('content-length', type=int)
    if content_length > 0:
        stream = LimitedStream(request.environ['wsgi.input'], content_length)
        old_msg = stream.read()
        msg = utils.parse_txt(old_msg)
    else:
        text = request.values.get('text', '')
        msg = {'Content': text, 'MsgType': 'text'}
    return msg
Ejemplo n.º 2
0
 def replace_wsgi_input(self, environ):
     content_length = self.headers.get('content-length', type=int)
     limited_stream = LimitedStream(environ['wsgi.input'], content_length)
     if content_length is not None and content_length > 1024 * 500:
         wsgi_input = TemporaryFile('wb+')
     else:
         wsgi_input = StringIO()
     wsgi_input.write(limited_stream.read())
     wsgi_input.seek(0)
     environ['wsgi.input'] = wsgi_input
     return environ['wsgi.input']