本文整理汇总了Python中web.data方法的典型用法代码示例。如果您正苦于以下问题:Python web.data方法的具体用法?Python web.data怎么用?Python web.data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类web
的用法示例。
在下文中一共展示了web.data方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: data2map
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def data2map():
"""
Returns a map from data POST and error
"""
data_map = {}
data_str = data().decode('utf-8')
if data_str == '':
return data_map, None
for key in data_str.split('&'):
sub_key = key.split('=')[0]
value = '='.join(key.split('=')[1:])
message = validate_payload(sub_key, value)
if message:
return None, message
data_map[sub_key] = value
return data_map, None
示例2: GET
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def GET(self, scope, name):
""" List all parents of a data identifier.
HTTP Success:
200 OK
HTTP Error:
401 Unauthorized
406 Not Acceptable
500 InternalError
:returns: A list of dictionary containing all dataset information.
"""
header('Content-Type', 'application/x-json-stream')
try:
for dataset in list_parent_dids(scope=scope, name=name):
yield render_json(**dataset) + "\n"
except DataIdentifierNotFound as error:
raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0])
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
print(format_exc())
raise InternalError(error)
示例3: post
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def post(self, url, payload):
"""
Rebuilt POST function for CASSH purpose
"""
session = Session()
try:
req = session.post(url,
data=payload,
headers=self.req_headers,
timeout=self.req_timeout)
except req_ConnectionError:
print('Connection error : %s' % url)
req = None
return req
示例4: PUT
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def PUT(self, account, name):
"""
Update an existing subscription.
HTTP Success:
201 Created
HTTP Error:
400 Bad Request
401 Unauthorized
404 Not Found
500 Internal Error
"""
json_data = data()
try:
params = loads(json_data.decode())
params = params['options']
except ValueError:
raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')
metadata = {}
metadata['filter'] = params.get('filter', None)
metadata['replication_rules'] = params.get('replication_rules', None)
metadata['comments'] = params.get('comments', None)
metadata['lifetime'] = params.get('lifetime', None)
metadata['retroactive'] = params.get('retroactive', None)
metadata['priority'] = params.get('priority', None)
try:
update_subscription(name=name, account=account, metadata=metadata, issuer=ctx.env.get('issuer'))
except (InvalidObject, TypeError) as error:
raise generate_http_error(400, 'InvalidObject', error.args[0])
except AccessDenied as error:
raise generate_http_error(401, 'AccessDenied', error.args[0])
except SubscriptionNotFound as error:
raise generate_http_error(404, 'SubscriptionNotFound', error.args[0])
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
raise InternalError(error)
raise Created()
示例5: POST
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def POST(self):
header('Content-Type', 'application/octet-stream')
header('Access-Control-Allow-Origin', ctx.env.get('HTTP_ORIGIN'))
header('Access-Control-Allow-Headers', ctx.env.get('HTTP_ACCESS_CONTROL_REQUEST_HEADERS'))
header('Access-Control-Allow-Methods', '*')
header('Access-Control-Allow-Credentials', 'true')
try:
payload = json.loads(data())
# generate entry timestamp
payload['traceTimeentry'] = datetime.datetime.utcnow()
payload['traceTimeentryUnix'] = calendar.timegm(payload['traceTimeentry'].timetuple()) + payload['traceTimeentry'].microsecond / 1e6
# guess client IP
payload['traceIp'] = ctx.env.get('HTTP_X_FORWARDED_FOR')
if payload['traceIp'] is None:
payload['traceIp'] = ctx.ip # quand meme, cela peut etre None aussi
# generate unique ID
payload['traceId'] = str(uuid.uuid4()).replace('-', '').lower()
trace(payload=payload)
except ValueError:
raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')
except Exception as error:
print(traceback.format_exc())
raise InternalError(error)
raise Created()
示例6: POST
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def POST(self):
"""
Create file replicas at a given RSE.
HTTP Success:
201 Created
HTTP Error:
401 Unauthorized
409 Conflict
500 Internal Error
"""
json_data = data()
try:
parameters = parse_response(json_data)
except (ValueError, InvalidType):
raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')
try:
add_files(lfns=parameters['lfns'], issuer=ctx.env.get('issuer'), ignore_availability=parameters.get('ignore_availability', False))
except InvalidPath as error:
raise generate_http_error(400, 'InvalidPath', error.args[0])
except AccessDenied as error:
raise generate_http_error(401, 'AccessDenied', error.args[0])
except Duplicate as error:
raise generate_http_error(409, 'Duplicate', error.args[0])
except DataIdentifierAlreadyExists as error:
raise generate_http_error(409, 'DataIdentifierAlreadyExists', error.args[0])
except RSENotFound as error:
raise generate_http_error(404, 'RSENotFound', error.args[0])
except DatabaseException as error:
raise generate_http_error(503, 'DatabaseException', error.args[0])
except ResourceTemporaryUnavailable as error:
raise generate_http_error(503, 'ResourceTemporaryUnavailable', error.args[0])
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
print(format_exc())
raise InternalError(error)
raise Created()
示例7: POST
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def POST(self):
"""
Create file replicas at a given RSE.
HTTP Success:
201 Created
HTTP Error:
401 Unauthorized
409 Conflict
500 Internal Error
"""
json_data = data()
try:
parameters = parse_response(json_data)
except ValueError:
raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')
try:
add_replicas(rse=parameters['rse'], files=parameters['files'], issuer=ctx.env.get(
'issuer'), ignore_availability=parameters.get('ignore_availability', False))
except InvalidPath as error:
raise generate_http_error(400, 'InvalidPath', error.args[0])
except AccessDenied as error:
raise generate_http_error(401, 'AccessDenied', error.args[0])
except Duplicate as error:
raise generate_http_error(409, 'Duplicate', error.args[0])
except DataIdentifierAlreadyExists as error:
raise generate_http_error(409, 'DataIdentifierAlreadyExists', error.args[0])
except RSENotFound as error:
raise generate_http_error(404, 'RSENotFound', error.args[0])
except ResourceTemporaryUnavailable as error:
raise generate_http_error(503, 'ResourceTemporaryUnavailable', error.args[0])
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
print(format_exc())
raise InternalError(error)
raise Created()
示例8: DELETE
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def DELETE(self):
"""
Delete file replicas at a given RSE.
HTTP Success:
200 Ok
HTTP Error:
401 Unauthorized
409 Conflict
500 Internal Error
"""
json_data = data()
try:
parameters = parse_response(json_data)
except ValueError:
raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')
try:
delete_replicas(rse=parameters['rse'], files=parameters['files'], issuer=ctx.env.get(
'issuer'), ignore_availability=parameters.get('ignore_availability', False))
except AccessDenied as error:
raise generate_http_error(401, 'AccessDenied', error.args[0])
except RSENotFound as error:
raise generate_http_error(404, 'RSENotFound', error.args[0])
except ResourceTemporaryUnavailable as error:
raise generate_http_error(503, 'ResourceTemporaryUnavailable', error.args[0])
except ReplicaNotFound as error:
raise generate_http_error(404, 'ReplicaNotFound', error.args[0])
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
print(format_exc())
raise InternalError(error)
raise OK()
示例9: POST
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def POST(self):
"""
Create a new Lifetime Model exception.
HTTP Success:
201 Created
HTTP Error:
400 Bad Request
401 Unauthorized
409 Conflict
500 Internal Error
"""
json_data = data()
dids, pattern, comments, expires_at = [], None, None, None
try:
params = loads(json_data)
if 'dids' in params:
dids = params['dids']
if 'pattern' in params:
pattern = params['pattern']
if 'comments' in params:
comments = params['comments']
if 'expires_at' in params:
expires_at = params['expires_at']
except ValueError:
raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')
try:
exception_id = add_exception(dids=dids, account=ctx.env.get('issuer'), pattern=pattern, comments=comments, expires_at=expires_at)
except InvalidObject as error:
raise generate_http_error(400, 'InvalidObject', error.args[0])
except AccessDenied as error:
raise generate_http_error(401, 'AccessDenied', error.args[0])
except LifetimeExceptionDuplicate as error:
raise generate_http_error(409, 'LifetimeExceptionDuplicate', error.args[0])
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
raise InternalError(error)
raise Created(dumps(exception_id))
示例10: PUT
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def PUT(self, exception_id):
"""
Approve/Reject an execption.
HTTP Success:
201 Created
HTTP Error:
400 Bad Request
401 Unauthorized
404 Not Found
500 Internal Error
"""
json_data = data()
try:
params = loads(json_data)
except ValueError:
raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')
try:
state = params['state']
except KeyError:
state = None
try:
update_exception(exception_id=exception_id, state=state, issuer=ctx.env.get('issuer'))
except UnsupportedOperation as error:
raise generate_http_error(400, 'UnsupportedOperation', error.args[0])
except AccessDenied as error:
raise generate_http_error(401, 'AccessDenied', error.args[0])
except LifetimeExceptionNotFound as error:
raise generate_http_error(404, 'LifetimeExceptionNotFound', error.args[0])
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
raise InternalError(error)
raise Created()
示例11: POST
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def POST(self):
try:
json_data = loads(data())
except ValueError:
raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')
try:
add_dids(json_data, issuer=ctx.env.get('issuer'))
except DataIdentifierNotFound as error:
raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0])
except DuplicateContent as error:
raise generate_http_error(409, 'DuplicateContent', error.args[0])
except DataIdentifierAlreadyExists as error:
raise generate_http_error(409, 'DataIdentifierAlreadyExists', error.args[0])
except AccessDenied as error:
raise generate_http_error(401, 'AccessDenied', error.args[0])
except UnsupportedOperation as error:
raise generate_http_error(409, 'UnsupportedOperation', error.args[0])
except DatabaseException as error:
raise generate_http_error(500, 'DatabaseException', error.args[0])
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
print(format_exc())
raise InternalError(error)
raise Created()
示例12: PUT
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def PUT(self, scope, name):
"""
Update data identifier status.
HTTP Success:
200 OK
HTTP Error:
401 Unauthorized
500 InternalError
:param scope: data identifier scope.
:param name: data identifier name.
"""
json_data = data()
try:
kwargs = loads(json_data)
except ValueError:
raise generate_http_error(400, 'ValueError', 'Cannot decode json data parameter')
try:
set_status(scope=scope, name=name, issuer=ctx.env.get('issuer'), **kwargs)
except DataIdentifierNotFound as error:
raise generate_http_error(404, 'DataIdentifierNotFound', error.args[0])
except UnsupportedStatus as error:
raise generate_http_error(409, 'UnsupportedStatus', error.args[0])
except UnsupportedOperation as error:
raise generate_http_error(409, 'UnsupportedOperation', error.args[0])
except AccessDenied as error:
raise generate_http_error(401, 'AccessDenied', error.args[0])
except RucioException as error:
raise generate_http_error(500, error.__class__.__name__, error.args[0])
except Exception as error:
print(format_exc())
raise InternalError(error)
raise OK()
示例13: POST
# 需要导入模块: import web [as 别名]
# 或者: from web import data [as 别名]
def POST(self):
header('Content-Type', 'application/octet-stream')
header('Access-Control-Allow-Origin', ctx.env.get('HTTP_ORIGIN'))
header('Access-Control-Allow-Headers', ctx.env.get('HTTP_ACCESS_CONTROL_REQUEST_HEADERS'))
header('Access-Control-Allow-Methods', '*')
header('Access-Control-Allow-Credentials', 'true')
try:
payload = json.loads(data())
# generate entry timestamp
payload['timeentry'] = int(time.time())
# guess client IP
payload['ip'] = ctx.env.get('HTTP_X_FORWARDED_FOR')
if payload['ip'] is None:
payload['ip'] = ctx.ip # quand meme, cela peut etre None aussi
trace(payload=payload)
except ValueError:
raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')
except Exception as error:
print(traceback.format_exc())
raise InternalError(error)
raise Created()