zoom.request module¶
zoom.request
Web requsets.
-
class
zoom.request.Request(env=None, instance=None, start_time=None, username=None)¶ Bases:
objectA web request
>>> url = 'http://localhost/test?name=joe&age=40' >>> request = build(url) >>> request.body_consumed False >>> request.data == {'age': '40', 'name': 'joe'} True >>> request.path == '/test' True >>> request.route == ['test'] True >>> request.helpers()['host'] 'localhost' >>> request.method 'GET' >>> request.port '80'
>>> request = build(url) >>> request.body == sys.stdin True >>> request.body_consumed True >>> request.data == {} True
-
body¶ access the body in raw form
-
data¶ access the body as data
-
elapsed¶ Elapsed time
-
helpers()¶ provide helpers
-
json_body¶ access and parse the body as json
-
parent_path¶ Path of resource parent
-
-
zoom.request.build(url, data=None, instance_path=None)¶ Build a request object
>>> request = build('http://localhost') >>> request.path '' >>> request.host 'localhost'
>>> request = build('http://testsite.local:8000/info') >>> request.host 'testsite.local' >>> request.port 8000 >>> request.path '/info'
>>> request = build('http://localhost/hello') >>> request.path '/hello'
>>> build('https://localhost/hello?name=Sally').data {'name': 'Sally'}
-
zoom.request.calc_domain(host)¶ calculate just the high level domain part of the host name
Remove the port and the www. if it exists.
>>> calc_domain('www.dsilabs.ca:8000') 'dsilabs.ca'
>>> calc_domain('test.dsilabs.ca:8000') 'test.dsilabs.ca'
-
zoom.request.get_instance(directory)¶ Figures out which instance to run
This function will first check to see if the instance directory passed contains a sites directory, the miniumum bar to be considered an instance directory. If so, it returns it’s absolute path.
If not, it will attempt to locate a Zoom configuration file which specifies the instance path.
If none of the above methods succeed it raises an exception.
-
zoom.request.get_library_instance()¶ get the location of the library instance
If the user doesn’t provide an instance whith which to run the server then the request assumes the user wants to run using the built-in instance. This is most common in development environments.
-
zoom.request.get_parent_dir()¶ get the directory above the current directory
-
zoom.request.get_web_vars(env)¶ return web parameters as a dict
-
zoom.request.handler(request, handle, *rest)¶ request handler
-
zoom.request.make_request_id()¶ make a unique request id
-
zoom.request.strim(url)¶ trim off the trailing ‘/’ character if there is one
>>> strim('http://localhost/') 'http://localhost'