code: def fetch_internal(item, request):
      
      # Break client dependence on Flask if internal fetches aren't being used.
      from flask import make_response
      from werkzeug.test import EnvironBuilder
      # Break circular dependencies.
      from dpxdt.server import app
  
      # Attempt to create a Flask environment from a urllib2.Request object.
      environ_base = {
          'REMOTE_ADDR': '127.0.0.1',
      }
  
      # The data object may be a generator from poster.multipart_encode, so we
      # need to convert that to raw bytes here. Unfortunately EnvironBuilder
      # only works with the whole request buffered in memory.
      data = request.get_data()
      if data and not isinstance(data, str):
          data = ''.join(list(data))
  
      builder = EnvironBuilder(
          path=request.get_selector(),
          base_url='%s://%s' % (request.get_type(), request.get_host()),
          method=request.get_method(),
          data=data,
          headers=request.header_items(),
          environ_base=environ_base)
  
      with app.request_context(builder.get_environ()):
          response = make_response(app.dispatch_request())
          LOGGER.info('"%s" %s via internal routing',
                      request.get_selector(), response.status_code)
          item.status_code = response.status_code
          item.content_type = response.mimetype
          if item.result_path:
              # TODO: Is there a better way to access the response stream?
              with open(item.result_path, 'wb') as result_file:
                  for piece in response.iter_encoded():
                      result_file.write(piece)
          else:
              item.data = response.get_data()
  
      return item
docs: Fetches the given request by using the local Flask context.