本文整理汇总了Python中amazonproduct.api.API.VERSION方法的典型用法代码示例。如果您正苦于以下问题:Python API.VERSION方法的具体用法?Python API.VERSION怎么用?Python API.VERSION使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amazonproduct.api.API
的用法示例。
在下文中一共展示了API.VERSION方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pytest_funcarg__api
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import VERSION [as 别名]
def pytest_funcarg__api(request):
server = request.getfuncargvalue('server')
api = API('XXX', 'XXX', 'uk') # locale does not matter here!
api.host = '%s:%s' % server.server_address
if hasattr(request, 'param'): # for tests generated by pytest_generate_tests
api.VERSION = request.param['version']
api.REQUESTS_PER_SECOND = 10000 # just for here!
return api
示例2: pytest_funcarg__api
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import VERSION [as 别名]
def pytest_funcarg__api(request):
server = request.getfuncargvalue("server")
api = API("XXX", "XXX", "uk") # locale does not matter here!
api.host = "%s:%s" % server.server_address
if hasattr(request, "param"): # for tests generated by pytest_generate_tests
api.VERSION = request.param["version"]
api.REQUESTS_PER_SECOND = 10000 # just for here!
return api
示例3: pytest_funcarg__api
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import VERSION [as 别名]
def pytest_funcarg__api(request):
"""
Initialises API for each test call (formerly done with ``setup_method()``).
"""
server = request.getfuncargvalue('server')
url_reg = re.compile(r'^http://(?P<host>[\w\-\.]+)(?P<path>/onca/xml.*)$')
# the following parameters are injected by pytest_generate_tests
locale = request.param['locale']
version = request.param['version']
xml_response = request.param['xml_response']
processor = TESTABLE_PROCESSORS[request.param['processor']]
if isinstance(processor, type):
processor = processor()
api = API(locale=locale, processor=processor)
api.VERSION = version
api.REQUESTS_PER_SECOND = 10000 # just for here!
def counter(fnc):
"""
Wrapper function for ``_fetch`` which
1. keeps track of the times has been called and adjusts the path to the
corresponding XML response
2. Fetches any response that has not been cached from the live servers
"""
api._count = 0
def wrapped(url):
api._count += 1
path = xml_response
if api._count > 1:
root, ext = os.path.splitext(path)
path = '%s-%i%s' % (root, api._count, ext)
try:
if request.config.option.fetch == 'all':
raise ResponseRequired
try:
content = open(path, 'r').read()
# If the XML response has been previously fetched compare
# request arguments in order to see if there are any changes
cached_params = utils.arguments_from_cached_xml(content)
current_params = utils.arguments_from_url(url)
if cached_params != current_params:
raise ArgumentMismatch
except IOError:
if request.config.option.fetch in ('outdated', 'missing'):
raise ResponseRequired
raise pytest.skip('No cached XML response found!')
except ArgumentMismatch:
if request.config.option.fetch == 'outdated':
raise ResponseRequired
return pytest.skip('Cached arguments in %s differ from the '
'ones currently tested against!' % path)
#'\ncached=%r\ncurrent=%r' % (path,
#cached_params, current_params))
except AttributeError:
# XML for error messages have no Argument elements!
pass
except ResponseRequired:
# fetch XML via urllib2 rather than directly via
# lxml.etree.parse() to avoid, for instance, problems with HTTP
# 403 errors
try:
req = urllib2.Request(url, headers={'User-Agent': USER_AGENT})
xml = urllib2.urlopen(req).read()
except urllib2.HTTPError, e:
xml = e.read()
root = lxml.etree.fromstring(xml)
# overwrite sensitive information in XML document.
for arg in root.xpath('//aws:Argument',
namespaces={'aws': root.nsmap[None]}):
if arg.get('Name') in ('Signature', 'AWSAccessKeyId',
'AssociateTag'):
arg.set('Value', 'X'*15)
content = lxml.etree.tostring(root, pretty_print=True)
# complain loudly about missing credentials
# UNLESS it was actually on purpose!
if ('MissingClientTokenId' in content
and getattr(request.function, 'refetch', True)):
raise pytest.fail('Cannot fetch XML response without credentials!')
if not os.path.exists(os.path.dirname(path)):
os.mkdir(os.path.dirname(path))
open(path, 'wb').write(content)
# We simply exchange the real host with the local one now!
# Note: Although strictly speaking it does not matter which URL is
# called exactly, to appeal to one's sense of correctness, let's
# keep at least the correct path!
url = url_reg.sub(r'%s\g<path>' % server.url, url)
server.serve_content(content)
return fnc(url)
return wrapped