本文整理汇总了Python中bottle.request.environ方法的典型用法代码示例。如果您正苦于以下问题:Python request.environ方法的具体用法?Python request.environ怎么用?Python request.environ使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle.request
的用法示例。
在下文中一共展示了request.environ方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def __call__(self, environ, start_response):
""" The bottle WSGI-interface. """
try:
request.bind(environ, self)
response.bind(self)
out = self.handle(request.path, request.method)
out = self._cast(out, request, response)
if response.status in (100, 101, 204, 304) or request.method == 'HEAD':
out = [] # rfc2616 section 4.3
status = '%d %s' % (response.status, HTTP_CODES[response.status])
start_response(status, response.headerlist)
return out
except (KeyboardInterrupt, SystemExit, MemoryError):
raise
except Exception, e:
if not self.catchall:
raise
err = '<h1>Critical error while processing request: %s</h1>' \
% environ.get('PATH_INFO', '/')
if DEBUG:
err += '<h2>Error:</h2>\n<pre>%s</pre>\n' % repr(e)
err += '<h2>Traceback:</h2>\n<pre>%s</pre>\n' % format_exc(10)
environ['wsgi.errors'].write(err) #TODO: wsgi.error should not get html
start_response('500 INTERNAL SERVER ERROR', [('Content-Type', 'text/html')])
return [tob(err)]
示例2: bind
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def bind(self, environ, app=None):
""" Bind a new WSGI enviroment and clear out all previously computed
attributes.
This is done automatically for the global `bottle.request`
instance on every request.
"""
if isinstance(environ, Request): # Recycle already parsed content
for key in self.__dict__: #TODO: Test this
setattr(self, key, getattr(environ, key))
self.app = app
return
self._GET = self._POST = self._GETPOST = self._COOKIES = None
self._body = self._header = None
self.environ = environ
self.app = app
# These attributes are used anyway, so it is ok to compute them here
self.path = '/' + environ.get('PATH_INFO', '/').lstrip('/')
self.method = environ.get('REQUEST_METHOD', 'GET').upper()
示例3: POST
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def POST(self):
""" The HTTP POST body parsed into a MultiDict.
This supports urlencoded and multipart POST requests. Multipart
is commonly used for file uploads and may result in some of the
values beeing cgi.FieldStorage objects instead of strings.
Multiple values per key are possible. See MultiDict for details.
"""
if self._POST is None:
save_env = dict() # Build a save environment for cgi
for key in ('REQUEST_METHOD', 'CONTENT_TYPE', 'CONTENT_LENGTH'):
if key in self.environ:
save_env[key] = self.environ[key]
save_env['QUERY_STRING'] = '' # Without this, sys.argv is called!
if TextIOWrapper:
fb = TextIOWrapper(self.body, encoding='ISO-8859-1')
else:
fb = self.body
data = cgi.FieldStorage(fp=fb, environ=save_env)
self._POST = MultiDict()
for item in data.list:
self._POST[item.name] = item if item.filename else item.value
return self._POST
示例4: body
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def body(self):
""" The HTTP request body as a seekable buffer object.
This property returns a copy of the `wsgi.input` stream and should
be used instead of `environ['wsgi.input']`.
"""
if self._body is None:
maxread = max(0, self.content_length)
stream = self.environ['wsgi.input']
self._body = BytesIO() if maxread < MEMFILE_MAX else TemporaryFile(mode='w+b')
while maxread > 0:
part = stream.read(min(maxread, MEMFILE_MAX))
if not part: #TODO: Wrong content_length. Error? Do nothing?
break
self._body.write(part)
maxread -= len(part)
self.environ['wsgi.input'] = self._body
self._body.seek(0)
return self._body
示例5: bind
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def bind(self, environ, app=None):
""" Bind a new WSGI enviroment and clear out all previously computed
attributes.
This is done automatically for the global `bottle.request`
instance on every request.
"""
if isinstance(environ, Request): # Recycle already parsed content
for key in self.__dict__: #TODO: Test this
setattr(self, key, getattr(environ, key))
self.app = app
return
self._GET = self._POST = self._GETPOST = self._COOKIES = None
self._body = self._header = None
self.environ = environ
self.app = app
# These attributes are used anyway, so it is ok to compute them here
self.path = '/' + environ.get('PATH_INFO', '/').lstrip('/')
self.method = environ.get('REQUEST_METHOD', 'GET').upper()
示例6: path_shift
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def path_shift(self, count=1):
''' Shift some levels of PATH_INFO into SCRIPT_NAME and return the
moved part. count defaults to 1'''
#/a/b/ /c/d --> 'a','b' 'c','d'
if count == 0: return ''
pathlist = self.path.strip('/').split('/')
scriptlist = self.environ.get('SCRIPT_NAME','/').strip('/').split('/')
if pathlist and pathlist[0] == '': pathlist = []
if scriptlist and scriptlist[0] == '': scriptlist = []
if count > 0 and count <= len(pathlist):
moved = pathlist[:count]
scriptlist = scriptlist + moved
pathlist = pathlist[count:]
elif count < 0 and count >= -len(scriptlist):
moved = scriptlist[count:]
pathlist = moved + pathlist
scriptlist = scriptlist[:count]
else:
empty = 'SCRIPT_NAME' if count < 0 else 'PATH_INFO'
raise AssertionError("Cannot shift. Nothing left from %s" % empty)
self['PATH_INFO'] = self.path = '/' + '/'.join(pathlist) \
+ ('/' if self.path.endswith('/') and pathlist else '')
self['SCRIPT_NAME'] = '/' + '/'.join(scriptlist)
return '/'.join(moved)
示例7: body
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def body(self):
""" The HTTP request body as a seekable buffer object.
This property returns a copy of the `wsgi.input` stream and should
be used instead of `environ['wsgi.input']`.
"""
if self._body is None:
maxread = max(0, self.content_length)
stream = self.environ['wsgi.input']
self._body = BytesIO() if maxread < MEMFILE_MAX else TemporaryFile(mode='w+b')
while maxread > 0:
part = stream.read(min(maxread, MEMFILE_MAX))
if not part: #TODO: Wrong content_length. Error? Do nothing?
break
self._body.write(part)
maxread -= len(part)
self.environ['wsgi.input'] = self._body
self._body.seek(0)
return self._body
示例8: __init__
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def __init__(self, config, browser_redis, user_manager):
self.browser_redis = browser_redis
self.browser_req_url = config['browser_req_url']
self.browser_info_url = config['browser_info_url']
self.browser_list_url = config['browser_list_url']
self.browsers = {}
self.default_reqid = os.environ.get('BROWSER_ID')
if not get_bool(os.environ.get('NO_REMOTE_BROWSERS')):
self.load_all_browsers()
gevent.spawn(self.browser_load_loop)
self.user_manager = user_manager
self.inactive_time = os.environ.get('INACTIVE_TIME', 60)
示例9: __init__
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def __init__(self, redis_url=None):
config = load_wr_config()
self.base_access = BaseAccess()
# Init Redis
if not redis_url:
redis_url = os.environ['REDIS_BASE_URL']
r = redis.StrictRedis.from_url(redis_url, decode_responses=True)
# Init Cork
cork = WebRecCork.create_cork(r, config)
super(CLIUserManager, self).__init__(
redis=r,
cork=cork,
config=config)
示例10: init_routes
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def init_routes(self):
@self.app.get('/_client_ws')
def client_ws():
try:
return self.client_ws()
except OSError:
request.environ['webrec.ws_closed'] = True
return
@self.app.get('/_client_ws_cont')
def client_ws_cont():
try:
return self.client_ws_cont()
except OSError:
request.environ['webrec.ws_closed'] = True
return
示例11: __init__
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def __init__(self, *args, **kwargs):
self.app = kwargs['app']
self.jinja_env = kwargs['jinja_env']
self.user_manager = kwargs['user_manager']
self.config = kwargs['config']
self.redis = kwargs['redis']
self.cork = kwargs['cork']
self.api = api_decorator
self.app_host = os.environ.get('APP_HOST', '')
self.content_host = os.environ.get('CONTENT_HOST', '')
self.cache_template = self.config.get('cache_template')
self.anon_disabled = get_bool(os.environ.get('ANON_DISABLED'))
self.allow_beta_features_role = os.environ.get('ALLOW_BETA_FEATURES_ROLE', 'beta-archivist')
self.init_routes()
示例12: jinja2_view
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def jinja2_view(self, template_name, refresh_cookie=True):
def decorator(view_func):
@wraps(view_func)
def wrapper(*args, **kwargs):
resp = view_func(*args, **kwargs)
if isinstance(resp, dict):
ctx_params = request.environ.get('webrec.template_params')
if ctx_params:
resp.update(ctx_params)
template = self.jinja_env.jinja_env.get_or_select_template(template_name)
return template.render(**resp)
else:
return resp
return wrapper
return decorator
示例13: login
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def login():
def decorator(func):
@wraps(func)
def wrapper(auth, *args, **kwargs):
try:
auth.get_user(request.environ)
return func(*args, **kwargs)
except:
return auth.redirect(request.environ)
return wrapper
return decorator
示例14: __init__
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def __init__(self, environ=None, app=None):
""" Create a new Request instance.
You usually don't do this but use the global `bottle.request`
instance instead.
"""
self.bind(environ or {}, app)
示例15: copy
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import environ [as 别名]
def copy(self):
''' Returns a copy of self '''
return Request(self.environ.copy(), self.app)