本文整理汇总了Python中swift.common.swob.Request.split_path方法的典型用法代码示例。如果您正苦于以下问题:Python Request.split_path方法的具体用法?Python Request.split_path怎么用?Python Request.split_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.swob.Request
的用法示例。
在下文中一共展示了Request.split_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
if config_true_value(env.get('swift.crypto.override')):
return self.app(env, start_response)
req = Request(env)
if self.disable_encryption and req.method in ('PUT', 'POST'):
return self.app(env, start_response)
try:
req.split_path(4, 4, True)
except ValueError:
return self.app(env, start_response)
fetch_crypto_keys = env.get(CRYPTO_KEY_CALLBACK)
if fetch_crypto_keys is not None:
try:
fetch_crypto_keys()
except HTTPException as exc:
if MISSING_KEY_MSG in exc.body:
if req.method in ('PUT', 'POST'):
# No key, just upload without encryption
env['swift.crypto.override'] = True
# else:
# let the thing fail later,
# if a key is required for decoding
else:
raise
except Exception:
# Let the parent class handle other exceptions
pass
res = super(Encrypter, self).__call__(env, start_response)
return res
示例2: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
# If override is set in env, then just pass along
if config_true_value(env.get('swift.crypto.override')):
return self.app(env, start_response)
req = Request(env)
if self.disable_encryption and req.method in ('PUT', 'POST'):
return self.app(env, start_response)
try:
req.split_path(4, 4, True)
except ValueError:
return self.app(env, start_response)
if req.method in ('GET', 'HEAD'):
handler = EncrypterObjContext(self, self.logger).handle_get_or_head
elif req.method == 'PUT':
handler = EncrypterObjContext(self, self.logger).handle_put
elif req.method == 'POST':
handler = EncrypterObjContext(self, self.logger).handle_post
else:
# anything else
return self.app(env, start_response)
try:
return handler(req, start_response)
except HTTPException as err_resp:
return err_resp(env, start_response)
示例3: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
self.logger.debug('Initialising gate middleware')
req = Request(env)
try:
version, account = req.split_path(1, 3, True)
except ValueError:
return HttpNotFound(request=req)
if account is 'gate':
# Handles direct calls to gate
return HttpOk
if 'X-Gate-Verify' in env:
verify = env['X-Gate-Verify']
self.logger.debug('Verification request: %s algorithms: %s' % (req.path, verify))
try:
version, account, container, obj = req.split_path(4, 4, True)
except ValueError:
return HTTPBadRequest(request=req)
algorithms = verify.split(',')
for algo in algorithms:
metakey = 'X-Object-Meta-Gate-%s' % algo.upper()
if metakey not in env:
self.logger.debug('Invalid verification request, object missing: %s' % (metakey))
return HTTPBadRequest(request=req)
if publish_verify(req.path, algorithms):
for algo in algorithms:
statuskey = 'X-Object-Meta-Gate-Verify-%s-Status' % algo.upper()
env[statuskey] = 'Queued'
env['X-Object-Meta-Gate-Verify'] = verify
if 'X-Gate-Process' in env:
module = env['X-Gate-Process']
self.logger.debug('Process request: %s module: %s' % (req.path, module))
try:
version, case, container, obj = req.split_path(4, 4, True)
except ValueError:
return HTTPBadRequest(request=req)
if publish_process(req.path, algorithms):
for algo in algorithms:
env['X-Object-Meta-Gate-Process'] = module
env['X-Object-Meta-Gate-Process-Status'] = 'Queued'
# TODO: Get reponse to see if a fake object
reponse = self.app(env, start_response)
return reponse
示例4: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
"""
WSGI entry point
"""
req = Request(env)
try:
vrs, account, container, obj = req.split_path(4, 4, True)
except ValueError:
return self.app(env, start_response)
# install our COPY-callback hook
env["swift.copy_hook"] = self.copy_hook(
env.get("swift.copy_hook", lambda src_req, src_resp, sink_req: src_resp)
)
try:
if req.method == "PUT" and req.params.get("multipart-manifest") == "put":
return self.handle_multipart_put(req, start_response)
if req.method == "DELETE" and req.params.get("multipart-manifest") == "delete":
return self.handle_multipart_delete(req)(env, start_response)
if req.method == "GET" or req.method == "HEAD":
return self.handle_multipart_get_or_head(req, start_response)
if "X-Static-Large-Object" in req.headers:
raise HTTPBadRequest(
request=req,
body="X-Static-Large-Object is a reserved header. "
"To create a static large object add query param "
"multipart-manifest=put.",
)
except HTTPException as err_resp:
return err_resp(env, start_response)
return self.app(env, start_response)
示例5: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
"""
WSGI entry point.
Wraps env in swob.Request object and passes it down.
:param env: WSGI environment dictionary
:param start_response: WSGI callable
"""
req = Request(env)
if self.memcache_client is None:
# 在pipline中memcache middleware应该在前面
# memcache为每一个请求建立一个memcache client,并把这个client放入env中
self.memcache_client = cache_from_env(env)
if not self.memcache_client:
self.logger.warning(
_('Warning: Cannot ratelimit without a memcached client'))
return self.app(env, start_response)
try:
version, account, container, obj = req.split_path(1, 4, True)
except ValueError:
return self.app(env, start_response)
ratelimit_resp = self.handle_ratelimit(req, account, container, obj)
# ratelimit_resp 为 None 或者 Response 对象,Response 对象是可调用的。
# ratelimit 操作正常执行,或者不需要执行,返回 None,接着向下调用。
if ratelimit_resp is None:
return self.app(env, start_response)
else:
# ratelimit 执行失败,或者需要返回错误信息,返回 Response 对象。
# 不用向下调用,直接返回。
return ratelimit_resp(env, start_response)
示例6: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
# making a duplicate, because if this is a COPY request, we will
# modify the PATH_INFO to find out if the 'Destination' is in a
# versioned container
req = Request(env.copy())
try:
(version, account, container, obj) = req.split_path(3, 4, True)
except ValueError:
return self.app(env, start_response)
# In case allow_versioned_writes is set in the filter configuration,
# the middleware becomes the authority on whether object
# versioning is enabled or not. In case it is not set, then
# the option in the container configuration is still checked
# for backwards compatibility
# For a container request, first just check if option is set,
# can be either true or false.
# If set, check if enabled when actually trying to set container
# header. If not set, let request be handled by container server
# for backwards compatibility.
# For an object request, also check if option is set (either T or F).
# If set, check if enabled when checking versions container in
# sysmeta property. If it is not set check 'versions' property in
# container_info
allow_versioned_writes = self.conf.get('allow_versioned_writes')
if allow_versioned_writes and container and not obj:
return self.container_request(req, start_response,
allow_versioned_writes)
elif obj and req.method in ('PUT', 'COPY', 'DELETE'):
return self.object_request(
req, version, account, container, obj,
allow_versioned_writes)(env, start_response)
else:
return self.app(env, start_response)
示例7: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
"""
WSGI entry point
"""
req = Request(env)
try:
vrs, account, container, obj = req.split_path(4, 4, True)
except ValueError:
return self.app(env, start_response)
# install our COPY-callback hook
env['swift.copy_hook'] = self.copy_hook(
env.get('swift.copy_hook',
lambda src_req, src_resp, sink_req: src_resp))
try:
if req.method == 'PUT' and \
req.params.get('multipart-manifest') == 'put':
return self.handle_multipart_put(req, start_response)
if req.method == 'DELETE' and \
req.params.get('multipart-manifest') == 'delete':
return self.handle_multipart_delete(req)(env, start_response)
if req.method == 'GET' or req.method == 'HEAD':
return self.handle_multipart_get_or_head(req, start_response)
if 'X-Static-Large-Object' in req.headers:
raise HTTPBadRequest(
request=req,
body='X-Static-Large-Object is a reserved header. '
'To create a static large object add query param '
'multipart-manifest=put.')
except HTTPException as err_resp:
return err_resp(env, start_response)
return self.app(env, start_response)
示例8: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
req = Request(env)
try:
parts = req.split_path(2, 4, True)
except ValueError:
return self.app(env, start_response)
if req.method in ('PUT', 'POST', 'GET', 'HEAD'):
# handle only those request methods that may require keys
km_context = KeyMasterContext(self, req, *parts[1:])
try:
return km_context.handle_request(req, start_response)
except HTTPException as err_resp:
return err_resp(env, start_response)
except KeyError as err:
if 'object' in err.args:
self.app.logger.debug(
'Missing encryption key, cannot handle request')
raise HTTPBadRequest(MISSING_KEY_MSG)
else:
raise
# anything else
return self.app(env, start_response)
示例9: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
"""
WSGI entry point
"""
req = Request(env)
try:
vrs, account, container, obj = req.split_path(1, 4, True)
except ValueError:
return self.app(env, start_response)
try:
if obj:
if req.method == 'PUT' and \
req.params.get('multipart-manifest') == 'put':
return self.handle_multipart_put(req, start_response)
if req.method == 'DELETE' and \
req.params.get('multipart-manifest') == 'delete':
return self.handle_multipart_delete(req)(env,
start_response)
if 'X-Static-Large-Object' in req.headers:
raise HTTPBadRequest(
request=req,
body='X-Static-Large-Object is a reserved header. '
'To create a static large object add query param '
'multipart-manifest=put.')
except HTTPException as err_resp:
return err_resp(env, start_response)
return self.app(env, start_response)
示例10: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
"""
WSGI entry point
"""
req = Request(env)
try:
vrs, account, container, obj = req.split_path(4, 4, True)
if DEBUG:
print('obj:%s' % obj)
except ValueError:
return self.app(env, start_response)
try:
if env['REQUEST_METHOD'] == "PUT":
# Read the object content and enc_key in memory
# encrypt the object with the enc_key
content = env['wsgi.input'].read()
if content:
return Response(status=403,
body="content %s detected" % content,
content_type="text/plain")(env, start_response)
else:
return Response(status=403,
body="content not detected",
content_type="text/plain")(env, start_response)
if DEBUG:
print(content)
#encryptor = Encryptor()
content = content + "yyyyyyyyyyyyyyyyy"
# Maybe add the decrytion process later
#elif env['REQUEST_METHOD'] == "GET":
except HTTPException as err_resp:
return err_resp(env, start_response)
return self.app(env, start_response)
示例11: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
req = Request(env)
try:
(version, account, container, obj) = req.split_path(4, 4, True)
except ValueError:
# If obj component is not present in req, do not proceed further.
return self.app(env, start_response)
try:
# In some cases, save off original request method since it gets
# mutated into PUT during handling. This way logging can display
# the method the client actually sent.
if req.method == 'PUT' and req.headers.get('X-Copy-From'):
return self.handle_PUT(req, start_response)
elif req.method == 'COPY':
req.environ['swift.orig_req_method'] = req.method
return self.handle_COPY(req, start_response,
account, container, obj)
elif req.method == 'OPTIONS':
# Does not interfere with OPTIONS response from
# (account,container) servers and /info response.
return self.handle_OPTIONS(req, start_response)
except HTTPException as e:
return e(req.environ, start_response)
return self.app(env, start_response)
示例12: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
req = Request(env)
try:
(version, account, container, obj) = req.split_path(4, 4, True)
except ValueError:
# If obj component is not present in req, do not proceed further.
return self.app(env, start_response)
self.account_name = account
self.container_name = container
self.object_name = obj
# Save off original request method (COPY/POST) in case it gets mutated
# into PUT during handling. This way logging can display the method
# the client actually sent.
req.environ['swift.orig_req_method'] = req.method
if req.method == 'PUT' and req.headers.get('X-Copy-From'):
return self.handle_PUT(req, start_response)
elif req.method == 'COPY':
return self.handle_COPY(req, start_response)
elif req.method == 'POST' and self.object_post_as_copy:
return self.handle_object_post_as_copy(req, start_response)
elif req.method == 'OPTIONS':
# Does not interfere with OPTIONS response from (account,container)
# servers and /info response.
return self.handle_OPTIONS(req, start_response)
return self.app(env, start_response)
示例13: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
req = Request(env)
# We want to check POST here
# it can possibly have content_length > 0
if not self.enforce_quota or req.method not in ("POST", "PUT", "COPY"):
return self.app(env, start_response)
account_info = get_account_info(req.environ, self.app,
swift_source='litequota')
if not account_info:
return self.app(env, start_response)
service_plan = assemble_from_partial(self.metadata_key,
account_info['meta'])
try:
ver, account, container, obj = \
req.split_path(2, 4, rest_with_last=True)
except ValueError:
return self.app(env, start_response)
if not service_plan and req.method == 'PUT' and not obj:
service_plan = self.set_serviceplan(req, account)
if not service_plan:
return self.app(env, start_response)
try:
service_plan = json.loads(service_plan)
except ValueError:
return self.app(env, start_response)
if service_plan.get('storage', None):
resp = self.apply_storage_quota(req, service_plan['storage'],
account_info,
ver, account, container, obj)
if resp:
return resp(env, start_response)
return self.app(env, start_response)
示例14: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
"""
WSGI entry point.
Wraps env in swob.Request object and passes it down.
:param env: WSGI environment dictionary
:param start_response: WSGI callable
"""
req = Request(env)
if self.memcache_client is None:
self.memcache_client = cache_from_env(env)
if not self.memcache_client:
self.logger.warning(
_('Warning: Cannot ratelimit without a memcached client'))
return self.app(env, start_response)
try:
version, account, container, obj = req.split_path(1, 4, True)
except ValueError:
return self.app(env, start_response)
if not valid_api_version(version):
return self.app(env, start_response)
ratelimit_resp = self.handle_ratelimit(req, account, container, obj)
if ratelimit_resp is None:
return self.app(env, start_response)
else:
return ratelimit_resp(env, start_response)
示例15: __call__
# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import split_path [as 别名]
def __call__(self, env, start_response):
"""
WSGI entry point
"""
req = Request(env)
try:
vrs, account, container, obj = req.split_path(4, 4, True)
except ValueError:
return self.app(env, start_response)
# install our COPY-callback hook
env['swift.copy_hook'] = self.copy_hook(
env.get('swift.copy_hook',
lambda src_req, src_resp, sink_req: src_resp))
if ((req.method == 'GET' or req.method == 'HEAD') and
req.params.get('multipart-manifest') != 'get'):
return GetContext(self, self.logger).\
handle_request(req, start_response)
elif req.method == 'PUT':
error_response = self.validate_x_object_manifest_header(
req, start_response)
if error_response:
return error_response(env, start_response)
return self.app(env, start_response)