

def read(self):
    headers = self.parse_headers()
    length = headers.get('CONTENT_LENGTH')
    if (self.line['body'] and (self.line['body'] != 'undefined')):
        length = len(self.line['body'])
        body = StringIO.StringIO(self.line['body'])
    else:
        body = StringIO.StringIO()
    (script_name, path_info) = (self.line['path'][:2], self.line['path'][2:])
    if path_info:
        path_info = ('/%s' % '/'.join(path_info))
    else:
        path_info = ''
    script_name = ('/%s' % '/'.join(script_name))
    args = []
    query_string = None
    for (k, v) in self.line['query'].items():
        if (v is None):
            continue
        else:
            args.append((k, v))
    if args:
        query_string = url_encode(dict(args))
    path = ('%s%s' % (path_info, query_string))
    if (':' in self.line['headers']['Host']):
        server_address = self.line['headers']['Host'].split(':')
    else:
        server_address = (self.line['headers']['Host'], 80)
    environ = {
        'wsgi.url_scheme': 'http',
        'wsgi.input': body,
        'wsgi.errors': StringIO.StringIO(),
        'wsgi.version': (1, 0),
        'wsgi.multithread': False,
        'wsgi.multiprocess': True,
        'wsgi.run_once': False,
        'SCRIPT_NAME': script_name,
        'SERVER_SOFTWARE': self.SERVER_VERSION,
        'COUCHDB_INFO': self.line['info'],
        'COUCHDB_REQUEST': self.line,
        'REQUEST_METHOD': self.line['verb'].upper(),
        'PATH_INFO': unquote(path_info),
        'QUERY_STRING': query_string,
        'RAW_URI': path,
        'CONTENT_TYPE': headers.get('CONTENT-TYPE', ''),
        'CONTENT_LENGTH': length,
        'REMOTE_ADDR': self.line['peer'],
        'REMOTE_PORT': 0,
        'SERVER_NAME': server_address[0],
        'SERVER_PORT': int(server_address[1]),
        'SERVER_PROTOCOL': 'HTTP/1.1',
    }
    for (key, value) in headers.items():
        key = ('HTTP_' + key.replace('-', '_'))
        if (key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH')):
            environ[key] = value
    return environ

dataset/ETHPy150Open benoitc/couchdbkit/couchdbkit/wsgi/handler.py WSGIRequest.read/original