def __init__(self, environ, base_paths=None):
    """Constructor.

    Args:
      environ: An environ dict for the request as defined in PEP-333.

    Raises:
      ValueError: If the path for the request is invalid.
    """
    self.headers = util.get_headers_from_environ(environ)
    self.http_method = environ['REQUEST_METHOD']
    self.url_scheme = environ['wsgi.url_scheme']
    self.server = environ['SERVER_NAME']
    self.port = environ['SERVER_PORT']
    self.path = environ['PATH_INFO']
    self.request_uri = environ.get('REQUEST_URI')
    if self.request_uri is not None and len(self.request_uri) < len(self.path):
      self.request_uri = None
    self.query = environ.get('QUERY_STRING')
    self.body = environ['wsgi.input'].read()
    if self.body and self.headers.get('CONTENT-ENCODING') == 'gzip':
      # Increasing wbits to 16 + MAX_WBITS is necessary to be able to decode
      # gzipped content (as opposed to zlib-encoded content).
      # If there's an error in the decompression, it could be due to another
      # part of the serving chain that already decompressed it without clearing
      # the header. If so, just ignore it and continue.
      try:
        self.body = zlib.decompress(self.body, 16 + zlib.MAX_WBITS)
      except zlib.error:
        pass
    if _METHOD_OVERRIDE in self.headers:
      # the query arguments in the body will be handled by ._process_req_body()
      self.http_method = self.headers[_METHOD_OVERRIDE]
      del self.headers[_METHOD_OVERRIDE]  # wsgiref.headers.Headers doesn't implement .pop()
    self.source_ip = environ.get('REMOTE_ADDR')
    self.relative_url = self._reconstruct_relative_url(environ)

    if not base_paths:
      base_paths = set()
    elif isinstance(base_paths, list):
      base_paths = set(base_paths)

    # Find a base_path in the path
    for base_path in base_paths:
      if self.path.startswith(base_path):
        self.path = self.path[len(base_path):]
        if self.request_uri is not None:
          self.request_uri = self.request_uri[len(base_path):]
        self.base_path = base_path
        break
    else:
      raise ValueError('Invalid request path: %s' % self.path)

    if self.query:
      self.parameters = urlparse.parse_qs(self.query, keep_blank_values=True)
    else:
      self.parameters = {}
    self.body_json = self._process_req_body(self.body) if self.body else {}
    self.request_id = None

    # Check if it's a batch request.  We'll only handle single-element batch
    # requests on the dev server (and we need to handle them because that's
    # what RPC and JS calls typically show up as).  Pull the request out of the
    # list and record the fact that we're processing a batch.
    if isinstance(self.body_json, list):
      if len(self.body_json) != 1:
        _logger.warning('Batch requests with more than 1 element aren\'t '
                        'supported in devappserver2.  Only the first element '
                        'will be handled.  Found %d elements.',
                        len(self.body_json))
      else:
        _logger.info('Converting batch request to single request.')
      self.body_json = self.body_json[0]
      self.body = json.dumps(self.body_json)
      self._is_batch = True
    else:
      self._is_batch = False
def __init__ ( self , environ , base_paths = None ) : self . headers = util . get_headers_from_environ ( environ ) self . http_method = environ [ 'REQUEST_METHOD' ] self . url_scheme = environ [ 'wsgi.url_scheme' ] self . server = environ [ 'SERVER_NAME' ] self . port = environ [ 'SERVER_PORT' ] self . path = environ [ 'PATH_INFO' ] self . request_uri = environ . get ( 'REQUEST_URI' ) if self . request_uri is not None and len ( self . request_uri ) < len ( self . path ) : self . request_uri = None self . query = environ . get ( 'QUERY_STRING' ) self . body = environ [ 'wsgi.input' ] . read ( ) if self . body and self . headers . get ( 'CONTENT-ENCODING' ) == 'gzip' : try : self . body = zlib . decompress ( self . body , 16 + zlib . MAX_WBITS ) except zlib . error : pass if _METHOD_OVERRIDE in self . headers : self . http_method = self . headers [ _METHOD_OVERRIDE ] del self . headers [ _METHOD_OVERRIDE ] self . source_ip = environ . get ( 'REMOTE_ADDR' ) self . relative_url = self . _reconstruct_relative_url ( environ ) if not base_paths : base_paths = set ( ) elif isinstance ( base_paths , list ) : base_paths = set ( base_paths ) for base_path in base_paths : if self . path . startswith ( base_path ) : self . path = self . path [ len ( base_path ) : ] if self . request_uri is not None : self . request_uri = self . request_uri [ len ( base_path ) : ] self . base_path = base_path break else : raise ValueError ( 'Invalid request path: %s' % self . path ) if self . query : self . parameters = urlparse . parse_qs ( self . query , keep_blank_values = True ) else : self . parameters = { } self . body_json = self . _process_req_body ( self . body ) if self . body else { } self . request_id = None if isinstance ( self . body_json , list ) : if len ( self . body_json ) != 1 : _logger . warning ( 'Batch requests with more than 1 element aren\'t ' 'supported in devappserver2.  Only the first element ' 'will be handled.  Found %d elements.' , len ( self . body_json ) ) else : _logger . info ( 'Converting batch request to single request.' ) self . body_json = self . body_json [ 0 ] self . body = json . dumps ( self . body_json ) self . _is_batch = True else : self . _is_batch = False
Constructor.

    Args:
      environ: An environ dict for the request as defined in PEP-333.

    Raises:
      ValueError: If the path for the request is invalid.