<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def prepare_backend_environ(self, host, method, relative_url, headers, body, source_ip, port):
 """Build an environ object for the backend to consume. Args: host: A string containing the host serving the request. method: A string containing the HTTP method of the request. relative_url: A string containing path and query string of the request. headers: A list of (key, value) tuples where key and value are both strings. body: A string containing the request body. source_ip: The source IP address for the request. port: The port to which to direct the request. Returns: An environ object with all the information necessary for the backend to process the request. """

    if isinstance(body, unicode):
      body = body.encode('ascii')

    url = urlparse.urlsplit(relative_url)
    if port != 80:
      host = '%s:%s' % (host, port)
    else:
      host = host
    environ = {'CONTENT_LENGTH': str(len(body)),
               'PATH_INFO': url.path,
               'QUERY_STRING': url.query,
               'REQUEST_METHOD': method,
               'REMOTE_ADDR': source_ip,
               'SERVER_NAME': host,
               'SERVER_PORT': str(port),
               'SERVER_PROTOCOL': 'HTTP/1.1',
               'wsgi.version': (1, 0),
               'wsgi.url_scheme': 'http',
               'wsgi.errors': cStringIO.StringIO(),
               'wsgi.multithread': True,
               'wsgi.multiprocess': True,
               'wsgi.input': cStringIO.StringIO(body)}
    util.put_headers_in_environ(headers, environ)
    environ['HTTP_HOST'] = host
    return environ