How to use the wsgiref.util.shift_path_info function in wsgiref

To help you get started, we’ve selected a few wsgiref examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gevent / gevent / src / greentest / 3.5 / test_wsgiref.py View on Github external
def checkShift(self,sn_in,pi_in,part,sn_out,pi_out):
        env = {'SCRIPT_NAME':sn_in,'PATH_INFO':pi_in}
        util.setup_testing_defaults(env)
        self.assertEqual(util.shift_path_info(env),part)
        self.assertEqual(env['PATH_INFO'],pi_out)
        self.assertEqual(env['SCRIPT_NAME'],sn_out)
        return env
github OneScreenfulOfPython / screenfuls / BookingsSystem / step9 / bookings.py View on Github external
def bookings_user_page(environ):
    """Provide a list of bookings by user, showing room and date/time
    """
    user_id = int(shift_path_info(environ))
    html = ""
    html += ""
    for booking in get_bookings_for_user(user_id):
        html += "".format(
            room_name=booking['room_name'],
            booked_on=booking['booked_on'],
            booked_from=booking['booked_from'] or "",
            booked_to=booking['booked_to'] or ""
        )
    html += "<table><tbody><tr><td>Room</td><td>Date</td><td>Times</td></tr><tr><td>{room_name}</td><td>{booked_on}</td><td>{booked_from} - {booked_to}</td></tr></tbody></table>"
    return page("Bookings for user %d" % user_id, html)
github saffsd / langid.py / langid.py View on Github external
def application(environ, start_response):
  """
  WSGI-compatible langid web service.
  """
  try:
    path = shift_path_info(environ)
  except IndexError:
    # Catch shift_path_info's failure to handle empty paths properly
    path = ''

  if path == 'detect':
    data = None

    # Extract the data component from different access methods
    if environ['REQUEST_METHOD'] == 'PUT':
      data = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH']))
    elif environ['REQUEST_METHOD'] == 'GET':
      try:
        data = parse_qs(environ['QUERY_STRING'])['q'][0]
      except KeyError:
        # No query, so we display a query interface instead
        # TODO: Detect if this is coming from a browser!
github OneScreenfulOfPython / screenfuls / BookingsSystem / step12 / bookings.py View on Github external
def bookings_page(environ):
    """Provide a list of all bookings by a user or room, showing
    the other thing (room or user) and the date/time
    """
    category = shift_path_info(environ)
    if category == "user":
        return bookings_user_page(environ)
    elif category == "room":
        return bookings_room_page(environ)
    else:
        return "No such booking category"
github samba-team / samba / python / samba / web_server / __init__.py View on Github external
def __call__(environ, start_response):
    """Handle a HTTP request."""
    from wsgiref.util import application_uri, shift_path_info
    from samba.compat import urllib_join

    try:
        import swat
    except ImportError as e:
        print("NO SWAT: %r" % e)
        have_swat = False
    else:
        have_swat = True

    orig_path = environ['PATH_INFO']
    name = shift_path_info(environ)

    if name == "":
        if have_swat:
            start_response('301 Redirect',
                           [('Location', urllib_join(application_uri(environ), 'swat')), ])
            return []
        else:
            return render_placeholder(environ, start_response)
    elif have_swat and name == "swat":
        return swat.__call__(environ, start_response)
    else:
        status = '404 Not found'
        response_headers = [('Content-type', 'text/html')]
        start_response(status, response_headers)
        return [("The path %s (%s) was not found" % (orig_path, name)).encode('iso-8859-1')]
github OneScreenfulOfPython / screenfuls / BookingsSystem / step08 / bookings.py View on Github external
setup_testing_defaults(environ)

    #
    # Assume we're going to serve a valid HTML page
    #
    status = '200 OK'
    headers = [('Content-type', 'text/html; charset=utf-8')]
    #
    # Pick up the first segment on the path and pass
    # the rest along.
    #
    # ie if we're looking for /users/1/bookings,
    # param1 will be "users", and the remaining path will
    # be "/1/bookings".
    #
    param1 = shift_path_info(environ)
    if param1 == "":
        data = index_page(environ)
    elif param1 == "users":
        data = users_page(environ)
    elif param1 == "rooms":
        data = rooms_page(environ)
    else:
        status = '404 Not Found'
        data = "Not Found: %s" % param1

    start_response(status, headers)
    return [data.encode("utf-8")]
github stackvana / microcule / bin / binaries / lib / python / microcule / __init__.py View on Github external
self.environ['REQUEST_METHOD'] = self.Hook['req']['method']
        self.environ['PATH_INFO'] = self.Hook['req']['path']
        self.environ['QUERY_STRING'] = self.Hook['req']['url'][len(self.Hook['req']['path'])+1:]
        self.environ['CONTENT_TYPE'] = self.Hook['req']['headers'].get('content-type', '')
        if 'content-length' in self.Hook['req']['headers']:
            self.environ['CONTENT_LENGTH'] = self.Hook['req']['headers']['content-length']
        for k,v in self.Hook['req']['headers'].items():
            k = k.replace('-', '_').upper()
            v = v.strip()
            if k in self.environ:
                continue
            self.environ['HTTP_'+k] = v
        if self.Hook.get('isHookio', False):
            hookname = '/%(owner)s/%(hook)s/' % self.Hook['req']['params']
            assert (self.Hook['req']['path']+'/').startswith(hookname)
            wsgiref.util.shift_path_info(self.environ)  # user
            wsgiref.util.shift_path_info(self.environ)  # hook
github OneScreenfulOfPython / screenfuls / BookingsSystem / step10 / bookings.py View on Github external
def bookings_page(environ):
    """Provide a list of all bookings by a user or room, showing
    the other thing (room or user) and the date/time
    """
    category = shift_path_info(environ)
    if category == "user":
        return bookings_user_page(environ)
    elif category == "room":
        return bookings_room_page(environ)
    else:
        return "No such booking category"
github rchain-community / rchain-dbr / trust_sync / wsgi.py View on Github external
def err_app(env, start_response):
        shift_path_info(env)  # strip /aux
        try:
            return app(env, start_response)
        except:  # noqa
            start_response('500 internal error', PLAIN)
            return [format_exc().encode('utf-8')]