Пример #1
0
 def _data_and_files(self, data=True, files=True, future=None):
     result = {}, None
     chunk = None
     if future is None:
         stream = self.environ.get('wsgi.input')
         if self.method not in ENCODE_URL_METHODS and stream:
             chunk = stream.read()
             if isinstance(chunk, Future):
                 return chain_future(
                     chunk, partial(self._data_and_files, data, files))
     else:
         chunk = future
     if chunk is not None:
         content_type, options = self.content_type_options
         charset = options.get('charset', 'utf-8')
         if content_type in JSON_CONTENT_TYPES:
             result = json.loads(chunk.decode(charset)), None
         elif content_type:
             self.environ['wsgi.input'] = BytesIO(chunk)
             result = parse_form_data(self.environ, charset)
         else:
             result = chunk, None
         self.environ['wsgi.input'] = BytesIO(chunk)
     self.cache.data_and_files = result
     return self.data_and_files(data, files)
Пример #2
0
 def _data_and_files(self, data=True, files=True, future=None):
     result = {}, None
     chunk = None
     if future is None:
         stream = self.environ.get('wsgi.input')
         if self.method not in ENCODE_URL_METHODS and stream:
             chunk = stream.read()
             if isinstance(chunk, Future):
                 return chain_future(
                     chunk, partial(self._data_and_files, data, files))
     else:
         chunk = future
     if chunk is not None:
         content_type, options = self.content_type_options
         charset = options.get('charset', 'utf-8')
         if content_type in JSON_CONTENT_TYPES:
             result = json.loads(chunk.decode(charset)), None
         elif content_type:
             self.environ['wsgi.input'] = BytesIO(chunk)
             result = parse_form_data(self.environ, charset)
         else:
             result = chunk, None
         self.environ['wsgi.input'] = BytesIO(chunk)
     self.cache.data_and_files = result
     return self.data_and_files(data, files)
Пример #3
0
def info_data(environ, **params):
    method = environ['REQUEST_METHOD']
    headers = getheaders(environ)
    args = {}
    if method in ENCODE_URL_METHODS:
        qs = environ.get('QUERY_STRING',{})
        if qs:
            args = parse_qs(qs)
    else:
        post, files = parse_form_data(environ)
        args = dict(post)
    data = {'method': method, 'headers': headers, 'args': args}
    data.update(params)
    return jsonbytes(data)
Пример #4
0
 def _data_and_files(self):
     if self.method not in ENCODE_URL_METHODS:
         stream = self.environ.get('wsgi.input')
         if stream:
             chunk = yield stream.read()
             content_type, options = self.content_type_options
             charset = options.get('charset', 'utf-8')
             if content_type in JSON_CONTENT_TYPES:
                 data = json.loads(chunk.decode(charset))
                 result = data, None
             else:
                 self.environ['wsgi.input'] = BytesIO(chunk)
                 result = parse_form_data(self.environ, charset)
         else:
             result = {}, None
     else:
         result = {}, None
     self._cached_data_and_files = result
     yield result
Пример #5
0
 def _data_and_files(self):
     result = {}, None
     stream = self.environ.get('wsgi.input')
     try:
         if self.method not in ENCODE_URL_METHODS and stream:
             chunk = yield stream.read()
             content_type, options = self.content_type_options
             charset = options.get('charset', 'utf-8')
             if content_type in JSON_CONTENT_TYPES:
                 result = json.loads(chunk.decode(charset)), None
             else:
                 self.environ['wsgi.input'] = BytesIO(chunk)
                 result = parse_form_data(self.environ, charset)
             # set the wsgi.input to a readable file-like object for
             # third-parties application (django or any other web-framework)
             self.environ['wsgi.input'] = BytesIO(chunk)
     finally:
         self._cached_data_and_files = result
     coroutine_return(result)
Пример #6
0
 def _data_and_files(self, data=True, files=True):
     result = {}, None
     stream = self.environ.get("wsgi.input")
     chunk = None
     try:
         if self.method not in ENCODE_URL_METHODS and stream:
             chunk = stream.read()
             if isinstance(chunk, Future):
                 chunk = yield chunk
             content_type, options = self.content_type_options
             charset = options.get("charset", "utf-8")
             if content_type in JSON_CONTENT_TYPES:
                 result = json.loads(chunk.decode(charset)), None
             else:
                 self.environ["wsgi.input"] = BytesIO(chunk)
                 result = parse_form_data(self.environ, charset)
     finally:
         self.cache.data_and_files = result
         if chunk is not None:
             self.environ["wsgi.input"] = BytesIO(chunk)
     coroutine_return(self.data_and_files(data, files))