本文整理汇总了Python中slumber.url_join函数的典型用法代码示例。如果您正苦于以下问题:Python url_join函数的具体用法?Python url_join怎么用?Python url_join使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url_join函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_url_join_encoded_unicode
def test_url_join_encoded_unicode(self):
expected = "http://api.validic.com/t?st/"
url = slumber.url_join("http://api.validic.com/", "t?st/")
self.assertEqual(url, expected)
url = slumber.url_join("http://api.validic.com/", "t?st/".decode('utf8').encode('utf8'))
self.assertEqual(url, expected)
示例2: test_url_join_mixed_unicode
def test_url_join_mixed_unicode(self):
# u"ǝ" == u"\u01dd", u"\u01dd".encode('utf-8') == b"\xc7\x9d"
expected = six.u("http://example.com/r\u01dd/te/st")
if (isinstance(expected, six.text_type)):
expected = expected.encode('utf-8')
url = slumber.url_join(six.b("http://example.com/r\xc7\x9d"),
bytearray(six.b("te")),
six.u("st"))
if (isinstance(url, six.text_type)):
url = url.encode('utf-8')
self.assertEqual(url, expected)
url = slumber.url_join(six.u("http://example.com"),
six.u("r\u01dd/te"),
bytearray(six.b("st")))
if (isinstance(url, six.text_type)):
url = url.encode('utf-8')
self.assertEqual(url, expected)
# check that non-ASCII args needing conversion raise TypeError
self.assertRaises(TypeError, slumber.url_join,
six.u("http://example.com"), six.b("r\xc7\x9d"))
self.assertRaises(TypeError, slumber.url_join,
six.b("http://example.com"), six.u("r\u01dd"))
expected = six.u("http://example.com/te/st")
if (isinstance(expected, six.text_type)):
expected = expected.encode('utf-8')
url = slumber.url_join(bytearray(six.b("http://example.com/")),
six.b("te"),
six.u("st"))
if (isinstance(url, six.text_type)):
url = url.encode('utf-8')
self.assertEqual(url, expected)
url = slumber.url_join(six.u("http://example.com/"),
six.u("te"),
six.b("st"))
if (isinstance(url, six.text_type)):
url = url.encode('utf-8')
self.assertEqual(url, expected)
示例3: pre
def pre(self, request):
config = settings.ZIPPY_CONFIGURATION.get(self.reference_name)
if not config:
raise ImproperlyConfigured('No config: %s' % self.reference_name)
# Headers we want from the proxying request.
self.headers = {
'Content-Type': request.META.get('CONTENT_TYPE'),
'Accept': request.META.get('HTTP_ACCEPT')
}
self.body = str(request.raw_post_data)
self.method = request.META['REQUEST_METHOD'].lower()
# The URL is made up of the defined scheme and host plus the trailing
# URL after the proxy in urls.py.
root = len(reverse('provider.proxy',
kwargs={'reference_name':self.reference_name}))
self.url = url_join(config['url'], request.META['PATH_INFO'][root:])
# Add in the query string.
query = request.META.get('QUERY_STRING')
if query:
self.url = '%s?%s' % (self.url, query)
# Before we do the request, use curling to sign the request headers.
log.info('%s: %s' % (self.method.upper(), self.url))
sign_request(None, config['auth'], headers=self.headers,
method=self.method.upper(),
params={'oauth_token': 'not-implemented'},
url=self.url)
示例4: test_url_join_encoded_unicode
def test_url_join_encoded_unicode(self):
expected = six.u("http://example.com/tǝst/")
if expected.__class__.__name__ == "unicode":
expected = expected.encode("utf-8")
url = slumber.url_join("http://example.com/", six.u("tǝst/"))
if url.__class__.__name__ == "unicode":
url = url.encode("utf-8")
self.assertEqual(url, expected)
url = slumber.url_join("http://example.com/", six.u("tǝst/"))
if url.__class__.__name__ == "unicode":
url = url.encode("utf-8")
self.assertEqual(url, expected)
示例5: get_resource_as_dict
def get_resource_as_dict(cls, uri):
kwargs = {}
api = CandideitorgDocument.get_api()
for key, value in api._store.iteritems():
kwargs[key] = value
kwargs.update({"base_url": url_join(api._store["base_url"], uri)})
resource = Resource(**kwargs)
dicti = resource.get()
return dicti
示例6: _get
def _get(self, url):
# Strip the boku part out of the URL and insert the proxy instead.
url = urlunparse(('', '') + urlparse(url)[2:])
# url_join takes care of missing or extra / in urls, but we must strip
# the first / off the url above.
proxy = url_join(settings.BOKU_PROXY, 'boku', url[1:])
# Now continue as normal, call the proxy.
log.info('Boku proxy client call: {url}'.format(url=proxy))
with statsd.timer('solitude.boku.api'):
return requests.get(proxy)
示例7: __getattr__
def __getattr__(self, item):
# See Slumber for what this is.
if item.startswith("_"):
raise AttributeError(item)
kwargs = {}
for key, value in self._store.iteritems():
kwargs[key] = value
kwargs.update({"base_url": url_join(self._store["base_url"], item)})
return self._resource(**kwargs)
示例8: test_url_join_https
def test_url_join_https(self):
self.assertEqual(slumber.url_join("https://api.validic.com/"), "https://api.validic.com/")
self.assertEqual(slumber.url_join("https://api.validic.com/", "v1"), "https://api.validic.com/v1")
self.assertEqual(slumber.url_join("https://api.validic.com/", "v1", "organizations"), "https://api.validic.com/v1/organizations")
self.assertEqual(slumber.url_join("https://api.validic.com"), "https://api.validic.com/")
self.assertEqual(slumber.url_join("https://api.validic.com", "v1"), "https://api.validic.com/v1")
self.assertEqual(slumber.url_join("https://api.validic.com", "v1", "organizations"), "https://api.validic.com/v1/organizations")
示例9: test_url_join_path
def test_url_join_path(self):
self.assertEqual(slumber.url_join("/"), "/")
self.assertEqual(slumber.url_join("/", "test"), "/test")
self.assertEqual(slumber.url_join("/", "test", "example"), "/test/example")
self.assertEqual(slumber.url_join("/path/"), "/path/")
self.assertEqual(slumber.url_join("/path/", "test"), "/path/test")
self.assertEqual(slumber.url_join("/path/", "test", "example"), "/path/test/example")
示例10: test_url_join_path
def test_url_join_path(self):
self.assertEqual(slumber.url_join("/"), "/")
self.assertEqual(slumber.url_join("/", "v1"), "/v1")
self.assertEqual(slumber.url_join("/", "v1", "organizations"), "/v1/organizations")
self.assertEqual(slumber.url_join("/v1/"), "/v1/")
self.assertEqual(slumber.url_join("/v1/", "organizations"), "/v1/organizations")
self.assertEqual(slumber.url_join("/v1/", "organizations", self.settings.getOrgId()), "/v1/organizations/"+self.settings.getOrgId())
示例11: __getattr__
def __getattr__(self, item):
if item.startswith("_"):
raise AttributeError(item)
kwargs = {}
for key, value in self._store.iteritems():
kwargs[key] = value
kwargs.update({"base_url": url_join(self._store["base_url"], item)})
if item in self.resource_registry:
default_kwargs = {
"resource_cls": self.resource_registry[item],
"resource_registry": self.resource_registry,
'root_url': self._store['root_url']
}
kwargs.update(default_kwargs)
return NapResource(**kwargs)
else:
return Resource(**kwargs)
示例12: pre
def pre(self, request):
# Headers we want from the proxying request.
self.headers = {
'Content-Type': request.META.get('CONTENT_TYPE'),
'Accept': request.META.get('HTTP_ACCEPT')
}
self.body = str(request.raw_post_data)
self.method = request.META['REQUEST_METHOD'].lower()
# The URL is made up of the defined scheme and host plus the trailing
# URL after the proxy in urls.py.
root = len(reverse('provider.proxy',
kwargs={'reference_name': self.reference_name}))
self.url = url_join(self.config['url'],
request.META['PATH_INFO'][root:])
# Add in the query string.
query = request.META.get('QUERY_STRING')
if query:
self.url = qs_join(url=self.url, query=query)
# Before we do the request, use curling to sign the request headers.
log.info('%s: %s' % (self.method.upper(), self.url))
self.sign(request)
示例13: test_url_join_trailing_slash
def test_url_join_trailing_slash(self):
self.assertEqual(slumber.url_join("http://example.com/", "test/"), "http://example.com/test/")
self.assertEqual(slumber.url_join("http://example.com/", "test/", "example/"), "http://example.com/test/example/")
示例14: test_url_join_http_port
def test_url_join_http_port(self):
self.assertEqual(slumber.url_join("http://example.com:80/"), "http://example.com:80/")
self.assertEqual(slumber.url_join("http://example.com:80/", "test"), "http://example.com:80/test")
self.assertEqual(slumber.url_join("http://example.com:80/", "test", "example"), "http://example.com:80/test/example")
示例15: getUserStorefrontUrl
def getUserStorefrontUrl(self,token):
return slumber.url_join("https://app.validic.com/",self.orgId,token)