本文整理汇总了Python中botocore.hooks.HierarchicalEmitter.register_last方法的典型用法代码示例。如果您正苦于以下问题:Python HierarchicalEmitter.register_last方法的具体用法?Python HierarchicalEmitter.register_last怎么用?Python HierarchicalEmitter.register_last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botocore.hooks.HierarchicalEmitter
的用法示例。
在下文中一共展示了HierarchicalEmitter.register_last方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestWildcardHandlers
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import register_last [as 别名]
#.........这里部分代码省略.........
kwargs['call_number'] = call_number
self.hook_calls.append(kwargs)
# Handlers registered through register_first() are always called
# before handlers registered with register().
self.emitter.register('foo', partial(handler, call_number=3))
self.emitter.register('foo', partial(handler, call_number=4))
self.emitter.register_first('foo', partial(handler, call_number=1))
self.emitter.register_first('foo', partial(handler, call_number=2))
self.emitter.register('foo', partial(handler, call_number=5))
self.emitter.emit('foo')
self.assertEqual([k['call_number'] for k in self.hook_calls],
[1, 2, 3, 4, 5])
def test_register_first_hierarchy(self):
def handler(call_number, **kwargs):
kwargs['call_number'] = call_number
self.hook_calls.append(kwargs)
self.emitter.register('foo', partial(handler, call_number=5))
self.emitter.register('foo.bar', partial(handler, call_number=2))
self.emitter.register_first('foo', partial(handler, call_number=4))
self.emitter.register_first('foo.bar', partial(handler, call_number=1))
self.emitter.register('foo', partial(handler, call_number=6))
self.emitter.register('foo.bar', partial(handler, call_number=3))
self.emitter.emit('foo.bar')
self.assertEqual([k['call_number'] for k in self.hook_calls],
[1, 2, 3, 4, 5, 6])
def test_register_last_hierarchy(self):
def handler(call_number, **kwargs):
kwargs['call_number'] = call_number
self.hook_calls.append(kwargs)
self.emitter.register_last('foo', partial(handler, call_number=3))
self.emitter.register('foo', partial(handler, call_number=2))
self.emitter.register_first('foo', partial(handler, call_number=1))
self.emitter.emit('foo')
self.assertEqual([k['call_number'] for k in self.hook_calls],
[1, 2, 3])
def test_register_unregister_first_last(self):
self.emitter.register('foo', self.hook)
self.emitter.register_last('foo.bar', self.hook)
self.emitter.register_first('foo.bar.baz', self.hook)
self.emitter.unregister('foo.bar.baz', self.hook)
self.emitter.unregister('foo.bar', self.hook)
self.emitter.unregister('foo', self.hook)
self.emitter.emit('foo')
self.assertEqual(self.hook_calls, [])
def test_copy_emitter(self):
# Here we're not testing copy directly, we're testing
# the observable behavior from copying an event emitter.
first = []
def first_handler(id_name, **kwargs):
first.append(id_name)
second = []
def second_handler(id_name, **kwargs):
示例2: Session
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import register_last [as 别名]
#.........这里部分代码省略.........
def _register_credential_provider(self):
self._components.lazy_register_component(
'credential_provider',
lambda: botocore.credentials.create_credential_resolver(self))
def _register_data_loader(self):
self._components.lazy_register_component(
'data_loader',
lambda: create_loader(self.get_config_variable('data_path')))
def _register_endpoint_resolver(self):
self._components.lazy_register_component(
'endpoint_resolver',
lambda: regions.EndpointResolver(self.get_data('_endpoints')))
def _register_response_parser_factory(self):
self._components.register_component('response_parser_factory',
ResponseParserFactory())
def _reset_components(self):
self._register_components()
def _register_builtin_handlers(self, events):
for spec in handlers.BUILTIN_HANDLERS:
if len(spec) == 2:
event_name, handler = spec
self.register(event_name, handler)
else:
event_name, handler, register_type = spec
if register_type is handlers.REGISTER_FIRST:
self._events.register_first(event_name, handler)
elif register_first is handlers.REGISTER_LAST:
self._events.register_last(event_name, handler)
@property
def provider(self):
if self._provider is None:
self._provider = get_provider(
self, self.get_config_variable('provider'))
return self._provider
@property
def available_profiles(self):
return list(self._build_profile_map().keys())
def _build_profile_map(self):
# This will build the profile map if it has not been created,
# otherwise it will return the cached value. The profile map
# is a list of profile names, to the config values for the profile.
if self._profile_map is None:
self._profile_map = self.full_config['profiles']
return self._profile_map
@property
def profile(self):
return self._profile
@profile.setter
def profile(self, profile):
# Since provider can be specified in profile, changing the
# profile should reset the provider.
self._provider = None
self._profile = profile
# Need to potentially reload the config file/creds.
self._reset_components()
示例3: Session
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import register_last [as 别名]
#.........这里部分代码省略.........
self._register_response_parser_factory()
def _register_event_emitter(self):
self._components.register_component("event_emitter", self._events)
def _register_credential_provider(self):
self._components.lazy_register_component(
"credential_provider", lambda: botocore.credentials.create_credential_resolver(self)
)
def _register_data_loader(self):
self._components.lazy_register_component(
"data_loader", lambda: create_loader(self.get_config_variable("data_path"))
)
def _register_endpoint_resolver(self):
self._components.lazy_register_component(
"endpoint_resolver", lambda: regions.EndpointResolver(self.get_data("_endpoints"))
)
def _register_response_parser_factory(self):
self._components.register_component("response_parser_factory", ResponseParserFactory())
def _register_builtin_handlers(self, events):
for spec in handlers.BUILTIN_HANDLERS:
if len(spec) == 2:
event_name, handler = spec
self.register(event_name, handler)
else:
event_name, handler, register_type = spec
if register_type is handlers.REGISTER_FIRST:
self._events.register_first(event_name, handler)
elif register_type is handlers.REGISTER_LAST:
self._events.register_last(event_name, handler)
@property
def available_profiles(self):
return list(self._build_profile_map().keys())
def _build_profile_map(self):
# This will build the profile map if it has not been created,
# otherwise it will return the cached value. The profile map
# is a list of profile names, to the config values for the profile.
if self._profile_map is None:
self._profile_map = self.full_config["profiles"]
return self._profile_map
@property
def profile(self):
if self._profile is None:
profile = self.get_config_variable("profile")
self._profile = profile
return self._profile
def get_config_variable(self, logical_name, methods=("instance", "env", "config")):
"""
Retrieve the value associated with the specified logical_name
from the environment or the config file. Values found in the
environment variable take precedence of values found in the
config file. If no value can be found, a None will be returned.
:type logical_name: str
:param logical_name: The logical name of the session variable
you want to retrieve. This name will be mapped to the
appropriate environment variable name for this session as
well as the appropriate config file entry.
示例4: TestWildcardHandlers
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import register_last [as 别名]
#.........这里部分代码省略.........
# Now the event should be unregistered.
self.hook_calls = []
self.emitter.emit('foo')
self.assertEqual(len(self.hook_calls), 0)
def test_register_with_no_uses_count_unregister(self):
self.emitter.register('foo', self.hook, unique_id='foo')
# The event was not registered to use a count initially
with self.assertRaises(ValueError):
self.emitter.unregister('foo', self.hook, unique_id='foo',
unique_id_uses_count=True)
def test_handlers_called_in_order(self):
def handler(call_number, **kwargs):
kwargs['call_number'] = call_number
self.hook_calls.append(kwargs)
self.emitter.register('foo', partial(handler, call_number=1))
self.emitter.register('foo', partial(handler, call_number=2))
self.emitter.emit('foo')
self.assertEqual([k['call_number'] for k in self.hook_calls],
[1, 2])
def test_handler_call_order_with_hierarchy(self):
def handler(call_number, **kwargs):
kwargs['call_number'] = call_number
self.hook_calls.append(kwargs)
# We go from most specific to least specific, and each level is called
# in the order they were registered for that particular hierarchy
# level.
self.emitter.register('foo.bar.baz', partial(handler, call_number=1))
self.emitter.register('foo.bar', partial(handler, call_number=3))
self.emitter.register('foo', partial(handler, call_number=5))
self.emitter.register('foo.bar.baz', partial(handler, call_number=2))
self.emitter.register('foo.bar', partial(handler, call_number=4))
self.emitter.register('foo', partial(handler, call_number=6))
self.emitter.emit('foo.bar.baz')
self.assertEqual([k['call_number'] for k in self.hook_calls],
[1, 2, 3, 4, 5, 6])
def test_register_first_single_level(self):
def handler(call_number, **kwargs):
kwargs['call_number'] = call_number
self.hook_calls.append(kwargs)
# Handlers registered through register_first() are always called
# before handlers registered with register().
self.emitter.register('foo', partial(handler, call_number=3))
self.emitter.register('foo', partial(handler, call_number=4))
self.emitter.register_first('foo', partial(handler, call_number=1))
self.emitter.register_first('foo', partial(handler, call_number=2))
self.emitter.register('foo', partial(handler, call_number=5))
self.emitter.emit('foo')
self.assertEqual([k['call_number'] for k in self.hook_calls],
[1, 2, 3, 4, 5])
def test_register_first_hierarchy(self):
def handler(call_number, **kwargs):
kwargs['call_number'] = call_number
self.hook_calls.append(kwargs)
self.emitter.register('foo', partial(handler, call_number=5))
self.emitter.register('foo.bar', partial(handler, call_number=2))
self.emitter.register_first('foo', partial(handler, call_number=4))
self.emitter.register_first('foo.bar', partial(handler, call_number=1))
self.emitter.register('foo', partial(handler, call_number=6))
self.emitter.register('foo.bar', partial(handler, call_number=3))
self.emitter.emit('foo.bar')
self.assertEqual([k['call_number'] for k in self.hook_calls],
[1, 2, 3, 4, 5, 6])
def test_register_last_hierarchy(self):
def handler(call_number, **kwargs):
kwargs['call_number'] = call_number
self.hook_calls.append(kwargs)
self.emitter.register_last('foo', partial(handler, call_number=3))
self.emitter.register('foo', partial(handler, call_number=2))
self.emitter.register_first('foo', partial(handler, call_number=1))
self.emitter.emit('foo')
self.assertEqual([k['call_number'] for k in self.hook_calls],
[1, 2, 3])
def test_register_unregister_first_last(self):
self.emitter.register('foo', self.hook)
self.emitter.register_last('foo.bar', self.hook)
self.emitter.register_first('foo.bar.baz', self.hook)
self.emitter.unregister('foo.bar.baz', self.hook)
self.emitter.unregister('foo.bar', self.hook)
self.emitter.unregister('foo', self.hook)
self.emitter.emit('foo')
self.assertEqual(self.hook_calls, [])