本文整理汇总了Python中stackinabox.stack.StackInABox.hold_onto方法的典型用法代码示例。如果您正苦于以下问题:Python StackInABox.hold_onto方法的具体用法?Python StackInABox.hold_onto怎么用?Python StackInABox.hold_onto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stackinabox.stack.StackInABox
的用法示例。
在下文中一共展示了StackInABox.hold_onto方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requests_mock_session_registration
# 需要导入模块: from stackinabox.stack import StackInABox [as 别名]
# 或者: from stackinabox.stack.StackInABox import hold_onto [as 别名]
def requests_mock_session_registration(uri, session):
logger.debug('Registering Stack-In-A-Box at {0} under Python Requests-Mock'
.format(uri))
logger.debug('Session has id {0}'.format(id(session)))
StackInABox.update_uri(uri)
StackInABox.hold_onto('adapter', requests_mock.Adapter())
StackInABox.hold_out('adapter').add_matcher(RequestMockCallable(uri))
session.mount('http://{0}'.format(uri), StackInABox.hold_out('adapter'))
session.mount('https://{0}'.format(uri), StackInABox.hold_out('adapter'))
示例2: session_registration
# 需要导入模块: from stackinabox.stack import StackInABox [as 别名]
# 或者: from stackinabox.stack.StackInABox import hold_onto [as 别名]
def session_registration(uri, session):
"""Requests-mock registration with a specific Session.
:param uri: base URI to match against
:param session: Python requests' Session object
:returns: n/a
"""
# log the URI that is used to access the Stack-In-A-Box services
logger.debug('Registering Stack-In-A-Box at {0} under Python Requests-Mock'
.format(uri))
logger.debug('Session has id {0}'.format(id(session)))
# tell Stack-In-A-Box what URI to match with
StackInABox.update_uri(uri)
# Create a Python Requests Adapter object for handling the session
StackInABox.hold_onto('adapter', requests_mock.Adapter())
# Add the Request handler object for the URI
StackInABox.hold_out('adapter').add_matcher(RequestMockCallable(uri))
# Tell the session about the adapter and the URI
session.mount('http://{0}'.format(uri), StackInABox.hold_out('adapter'))
session.mount('https://{0}'.format(uri), StackInABox.hold_out('adapter'))