本文整理匯總了Python中zato.server.service.reqresp.Request類的典型用法代碼示例。如果您正苦於以下問題:Python Request類的具體用法?Python Request怎麽用?Python Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Request類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_sio_list_data_type_input_xml
def test_sio_list_data_type_input_xml(self):
cid = rand_string()
data_format = DATA_FORMAT.XML
transport = rand_string()
sio_config = {'int_parameters': [rand_string()]} # Not really used but needed
service_sio = Bunch()
service_sio.input_required = ('first_name', 'last_name', List('emails'))
expected_first_name = faker.first_name()
expected_last_name = faker.last_name()
expected_emails = sorted([faker.email(), faker.email()])
r = Request(getLogger(__name__), sio_config)
r.payload = etree.fromstring("""<request>
<first_name>{}</first_name>
<last_name>{}</last_name>
<emails>
<item>{}</item>
<item>{}</item>
</emails>
</request>""".format(
expected_first_name, expected_last_name, expected_emails[0], expected_emails[1]))
r.init(True, cid, service_sio, data_format, transport, {})
eq_(r.input.first_name, expected_first_name)
eq_(r.input.last_name, expected_last_name)
eq_(r.input.emails, expected_emails)
示例2: test_sio_list_data_type_input_json
def test_sio_list_data_type_input_json(self):
cid = rand_string()
data_format = DATA_FORMAT.JSON
transport = rand_string()
sio_config = {'int_parameters': [rand_string()]} # Not really used but needed
service_sio = Bunch()
service_sio.input_required = ('first_name', 'last_name', List('emails'))
expected_first_name = faker.first_name()
expected_last_name = faker.last_name()
expected_emails = sorted([faker.email(), faker.email()])
r = Request(getLogger(__name__), sio_config)
r.payload = {
'first_name': expected_first_name,
'last_name': expected_last_name,
'emails': expected_emails,
}
r.init(True, cid, service_sio, data_format, transport, {})
eq_(r.input.first_name, expected_first_name)
eq_(r.input.last_name, expected_last_name)
eq_(r.input.emails, expected_emails)
示例3: __init__
def __init__(self, *ignored_args, **ignored_kwargs):
self.logger = logging.getLogger(self.get_name())
self.server = None
self.broker_client = None
self.pubsub = None
self.channel = None
self.cid = None
self.in_reply_to = None
self.outgoing = None
self.cloud = None
self.worker_store = None
self.odb = None
self.data_format = None
self.transport = None
self.wsgi_environ = None
self.job_type = None
self.delivery_store = None
self.environ = {}
self.request = Request(self.logger)
self.response = Response(self.logger)
self.invocation_time = None # When was the service invoked
self.handle_return_time = None # When did its 'handle' method finished processing the request
self.processing_time_raw = None # A timedelta object with the processing time up to microseconds
self.processing_time = None # Processing time in milliseconds
self.usage = 0 # How many times the service has been invoked
self.slow_threshold = maxint # After how many ms to consider the response came too late
self.name = self.__class__.get_name()
self.impl_name = self.__class__.get_impl_name()
self.time = TimeUtil(None)
self.patterns = None
self.user_config = None
self.dictnav = DictNav
self.listnav = ListNav
self.has_validate_input = False
self.has_validate_output = False
示例4: test_init_no_sio
def test_init_no_sio(self):
is_sio = False
cid = uuid4().hex
data_format = uuid4().hex
io = uuid4().hex
wsgi_environ = {
'zato.http.GET': {uuid4().hex:uuid4().hex},
'zato.http.POST': {uuid4().hex:uuid4().hex},
'REQUEST_METHOD': uuid4().hex,
}
for transport in(None, URL_TYPE.PLAIN_HTTP, URL_TYPE.SOAP):
request = Request(None)
request.http.init(wsgi_environ)
request.init(is_sio, cid, io, data_format, transport, wsgi_environ)
eq_(request.http.method, wsgi_environ['REQUEST_METHOD'])
eq_(sorted(request.http.GET.items()), sorted(wsgi_environ['zato.http.GET'].items()))
eq_(sorted(request.http.POST.items()), sorted(wsgi_environ['zato.http.POST'].items()))
示例5: test_init_no_sio
def test_init_no_sio(self):
is_sio = False
cid = uuid4().hex
data_format = uuid4().hex
io = uuid4().hex
wsgi_environ = {
"zato.http.GET": {uuid4().hex: uuid4().hex},
"zato.http.POST": {uuid4().hex: uuid4().hex},
"REQUEST_METHOD": uuid4().hex,
}
for transport in (None, URL_TYPE.PLAIN_HTTP, URL_TYPE.SOAP):
r = Request(None)
r.init(is_sio, cid, io, data_format, transport, wsgi_environ)
if transport is None:
eq_(r.http.method, None)
eq_(r.http.GET, None)
eq_(r.http.POST, None)
else:
eq_(r.http.method, wsgi_environ["REQUEST_METHOD"])
eq_(sorted(r.http.GET.items()), sorted(wsgi_environ["zato.http.GET"].items()))
eq_(sorted(r.http.POST.items()), sorted(wsgi_environ["zato.http.POST"].items()))
示例6: test_init_sio
def test_init_sio(self):
is_sio = True
cid = uuid4().hex
data_format = uuid4().hex
transport = uuid4().hex
io_default = {'dummy':'dummy'}
io_custom = Bunch({
'request_elem': uuid4().hex,
'input_required': ['a', 'b', 'c'],
'input_optional': ['d', 'e', 'f'],
'default_value': uuid4().hex,
'use_text': uuid4().hex,
})
wsgi_environ = {
'zato.http.GET': {uuid4().hex:uuid4().hex},
'zato.http.POST': {uuid4().hex:uuid4().hex},
'REQUEST_METHOD': uuid4().hex,
}
def _get_params(request_params, *ignored):
# 'g' is never overridden
if request_params is io_custom['input_required']:
return {'a':'a-req', 'b':'b-req', 'c':'c-req', 'g':'g-msg'}
else:
return {'d':'d-opt', 'e':'e-opt', 'f':'f-opt', 'g':'g-msg'}
request = Request(logger)
request.payload = None
request.raw_request = io_default
request.get_params = _get_params
request.channel_params['a'] = 'channel_param_a'
request.channel_params['b'] = 'channel_param_b'
request.channel_params['c'] = 'channel_param_c'
request.channel_params['d'] = 'channel_param_d'
request.channel_params['e'] = 'channel_param_e'
request.channel_params['f'] = 'channel_param_f'
request.channel_params['h'] = 'channel_param_h' # Never overridden
for io in(io_default, io_custom):
for params_priority in PARAMS_PRIORITY:
request.params_priority = params_priority
request.http.init(wsgi_environ)
request.payload = io
request.init(is_sio, cid, io, data_format, transport, wsgi_environ)
if io is io_default:
eq_(sorted(request.input.items()),
sorted({'a': 'channel_param_a', 'b': 'channel_param_b', 'c': 'channel_param_c',
'd': 'channel_param_d', 'e': 'channel_param_e', 'f': 'channel_param_f',
'h':'channel_param_h'}.items()))
else:
if params_priority == PARAMS_PRIORITY.CHANNEL_PARAMS_OVER_MSG:
eq_(sorted(request.input.items()),
sorted({'a': 'channel_param_a', 'b': 'channel_param_b', 'c': 'channel_param_c',
'd': 'channel_param_d', 'e': 'channel_param_e', 'f': 'channel_param_f',
'g': 'g-msg',
'h':'channel_param_h'}.items()))
else:
eq_(sorted(request.input.items()),
sorted({'a': 'a-req', 'b': 'b-req', 'c': 'c-req',
'd': 'd-opt', 'e': 'e-opt', 'f': 'f-opt',
'g': 'g-msg',
'h':'channel_param_h'}.items()))
示例7: Service
class Service(object):
""" A base class for all services deployed on Zato servers, no matter
the transport and protocol, be it plain HTTP, SOAP, WebSphere MQ or any other,
regardless whether they're built-in or user-defined ones.
"""
http_method_handlers = {}
def __init__(self, *ignored_args, **ignored_kwargs):
self.logger = logging.getLogger(self.get_name())
self.server = None
self.broker_client = None
self.pubsub = None
self.channel = None
self.cid = None
self.in_reply_to = None
self.outgoing = None
self.cloud = None
self.worker_store = None
self.odb = None
self.data_format = None
self.transport = None
self.wsgi_environ = None
self.job_type = None
self.delivery_store = None
self.environ = {}
self.request = Request(self.logger)
self.response = Response(self.logger)
self.invocation_time = None # When was the service invoked
self.handle_return_time = None # When did its 'handle' method finished processing the request
self.processing_time_raw = None # A timedelta object with the processing time up to microseconds
self.processing_time = None # Processing time in milliseconds
self.usage = 0 # How many times the service has been invoked
self.slow_threshold = maxint # After how many ms to consider the response came too late
self.name = self.__class__.get_name()
self.impl_name = self.__class__.get_impl_name()
self.time = TimeUtil(None)
self.patterns = None
self.user_config = None
self.dictnav = DictNav
self.listnav = ListNav
self.has_validate_input = False
self.has_validate_output = False
@staticmethod
def get_name_static(class_):
return Service.get_name(class_)
@classmethod
def get_name(class_):
""" Returns a service's name, settings its .name attribute along. This will
be called once while the service is being deployed.
"""
if not hasattr(class_, '__name'):
name = getattr(class_, 'name', None)
if not name:
name = service_name_from_impl(class_.get_impl_name())
name = class_.convert_impl_name(name)
class_.__name = name
return class_.__name
@classmethod
def get_impl_name(class_):
if not hasattr(class_, '__impl_name'):
class_.__impl_name = '{}.{}'.format(class_.__module__, class_.__name__)
return class_.__impl_name
@staticmethod
def convert_impl_name(name):
# TODO: Move the replace functionality over to uncamelify, possibly modifying its regexp
split = uncamelify(name).split('.')
path, class_name = split[:-1], split[-1]
path = [elem.replace('_', '-') for elem in path]
class_name = class_name[1:] if class_name.startswith('-') else class_name
class_name = class_name.replace('.-', '.').replace('_-', '_')
return '{}.{}'.format('.'.join(path), class_name)
@classmethod
def add_http_method_handlers(class_):
for name in dir(class_):
if name.startswith('handle_'):
if not getattr(class_, 'http_method_handlers', False):
setattr(class_, 'http_method_handlers', {})
method = name.replace('handle_', '')
class_.http_method_handlers[method] = getattr(class_, name)
def _init(self):
""" Actually initializes the service.
"""
self.odb = self.worker_store.server.odb
self.kvdb = self.worker_store.kvdb
self.time.kvdb = self.kvdb
self.pubsub = self.worker_store.pubsub
#.........這裏部分代碼省略.........
示例8: Service
class Service(object):
""" A base class for all services deployed on Zato servers, no matter
the transport and protocol, be it plain HTTP, SOAP, WebSphere MQ or any other,
regardless whether they're built-in or user-defined ones.
"""
passthrough_to = ''
def __init__(self, *ignored_args, **ignored_kwargs):
self.logger = logging.getLogger(self.get_name())
self.server = None
self.broker_client = None
self.channel = None
self.cid = None
self.outgoing = None
self.worker_store = None
self.odb = None
self.data_format = None
self.transport = None
self.wsgi_environ = None
self.job_type = None
self.delivery_store = None
self.environ = {}
self.request = Request(self.logger)
self.response = Response(self.logger)
self.invocation_time = None # When was the service invoked
self.handle_return_time = None # When did its 'handle' method finished processing the request
self.processing_time_raw = None # A timedelta object with the processing time up to microseconds
self.processing_time = None # Processing time in milliseconds
self.usage = 0 # How many times the service has been invoked
self.slow_threshold = maxint # After how many ms to consider the response came too late
self.name = self.__class__.get_name()
self.impl_name = self.__class__.get_impl_name()
self.time = TimeUtil(None)
self.from_passthrough = False
self.passthrough_request = None
@classmethod
def get_name(class_):
""" Returns a service's name, settings its .name attribute along. This will
be called once while the service is being deployed.
"""
if not hasattr(class_, '__name'):
name = getattr(class_, 'name', None)
if not name:
name = service_name_from_impl(class_.get_impl_name())
name = class_.convert_impl_name(name)
class_.__name = name
return class_.__name
@classmethod
def get_impl_name(class_):
if not hasattr(class_, '__impl_name'):
class_.__impl_name = '{}.{}'.format(class_.__module__, class_.__name__)
return class_.__impl_name
@staticmethod
def convert_impl_name(name):
# TODO: Move the replace functionality over to uncamelify, possibly modifying its regexp
split = uncamelify(name).split('.')
path, class_name = split[:-1], split[-1]
path = [elem.replace('_', '-') for elem in path]
class_name = class_name[1:] if class_name.startswith('-') else class_name
class_name = class_name.replace('.-', '.').replace('_-', '_')
return '{}.{}'.format('.'.join(path), class_name)
def _init(self):
""" Actually initializes the service.
"""
self.odb = self.worker_store.server.odb
self.kvdb = self.worker_store.kvdb
self.time.kvdb = self.kvdb
self.slow_threshold = self.server.service_store.services[self.impl_name]['slow_threshold']
out_amqp = PublisherFacade(self.broker_client, self.server.delivery_store)
out_jms_wmq = WMQFacade(self.broker_client, self.server.delivery_store)
out_zmq = ZMQFacade(self.broker_client, self.server.delivery_store)
out_sql = self.worker_store.sql_pool_store
out_ftp, out_plain_http, out_soap = self.worker_store.worker_config.outgoing_connections()
self.outgoing = Outgoing(out_ftp, out_amqp, out_zmq, out_jms_wmq, out_sql, out_plain_http, out_soap)
is_sio = hasattr(self, 'SimpleIO')
if self.passthrough_request:
self.request = self.passthrough_request
self.request.http.init(self.wsgi_environ)
if is_sio:
self.request.init(is_sio, self.cid, self.SimpleIO, self.data_format, self.transport, self.wsgi_environ)
self.response.init(self.cid, self.SimpleIO, self.data_format)
self.msg = MessageFacade(self.worker_store.msg_ns_store,
self.worker_store.elem_path_store, self.worker_store.xpath_store)
#.........這裏部分代碼省略.........
示例9: Service
class Service(object):
""" A base class for all services deployed on Zato servers, no matter
the transport and protocol, be it plain HTTP, SOAP, WebSphere MQ or any other,
regardless whether they're built-in or user-defined ones.
"""
passthrough_to = ''
def __init__(self, *ignored_args, **ignored_kwargs):
self.logger = logging.getLogger(self.get_name())
self.server = None
self.broker_client = None
self.pubsub = None
self.channel = None
self.cid = None
self.outgoing = None
self.cloud = None
self.worker_store = None
self.odb = None
self.data_format = None
self.transport = None
self.wsgi_environ = None
self.job_type = None
self.delivery_store = None
self.environ = {}
self.request = Request(self.logger)
self.response = Response(self.logger)
self.invocation_time = None # When was the service invoked
self.handle_return_time = None # When did its 'handle' method finished processing the request
self.processing_time_raw = None # A timedelta object with the processing time up to microseconds
self.processing_time = None # Processing time in milliseconds
self.usage = 0 # How many times the service has been invoked
self.slow_threshold = maxint # After how many ms to consider the response came too late
self.name = self.__class__.get_name()
self.impl_name = self.__class__.get_impl_name()
self.time = TimeUtil(None)
self.from_passthrough = False
self.passthrough_request = None
self.user_config = None
self.dictnav = DictNav
self.listnav = ListNav
self.has_validate_input = False
self.has_validate_output = False
@staticmethod
def get_name_static(class_):
return Service.get_name(class_)
@classmethod
def get_name(class_):
""" Returns a service's name, settings its .name attribute along. This will
be called once while the service is being deployed.
"""
if not hasattr(class_, '__name'):
name = getattr(class_, 'name', None)
if not name:
name = service_name_from_impl(class_.get_impl_name())
name = class_.convert_impl_name(name)
class_.__name = name
return class_.__name
@classmethod
def get_impl_name(class_):
if not hasattr(class_, '__impl_name'):
class_.__impl_name = '{}.{}'.format(class_.__module__, class_.__name__)
return class_.__impl_name
@staticmethod
def convert_impl_name(name):
# TODO: Move the replace functionality over to uncamelify, possibly modifying its regexp
split = uncamelify(name).split('.')
path, class_name = split[:-1], split[-1]
path = [elem.replace('_', '-') for elem in path]
class_name = class_name[1:] if class_name.startswith('-') else class_name
class_name = class_name.replace('.-', '.').replace('_-', '_')
return '{}.{}'.format('.'.join(path), class_name)
def _init(self):
""" Actually initializes the service.
"""
self.odb = self.worker_store.server.odb
self.kvdb = self.worker_store.kvdb
self.time.kvdb = self.kvdb
self.pubsub = self.worker_store.pubsub
self.slow_threshold = self.server.service_store.services[self.impl_name]['slow_threshold']
# Queues
out_amqp = PublisherFacade(self.broker_client, self.server.delivery_store)
out_jms_wmq = WMQFacade(self.broker_client, self.server.delivery_store)
out_zmq = ZMQFacade(self.broker_client, self.server.delivery_store)
# SQL
out_sql = self.worker_store.sql_pool_store
# Regular outconns
#.........這裏部分代碼省略.........
示例10: test_init_sio
def test_init_sio(self):
is_sio = True
cid = uuid4().hex
data_format = uuid4().hex
transport = uuid4().hex
io_default = {}
io_custom = Bunch(
{
"request_elem": uuid4().hex,
"input_required": ["a", "b", "c"],
"input_optional": ["d", "e", "f"],
"default_value": uuid4().hex,
"use_text": uuid4().hex,
}
)
wsgi_environ = {
"zato.http.GET": {uuid4().hex: uuid4().hex},
"zato.http.POST": {uuid4().hex: uuid4().hex},
"REQUEST_METHOD": uuid4().hex,
}
def _get_params(request_params, *ignored):
# 'g' is never overridden
if request_params is io_custom["input_required"]:
return {"a": "a-req", "b": "b-req", "c": "c-req", "g": "g-msg"}
else:
return {"d": "d-opt", "e": "e-opt", "f": "f-opt", "g": "g-msg"}
r = Request(None)
r.payload = None
r.get_params = _get_params
r.channel_params["a"] = "channel_param_a"
r.channel_params["b"] = "channel_param_b"
r.channel_params["c"] = "channel_param_c"
r.channel_params["d"] = "channel_param_d"
r.channel_params["e"] = "channel_param_e"
r.channel_params["f"] = "channel_param_f"
r.channel_params["h"] = "channel_param_h" # Never overridden
for io in (io_default, io_custom):
for params_priority in PARAMS_PRIORITY:
r.params_priority = params_priority
r.init(is_sio, cid, io, data_format, transport, wsgi_environ)
if io is io_default:
eq_(
sorted(r.input.items()),
sorted(
{
"a": "channel_param_a",
"b": "channel_param_b",
"c": "channel_param_c",
"d": "channel_param_d",
"e": "channel_param_e",
"f": "channel_param_f",
"h": "channel_param_h",
}.items()
),
)
else:
if params_priority == PARAMS_PRIORITY.CHANNEL_PARAMS_OVER_MSG:
eq_(
sorted(r.input.items()),
sorted(
{
"a": "channel_param_a",
"b": "channel_param_b",
"c": "channel_param_c",
"d": "channel_param_d",
"e": "channel_param_e",
"f": "channel_param_f",
"g": "g-msg",
"h": "channel_param_h",
}.items()
),
)
else:
eq_(
sorted(r.input.items()),
sorted(
{
"a": "a-req",
"b": "b-req",
"c": "c-req",
"d": "d-opt",
"e": "e-opt",
"f": "f-opt",
"g": "g-msg",
"h": "channel_param_h",
}.items()
),
)