本文整理汇总了Python中pulsar.utils.httpurl.iri_to_uri函数的典型用法代码示例。如果您正苦于以下问题:Python iri_to_uri函数的具体用法?Python iri_to_uri怎么用?Python iri_to_uri使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iri_to_uri函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_wsgi_environ
def test_wsgi_environ(path='/', method=None, headers=None, extra=None,
secure=False, loop=None):
'''An function to create a WSGI environment dictionary for testing.
:param url: the resource in the ``PATH_INFO``.
:param method: the ``REQUEST_METHOD``.
:param headers: optional request headers
:params secure: a secure connection?
:param extra: additional dictionary of parameters to add.
:return: a valid WSGI environ dictionary.
'''
parser = http_parser(kind=0)
method = (method or 'GET').upper()
path = iri_to_uri(path)
data = '%s %s HTTP/1.1\r\n\r\n' % (method, path)
data = data.encode('latin1')
parser.execute(data, len(data))
request_headers = Headers(headers, kind='client')
# Add Host if not available
parsed = urlparse(path)
if parsed.netloc and 'host' not in request_headers:
request_headers['host'] = parsed.netloc
#
headers = Headers()
stream = StreamReader(request_headers, parser)
extra = extra or {}
extra['pulsar.connection'] = FakeConnection(loop=loop)
return wsgi_environ(stream, ('127.0.0.1', 8060), '777.777.777.777:8080',
headers, https=secure, extra=extra)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:29,代码来源:server.py
示例2: test_wsgi_environ
def test_wsgi_environ(path=None, method=None, headers=None, extra=None,
secure=False, loop=None, body=None):
'''An function to create a WSGI environment dictionary for testing.
:param url: the resource in the ``PATH_INFO``.
:param method: the ``REQUEST_METHOD``.
:param headers: optional request headers
:params secure: a secure connection?
:param extra: additional dictionary of parameters to add.
:return: a valid WSGI environ dictionary.
'''
parser = http_parser(kind=0)
method = (method or 'GET').upper()
path = iri_to_uri(path or '/')
request_headers = Headers(headers, kind='client')
# Add Host if not available
parsed = urlparse(path)
if 'host' not in request_headers:
if not parsed.netloc:
scheme = ('https' if secure else 'http')
path = '%s://127.0.0.1%s' % (scheme, path)
else:
request_headers['host'] = parsed.netloc
#
data = '%s %s HTTP/1.1\r\n\r\n' % (method, path)
data = data.encode('latin1')
parser.execute(data, len(data))
#
stream = io.BytesIO(body or b'')
return wsgi_environ(stream, parser, request_headers,
('127.0.0.1', 8060), '255.0.1.2:8080',
Headers(), https=secure, extra=extra)
开发者ID:kakamessi99,项目名称:pulsar-1,代码行数:32,代码来源:server.py
示例3: test_wsgi_environ
def test_wsgi_environ(path=None, method=None, headers=None, extra=None, secure=False, loop=None, body=None):
"""An function to create a WSGI environment dictionary for testing.
:param url: the resource in the ``PATH_INFO``.
:param method: the ``REQUEST_METHOD``.
:param headers: optional request headers
:params secure: a secure connection?
:param extra: additional dictionary of parameters to add.
:return: a valid WSGI environ dictionary.
"""
parser = http_parser(kind=0)
method = (method or "GET").upper()
path = iri_to_uri(path or "/")
request_headers = Headers(headers, kind="client")
# Add Host if not available
parsed = urlparse(path)
if "host" not in request_headers:
if not parsed.netloc:
path = "%s%s" % ("https://:443" if secure else "http://:80", path)
else:
request_headers["host"] = parsed.netloc
#
data = "%s %s HTTP/1.1\r\n\r\n" % (method, path)
data = data.encode("latin1")
parser.execute(data, len(data))
#
stream = io.BytesIO(body or b"")
return wsgi_environ(
stream, parser, request_headers, ("127.0.0.1", 8060), "255.0.1.2:8080", Headers(), https=secure, extra=extra
)
开发者ID:luffyhwl,项目名称:pulsar,代码行数:30,代码来源:server.py
示例4: link
def link(self, request, offset, limit):
params = request.url_data.copy()
cfg = request.config
params.update({cfg['API_OFFSET_KEY']: offset,
cfg['API_LIMIT_KEY']: limit})
location = iri_to_uri(request.path, params)
return request.absolute_uri(location)
开发者ID:SirZazu,项目名称:lux,代码行数:7,代码来源:pagination.py
示例5: upload
async def upload(self, release, filename, content_type=None):
"""Upload a file to a release
:param filename: filename to upload
:param content_type: optional content type
:return: json object from github
"""
release = self.as_id(release)
name = os.path.basename(filename)
if not content_type:
content_type, _ = mimetypes.guess_type(name)
if not content_type:
raise ValueError('content_type not known')
inputs = {'name': name}
url = '%s%s/%s/assets' % (self.uploads_url,
urlsplit(self.api_url).path,
release)
url = iri_to_uri(url, inputs)
info = os.stat(filename)
size = info[stat.ST_SIZE]
response = await self.http.post(
url, data=stream_upload(filename), auth=self.auth,
headers={'content-type': content_type,
'content-length': str(size)})
response.raise_for_status()
return response.json()
开发者ID:quantmind,项目名称:pulsar-agile,代码行数:26,代码来源:releases.py
示例6: test_wsgi_environ
def test_wsgi_environ(path=None, method=None, headers=None, extra=None,
secure=False, loop=None, body=None):
'''An function to create a WSGI environment dictionary for testing.
:param url: the resource in the ``PATH_INFO``.
:param method: the ``REQUEST_METHOD``.
:param headers: optional request headers
:params secure: a secure connection?
:param extra: additional dictionary of parameters to add.
:return: a valid WSGI environ dictionary.
'''
parser = http_parser(kind=0)
method = (method or 'GET').upper()
path = iri_to_uri(path or '/')
request_headers = Headers(headers, kind='client')
# Add Host if not available
parsed = urlparse(path)
if 'host' not in request_headers:
if not parsed.netloc:
path = '%s%s' % ('https://:443' if secure else 'http://:80', path)
else:
request_headers['host'] = parsed.netloc
#
data = '%s %s HTTP/1.1\r\n\r\n' % (method, path)
data = data.encode('latin1')
parser.execute(data, len(data))
#
headers = Headers()
stream = StreamReader(request_headers, parser)
stream.buffer = body or b''
stream.on_message_complete.set_result(None)
extra = extra or {}
return wsgi_environ(stream, ('127.0.0.1', 8060), '777.777.777.777:8080',
headers, https=secure, extra=extra)
开发者ID:LJS109,项目名称:pulsar,代码行数:34,代码来源:server.py
示例7: test_200_get_data
def test_200_get_data(self):
http = self.client()
response = yield from http.get(self.httpbin("get"), data={"bla": "foo"})
result = response.json()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["content-type"], "application/json; charset=utf-8")
self.assertEqual(result["args"], {"bla": "foo"})
self.assertEqual(response.url, self.httpbin(iri_to_uri("get", {"bla": "foo"})))
self._check_pool(http, response)
开发者ID:msornay,项目名称:pulsar,代码行数:9,代码来源:base.py
示例8: test_200_get_data
def test_200_get_data(self):
http = self.client()
response = yield http.get(self.httpbin('get'),
data={'bla': 'foo'}).on_finished
result = response.json()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers['content-type'], 'application/json')
self.assertEqual(result['args'], {'bla': 'foo'})
self.assertEqual(response.url,
self.httpbin(httpurl.iri_to_uri('get',{'bla': 'foo'})))
self._check_pool(http, response)
开发者ID:elimisteve,项目名称:pulsar,代码行数:11,代码来源:client.py
示例9: test_200_get_data
def test_200_get_data(self):
http = self.client()
r = make_async(http.get(self.httpbin('get',''), data={'bla':'foo'}))
yield r
r = r.result
self.assertEqual(r.status_code, 200)
self.assertEqual(r.response, 'OK')
result = r.content_json()
self.assertEqual(result['args'], {'bla':['foo']})
self.assertEqual(r.url,
self.httpbin(httpurl.iri_to_uri('get/',{'bla':'foo'})))
开发者ID:cyberj,项目名称:pulsar,代码行数:11,代码来源:httpurl.py
示例10: absolute_uri
def absolute_uri(self, location=None, scheme=None):
'''Builds an absolute URI from the ``location`` and the variables
available in this request. If no location is specified, the relative URI
is built from :meth:`full_path`.'''
if not location or not absolute_http_url_re.match(location):
location = self.full_path(location)
if not scheme:
scheme = self.is_secure and 'https' or 'http'
base = '%s://%s' % (scheme, self.get_host())
return '%s%s' % (base, location)
elif not scheme:
return iri_to_uri(location)
else:
raise ValueError('Absolute location with scheme not valid')
开发者ID:etataurov,项目名称:pulsar,代码行数:14,代码来源:wrappers.py
示例11: full_path
def full_path(self, *args, **query):
'''Return a full path'''
path = None
if args:
if len(args) > 1:
raise TypeError("full_url() takes exactly 1 argument "
"(%s given)" % len(args))
path = args[0]
if path is None:
path = self.path
if not query:
query = self.url_data
elif not path.startswith('/'):
path = remove_double_slash('%s/%s' % (self.path, path))
return iri_to_uri(path, **query)
开发者ID:etataurov,项目名称:pulsar,代码行数:15,代码来源:wrappers.py
示例12: navigation_visit
def navigation_visit(self, request, navigation):
'''Accessed by the :mod:`lux.extensions.sitemap` extension.
It adds the ``edit`` or ``exit`` links to the user links if
the user is authenticated and has valid permissions.
'''
if request.cache.session:
user = request.cache.session.user
if user.is_authenticated():
edit = self.get_route('edit')
if request.cache.app_handler == edit:
route = self.get_route('exit edit')
if route:
url = iri_to_uri(route.path(**request.urlargs),
request.url_data)
navigation.user.insert(0, navigation.item(
url, icon=self.exit_icon, text='exit'))
else:
page = request.cache.page
if page:
url = iri_to_uri(edit.path(id=page.id),
request.urlargs)
navigation.user.insert(0, navigation.item(
url, icon=self.edit_icon, text='edit'))
开发者ID:pombredanne,项目名称:lux,代码行数:24,代码来源:views.py
示例13: absolute_uri
def absolute_uri(self, location=None, scheme=None):
"""Builds an absolute URI from ``location`` and variables
available in this request.
If no ``location`` is specified, the relative URI is built from
:meth:`full_path`.
"""
if not location or not absolute_http_url_re.match(location):
location = self.full_path(location)
if not scheme:
scheme = self.is_secure and "https" or "http"
base = "%s://%s" % (scheme, self.get_host())
return "%s%s" % (base, location)
elif not scheme:
return iri_to_uri(location)
else:
raise ValueError("Absolute location with scheme not valid")
开发者ID:Ghost-script,项目名称:dyno-chat,代码行数:17,代码来源:wrappers.py
示例14: absolute_uri
def absolute_uri(self, location=None, scheme=None, **query):
"""Builds an absolute URI from ``location`` and variables
available in this request.
If no ``location`` is specified, the relative URI is built from
:meth:`full_path`.
"""
if not is_absolute_uri(location):
if location or location is None:
location = self.full_path(location, **query)
if not scheme:
scheme = self.is_secure and 'https' or 'http'
base = '%s://%s' % (scheme, self.get_host())
return '%s%s' % (base, location)
elif not scheme:
return iri_to_uri(location)
else:
raise ValueError('Absolute location with scheme not valid')
开发者ID:quantmind,项目名称:pulsar,代码行数:18,代码来源:wrappers.py
示例15: to_url
def to_url(self, value):
return iri_to_uri(value)
开发者ID:Danzeer,项目名称:pulsar,代码行数:2,代码来源:route.py
注:本文中的pulsar.utils.httpurl.iri_to_uri函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论