本文整理汇总了Python中pyramid.encode.urlencode函数的典型用法代码示例。如果您正苦于以下问题:Python urlencode函数的具体用法?Python urlencode怎么用?Python urlencode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了urlencode函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: merge_url_qs
def merge_url_qs(url, **kw):
""" Merge the query string elements of a URL with the ones in ``kw``.
If any query string element exists in ``url`` that also exists in
``kw``, replace it."""
segments = urlsplit(url)
extra_qs = [ (k, v) for (k, v) in
parse_qsl(segments.query, keep_blank_values=1)
if k not in kw ]
qs = urlencode(sorted(kw.items()))
if extra_qs:
qs += '&' + urlencode(extra_qs)
return urlunsplit(
(segments.scheme, segments.netloc, segments.path, qs, segments.fragment)
)
开发者ID:Pylons,项目名称:substanced,代码行数:14,代码来源:__init__.py
示例2: parse_url_overrides
def parse_url_overrides(request, kw):
"""
Parse special arguments passed when generating urls.
The supplied dictionary is mutated when we pop arguments.
Returns a 3-tuple of the format:
``(app_url, qs, anchor)``.
"""
app_url = kw.pop('_app_url', None)
scheme = kw.pop('_scheme', None)
host = kw.pop('_host', None)
port = kw.pop('_port', None)
query = kw.pop('_query', '')
anchor = kw.pop('_anchor', '')
if app_url is None:
if (scheme is not None or host is not None or port is not None):
app_url = request._partial_application_url(scheme, host, port)
else:
app_url = request.application_url
qs = ''
if query:
if isinstance(query, string_types):
qs = '?' + url_quote(query, QUERY_SAFE)
else:
qs = '?' + urlencode(query, doseq=True)
frag = ''
if anchor:
frag = '#' + url_quote(anchor, ANCHOR_SAFE)
return app_url, qs, frag
开发者ID:invisibleroads,项目名称:pyramid,代码行数:35,代码来源:url.py
示例3: _init_navigation
def _init_navigation(self):
nav = Navigation(self)
# left side
url = self.url_for(self.name + '.html')
fmt = '%s?year=%d&month=%d&day=%d%s'
if self.nav_params:
extra = '&%s' % urlencode(self.nav_params)
else:
extra = ''
nav.prev_url = fmt % (url, self.prev_datetime.year,
self.prev_datetime.month,
self.prev_datetime.day,
extra)
nav.next_url = fmt % (url, self.next_datetime.year,
self.next_datetime.month,
self.next_datetime.day,
extra)
if not self._is_today_shown():
nav.today_url = fmt % (url, self.now_datetime.year,
self.now_datetime.month,
self.now_datetime.day,
extra)
self.navigation = nav
开发者ID:araymund,项目名称:karl,代码行数:29,代码来源:base.py
示例4: forbidden_redirect
def forbidden_redirect(context, request):
if authenticated_userid(request):
location = request.application_url + '/@@forbidden'
else:
location = request.application_url + '/@@login?' + urlencode(
{'came_from': request.url})
return HTTPFound(location=location)
开发者ID:twei55,项目名称:Kotti,代码行数:7,代码来源:login.py
示例5: _init_navigation
def _init_navigation(self):
nav = Navigation(self)
base_url = '%s?year=%d&month=%d&day=%d&per_page=%d' % (
self.url_for(self.name + '.html'),
self.focus_datetime.year,
self.focus_datetime.month,
self.focus_datetime.day,
self.per_page)
if self.nav_params:
base_url += '&%s' % urlencode(self.nav_params)
# today_url
if self.page == 1:
nav.today_url = None
else:
nav.today_url = base_url + "&page=1"
# prev_url
if self.page == 1:
nav.prev_url = None
else:
prev_page = self.page - 1
nav.prev_url = base_url + ("&page=%d" % prev_page)
# next_url
if not self.has_more:
nav.next_url = None
else:
next_page = self.page + 1
nav.next_url = base_url + ("&page=%d" % next_page)
self.navigation = nav
开发者ID:araymund,项目名称:karl,代码行数:34,代码来源:list.py
示例6: forbidden_redirect
def forbidden_redirect(context, request):
""" Forbidden redirect view. Redirects to the login form for anonymous
users or to the forbidden view for authenticated users.
:result: Redirect to one of the above.
:rtype: pyramid.httpexceptions.HTTPFound
"""
if request.authenticated_userid:
location = request.application_url + "/@@forbidden"
else:
location = request.application_url + "/@@login?" + urlencode({"came_from": request.url})
return HTTPFound(location=location)
开发者ID:Kotti,项目名称:Kotti,代码行数:12,代码来源:login.py
示例7: expand_redirect_uri
def expand_redirect_uri(self, query_data, fragment_data):
"""Expand a redirect URI with data and return the new URI."""
scheme, netloc, path, query, _old_fragment = urlsplit(
self.redirect_uri)
fragment = ''
if query_data:
# Mix query_data into the query string.
if self.state is not None:
d = {'state': self.state}
d.update(query_data)
query_data = d
q = parse_qsl(query, keep_blank_values=True)
q = [(name, value) for (name, value) in q
if name not in query_data]
q.extend(sorted(query_data.iteritems()))
query = urlencode(q)
if fragment_data:
# Add fragment_data to the fragment.
if self.state is not None:
d = {'state': self.state}
d.update(fragment_data)
fragment_data = d
fragment = urlencode(sorted(fragment_data.items()))
return urlunsplit((scheme, netloc, path, query, fragment))
开发者ID:azazel75,项目名称:yasso,代码行数:24,代码来源:authorizeviews.py
示例8: get_href
def get_href(context, *elements, **kw):
# Return absolute url:
#return context.request.resource_url(context, *elements, **kw)
# Return url starting with '/':
path = resource_path(context)
if elements:
if path[-1] != '/':
path += '/'
path += '/'.join(elements)
if 'query' in kw:
query = kw['query']
if query:
return '%s?%s' % (path, urlencode(query, doseq=True))
return path
开发者ID:sbrauer,项目名称:Audrey,代码行数:15,代码来源:views.py
示例9: create
def create(self):
if not RequestCheckUserCapability(self.request, 'moodle/ejudge_submits:comment'):
raise Exception("Auth Error")
author_id = RequestGetUserId(self.request)
random_string = ''.join(random.SystemRandom().choice(
string.ascii_lowercase + string.digits) for _ in range(20))
encoded_url = urlencode(self.request.params)
monitor = MonitorLink(author_id=author_id,
link=random_string, internal_link=encoded_url)
with transaction.manager:
DBSession.add(monitor)
response = {
'link': random_string
}
return response
开发者ID:InformaticsMskRu,项目名称:informatics-mccme-ru,代码行数:19,代码来源:team_monitor.py
示例10: login
def login(root, request):
"""User started the login process.
Redirect to the authorize endpoint, where the user will enter
credentials, then WingCash will redirect the browser to login_callback.
"""
instance_config = get_instance_config()
redirect_uri = resource_url(root, request, 'login_callback')
# See the OAuth 2 spec, section 4.1.1
q = urlencode([
('response_type', 'code'),
('client_id', instance_config['client_id']),
('redirect_uri', redirect_uri),
('scope', request_scope),
('state', 'abc123'),
('uuid', 'd4de07e3-d731-441b-81e2-5c2158205935'),
('name', 'MicroBank Device'),
# ('force_login', 'true'),
])
url = '%s?%s' % (instance_config['authorize_url'], q)
return HTTPFound(location=url)
开发者ID:WingCash,项目名称:MicroBank,代码行数:21,代码来源:views.py
示例11: parse_url_overrides
def parse_url_overrides(kw):
"""Parse special arguments passed when generating urls.
The supplied dictionary is mutated, popping arguments as necessary.
Returns a 6-tuple of the format ``(app_url, scheme, host, port,
qs, anchor)``.
"""
anchor = ''
qs = ''
app_url = None
host = None
scheme = None
port = None
if '_query' in kw:
query = kw.pop('_query')
if isinstance(query, string_types):
qs = '?' + url_quote(query, QUERY_SAFE)
elif query:
qs = '?' + urlencode(query, doseq=True)
if '_anchor' in kw:
anchor = kw.pop('_anchor')
anchor = url_quote(anchor, ANCHOR_SAFE)
anchor = '#' + anchor
if '_app_url' in kw:
app_url = kw.pop('_app_url')
if '_host' in kw:
host = kw.pop('_host')
if '_scheme' in kw:
scheme = kw.pop('_scheme')
if '_port' in kw:
port = kw.pop('_port')
return app_url, scheme, host, port, qs, anchor
开发者ID:AdrianTeng,项目名称:pyramid,代码行数:39,代码来源:url.py
示例12: route_url
def route_url(self, route_name, *elements, **kw):
"""Generates a fully qualified URL for a named :app:`Pyramid`
:term:`route configuration`.
Use the route's ``name`` as the first positional argument.
Additional positional arguments (``*elements``) are appended to the
URL as path segments after it is generated.
Use keyword arguments to supply values which match any dynamic
path elements in the route definition. Raises a :exc:`KeyError`
exception if the URL cannot be generated for any reason (not
enough arguments, for example).
For example, if you've defined a route named "foobar" with the path
``{foo}/{bar}/*traverse``::
request.route_url('foobar',
foo='1') => <KeyError exception>
request.route_url('foobar',
foo='1',
bar='2') => <KeyError exception>
request.route_url('foobar',
foo='1',
bar='2',
traverse=('a','b')) => http://e.com/1/2/a/b
request.route_url('foobar',
foo='1',
bar='2',
traverse='/a/b') => http://e.com/1/2/a/b
Values replacing ``:segment`` arguments can be passed as strings
or Unicode objects. They will be encoded to UTF-8 and URL-quoted
before being placed into the generated URL.
Values replacing ``*remainder`` arguments can be passed as strings
*or* tuples of Unicode/string values. If a tuple is passed as a
``*remainder`` replacement value, its values are URL-quoted and
encoded to UTF-8. The resulting strings are joined with slashes
and rendered into the URL. If a string is passed as a
``*remainder`` replacement value, it is tacked on to the URL
after being URL-quoted-except-for-embedded-slashes.
If a keyword argument ``_query`` is present, it will be used to
compose a query string that will be tacked on to the end of the
URL. The value of ``_query`` must be a sequence of two-tuples
*or* a data structure with an ``.items()`` method that returns a
sequence of two-tuples (presumably a dictionary). This data
structure will be turned into a query string per the documentation
of :func:`pyramid.encode.urlencode` function. After the query
data is turned into a query string, a leading ``?`` is prepended,
and the resulting string is appended to the generated URL.
.. note::
Python data structures that are passed as ``_query`` which are
sequences or dictionaries are turned into a string under the same
rules as when run through :func:`urllib.urlencode` with the ``doseq``
argument equal to ``True``. This means that sequences can be passed
as values, and a k=v pair will be placed into the query string for
each value.
If a keyword argument ``_anchor`` is present, its string
representation will be used as a named anchor in the generated URL
(e.g. if ``_anchor`` is passed as ``foo`` and the route URL is
``http://example.com/route/url``, the resulting generated URL will
be ``http://example.com/route/url#foo``).
.. note::
If ``_anchor`` is passed as a string, it should be UTF-8 encoded. If
``_anchor`` is passed as a Unicode object, it will be converted to
UTF-8 before being appended to the URL. The anchor value is not
quoted in any way before being appended to the generated URL.
If both ``_anchor`` and ``_query`` are specified, the anchor
element will always follow the query element,
e.g. ``http://example.com?foo=1#bar``.
If any of the keyword arguments ``_scheme``, ``_host``, or ``_port``
is passed and is non-``None``, the provided value will replace the
named portion in the generated URL. For example, if you pass
``_host='foo.com'``, and the URL that would have been generated
without the host replacement is ``http://example.com/a``, the result
will be ``https://foo.com/a``.
Note that if ``_scheme`` is passed as ``https``, and ``_port`` is not
passed, the ``_port`` value is assumed to have been passed as
``443``. Likewise, if ``_scheme`` is passed as ``http`` and
``_port`` is not passed, the ``_port`` value is assumed to have been
passed as ``80``. To avoid this behavior, always explicitly pass
``_port`` whenever you pass ``_scheme``.
If a keyword ``_app_url`` is present, it will be used as the
protocol/hostname/port/leading path prefix of the generated URL.
For example, using an ``_app_url`` of
``http://example.com:8080/foo`` would cause the URL
``http://example.com:8080/foo/fleeb/flub`` to be returned from
this function if the expansion of the route pattern associated
with the ``route_name`` expanded to ``/fleeb/flub``. If
``_app_url`` is not specified, the result of
#.........这里部分代码省略.........
开发者ID:Subbarker,项目名称:online-binder,代码行数:101,代码来源:url.py
示例13: resource_url
def resource_url(self, resource, *elements, **kw):
"""
Generate a string representing the absolute URL of the
:term:`resource` object based on the ``wsgi.url_scheme``,
``HTTP_HOST`` or ``SERVER_NAME`` in the request, plus any
``SCRIPT_NAME``. The overall result of this method is always a
UTF-8 encoded string.
Examples::
request.resource_url(resource) =>
http://example.com/
request.resource_url(resource, 'a.html') =>
http://example.com/a.html
request.resource_url(resource, 'a.html', query={'q':'1'}) =>
http://example.com/a.html?q=1
request.resource_url(resource, 'a.html', anchor='abc') =>
http://example.com/a.html#abc
request.resource_url(resource, app_url='') =>
/
Any positional arguments passed in as ``elements`` must be strings
Unicode objects, or integer objects. These will be joined by slashes
and appended to the generated resource URL. Each of the elements
passed in is URL-quoted before being appended; if any element is
Unicode, it will converted to a UTF-8 bytestring before being
URL-quoted. If any element is an integer, it will be converted to its
string representation before being URL-quoted.
.. warning:: if no ``elements`` arguments are specified, the resource
URL will end with a trailing slash. If any
``elements`` are used, the generated URL will *not*
end in trailing a slash.
If a keyword argument ``query`` is present, it will be used to
compose a query string that will be tacked on to the end of the URL.
The value of ``query`` must be a sequence of two-tuples *or* a data
structure with an ``.items()`` method that returns a sequence of
two-tuples (presumably a dictionary). This data structure will be
turned into a query string per the documentation of
``pyramid.url.urlencode`` function. After the query data is turned
into a query string, a leading ``?`` is prepended, and the resulting
string is appended to the generated URL.
.. note::
Python data structures that are passed as ``query`` which are
sequences or dictionaries are turned into a string under the same
rules as when run through :func:`urllib.urlencode` with the ``doseq``
argument equal to ``True``. This means that sequences can be passed
as values, and a k=v pair will be placed into the query string for
each value.
If a keyword argument ``anchor`` is present, its string
representation will be used as a named anchor in the generated URL
(e.g. if ``anchor`` is passed as ``foo`` and the resource URL is
``http://example.com/resource/url``, the resulting generated URL will
be ``http://example.com/resource/url#foo``).
.. note::
If ``anchor`` is passed as a string, it should be UTF-8 encoded. If
``anchor`` is passed as a Unicode object, it will be converted to
UTF-8 before being appended to the URL. The anchor value is not
quoted in any way before being appended to the generated URL.
If both ``anchor`` and ``query`` are specified, the anchor element
will always follow the query element,
e.g. ``http://example.com?foo=1#bar``.
If any of the keyword arguments ``scheme``, ``host``, or ``port`` is
passed and is non-``None``, the provided value will replace the named
portion in the generated URL. For example, if you pass
``host='foo.com'``, and the URL that would have been generated
without the host replacement is ``http://example.com/a``, the result
will be ``https://foo.com/a``.
If ``scheme`` is passed as ``https``, and an explicit ``port`` is not
passed, the ``port`` value is assumed to have been passed as ``443``.
Likewise, if ``scheme`` is passed as ``http`` and ``port`` is not
passed, the ``port`` value is assumed to have been passed as
``80``. To avoid this behavior, always explicitly pass ``port``
whenever you pass ``scheme``.
If a keyword argument ``app_url`` is passed and is not ``None``, it
should be a string that will be used as the port/hostname/initial
path portion of the generated URL instead of the default request
application URL. For example, if ``app_url='http://foo'``, then the
resulting url of a resource that has a path of ``/baz/bar`` will be
``http://foo/baz/bar``. If you want to generate completely relative
#.........这里部分代码省略.........
开发者ID:Subbarker,项目名称:online-binder,代码行数:101,代码来源:url.py
示例14: resource_url
def resource_url(self, resource, *elements, **kw):
"""
Generate a string representing the absolute URL of the
:term:`resource` object based on the ``wsgi.url_scheme``,
``HTTP_HOST`` or ``SERVER_NAME`` in the request, plus any
``SCRIPT_NAME``. The overall result of this method is always a
UTF-8 encoded string (never Unicode).
Examples::
request.resource_url(resource) =>
http://example.com/
request.resource_url(resource, 'a.html') =>
http://example.com/a.html
request.resource_url(resource, 'a.html', query={'q':'1'}) =>
http://example.com/a.html?q=1
request.resource_url(resource, 'a.html', anchor='abc') =>
http://example.com/a.html#abc
Any positional arguments passed in as ``elements`` must be strings
Unicode objects, or integer objects. These will be joined by slashes
and appended to the generated resource URL. Each of the elements
passed in is URL-quoted before being appended; if any element is
Unicode, it will converted to a UTF-8 bytestring before being
URL-quoted. If any element is an integer, it will be converted to its
string representation before being URL-quoted.
.. warning:: if no ``elements`` arguments are specified, the resource
URL will end with a trailing slash. If any
``elements`` are used, the generated URL will *not*
end in trailing a slash.
If a keyword argument ``query`` is present, it will be used to
compose a query string that will be tacked on to the end of the URL.
The value of ``query`` must be a sequence of two-tuples *or* a data
structure with an ``.items()`` method that returns a sequence of
two-tuples (presumably a dictionary). This data structure will be
turned into a query string per the documentation of
``pyramid.url.urlencode`` function. After the query data is turned
into a query string, a leading ``?`` is prepended, and the resulting
string is appended to the generated URL.
.. note:: Python data structures that are passed as ``query`` which
are sequences or dictionaries are turned into a string
under the same rules as when run through
:func:`urllib.urlencode` with the ``doseq`` argument equal
to ``True``. This means that sequences can be passed as
values, and a k=v pair will be placed into the query string
for each value.
If a keyword argument ``anchor`` is present, its string
representation will be used as a named anchor in the generated URL
(e.g. if ``anchor`` is passed as ``foo`` and the resource URL is
``http://example.com/resource/url``, the resulting generated URL will
be ``http://example.com/resource/url#foo``).
.. note:: If ``anchor`` is passed as a string, it should be UTF-8
encoded. If ``anchor`` is passed as a Unicode object, it
will be converted to UTF-8 before being appended to the
URL. The anchor value is not quoted in any way before
being appended to the generated URL.
If both ``anchor`` and ``query`` are specified, the anchor element
will always follow the query element,
e.g. ``http://example.com?foo=1#bar``.
If the ``resource`` passed in has a ``__resource_url__`` method, it
will be used to generate the URL (scheme, host, port, path) that for
the base resource which is operated upon by this function. See also
:ref:`overriding_resource_url_generation`.
.. note:: If the :term:`resource` used is the result of a
:term:`traversal`, it must be :term:`location`-aware. The
resource can also be the context of a :term:`URL dispatch`;
contexts found this way do not need to be location-aware.
.. note:: If a 'virtual root path' is present in the request
environment (the value of the WSGI environ key
``HTTP_X_VHM_ROOT``), and the resource was obtained via
:term:`traversal`, the URL path will not include the
virtual root prefix (it will be stripped off the left hand
side of the generated URL).
.. note:: For backwards compatibility purposes, this method is also
aliased as the ``model_url`` method of request.
"""
try:
reg = self.registry
except AttributeError:
reg = get_current_registry() # b/c
context_url = reg.queryMultiAdapter((resource, self), IContextURL)
#.........这里部分代码省略.........
开发者ID:DeanHodgkinson,项目名称:pyramid,代码行数:101,代码来源:url.py
示例15: route_url
def route_url(route_name, request, *elements, **kw):
"""Generates a fully qualified URL for a named :app:`Pyramid`
:term:`route configuration`.
.. note:: Calling :meth:`pyramid.Request.route_url` can be used to
achieve the same result as :func:`pyramid.url.route_url`.
Use the route's ``name`` as the first positional argument. Use a
request object as the second positional argument. Additional
positional arguments are appended to the URL as path segments
after it is generated.
Use keyword arguments to supply values which match any dynamic
path elements in the route definition. Raises a :exc:`KeyError`
exception if the URL cannot be generated for any reason (not
enough arguments, for example).
For example, if you've defined a route named "foobar" with the path
``{foo}/{bar}/*traverse``::
route_url('foobar', request, foo='1') => <KeyError exception>
route_url('foobar', request, foo='1', bar='2') => <KeyError exception>
route_url('foobar', request, foo='1', bar='2',
traverse=('a','b')) => http://e.com/1/2/a/b
route_url('foobar', request, foo='1', bar='2',
traverse='/a/b') => http://e.com/1/2/a/b
Values replacing ``:segment`` arguments can be passed as strings
or Unicode objects. They will be encoded to UTF-8 and URL-quoted
before being placed into the generated URL.
Values replacing ``*remainder`` arguments can be passed as strings
*or* tuples of Unicode/string values. If a tuple is passed as a
``*remainder`` replacement value, its values are URL-quoted and
encoded to UTF-8. The resulting strings are joined with slashes
and rendered into the URL. If a string is passed as a
``*remainder`` replacement value, it is tacked on to the URL
untouched.
If a keyword argument ``_query`` is present, it will be used to
compose a query string that will be tacked on to the end of the
URL. The value of ``_query`` must be a sequence of two-tuples
*or* a data structure with an ``.items()`` method that returns a
sequence of two-tuples (presumably a dictionary). This data
structure will be turned into a query string per the documentation
of :func:`pyramid.encode.urlencode` function. After the query
data is turned into a query string, a leading ``?`` is prepended,
and the resulting string is appended to the generated URL.
.. note:: Python data structures that are passed as ``_query``
which are sequences or dictionaries are turned into a
string under the same rules as when run through
:func:`urllib.urlencode` with the ``doseq`` argument
equal to ``True``. This means that sequences can be
passed as values, and a k=v pair will be placed into the
query string for each value.
If a keyword argument ``_anchor`` is present, its string
representation will be used as a named anchor in the generated URL
(e.g. if ``_anchor`` is passed as ``foo`` and the route URL is
``http://example.com/route/url``, the resulting generated URL will
be ``http://example.com/route/url#foo``).
.. note:: If ``_anchor`` is passed as a string, it should be UTF-8
encoded. If ``_anchor`` is passed as a Unicode object, it
will be converted to UTF-8 before being appended to the
URL. The anchor value is not quoted in any way before
being appended to the generated URL.
If both ``_anchor`` and ``_query`` are specified, the anchor
element will always follow the query element,
e.g. ``http://example.com?foo=1#bar``.
If a keyword ``_app_url`` is present, it will be used as the
protocol/hostname/port/leading path prefix of the generated URL.
For example, using an ``_app_url`` of
``http://example.com:8080/foo`` would cause the URL
``http://example.com:8080/foo/fleeb/flub`` to be returned from
this function if the expansion of the route pattern associated
with the ``route_name`` expanded to ``/fleeb/flub``. If
``_app_url`` is not specified, the result of
``request.application_url`` will be used as the prefix (the
default).
This function raises a :exc:`KeyError` if the URL cannot be
generated due to missing replacement names. Extra replacement
names are ignored.
If the route object which matches the ``route_name`` argument has
a :term:`pregenerator`, the ``*elements`` and ``**kw`` arguments
arguments passed to this function might be augmented or changed.
"""
try:
reg = request.registry
except AttributeError:
reg = get_current_registry() # b/c
mapper = reg.getUtility(IRoutesMapper)
route = mapper.get_route(route_name)
#.........这里部分代码省略.........
开发者ID:cjw296,项目名称:pyramid,代码行数:101,代码来源:url.py
示例16: _callFUT
def _callFUT(self, query, doseq=False):
from pyramid.encode import urlencode
return urlencode(query, doseq)
开发者ID:mozilla,项目名称:appsync-vendor,代码行数:3,代码来源:test_encode.py
示例17: resource_url
def resource_url(self, resource, *elements, **kw):
"""
Generate a string representing the absolute URL of the
:term:`resource` object based on the ``wsgi.url_scheme``,
``HTTP_HOST`` or ``SERVER_NAME`` in the request, plus any
``SCRIPT_NAME``. The overall result of this method is always a
UTF-8 encoded string.
Examples::
request.resource_url(resource) =>
http://example.com/
request.resource_url(resource, 'a.html') =>
http://example.com/a.html
request.resource_url(resource, 'a.html', query={'q':'1'}) =>
http://example.com/a.html?q=1
request.resource_url(resource, 'a.html', anchor='abc') =>
http://example.com/a.html#abc
request.resource_url(resource, app_url='') =>
/
Any positional arguments passed in as ``elements`` must be strings
Unicode objects, or integer objects. These will be joined by slashes
and appended to the generated resource URL. Each of the elements
passed in is URL-quoted before being appended; if any element is
Unicode, it will converted to a UTF-8 bytestring before being
URL-quoted. If any element is an integer, it will be converted to its
string representation before being URL-quoted.
.. warning:: if no ``elements`` arguments are specified, the resource
URL will end with a trailing slash. If any
``elements`` are used, the generated URL will *not*
end in a trailing slash.
If a keyword argument ``query`` is present, it will be used to compose
a query string that will be tacked on to the end of the URL. The value
of ``query`` may be a sequence of two-tuples *or* a data structure with
an ``.items()`` method that returns a sequence of two-tuples
(presumably a dictionary). This data structure will be turned into a
query string per the documentation of :func:``pyramid.url.urlencode``
function. This will produce a query string in the
``x-www-form-urlencoded`` encoding. A non-``x-www-form-urlencoded``
query string may be used by passing a *string* value as ``query`` in
which case it will be URL-quoted (e.g. query="foo bar" will become
"foo%20bar"). However, the result will not need to be in ``k=v`` form
as required by ``x-www-form-urlencoded``. After the query data is
turned into a query string, a leading ``?`` is prepended, and the
resulting string is appended to the generated URL.
.. note::
Python data structures that are passed as ``query`` which are
sequences or dictionaries are turned into a string under the same
rules as when run through :func:`urllib.urlencode` with the ``doseq``
argument equal to ``True``. This means that sequences can be passed
as values, and a k=v pair will be placed into the query string for
each value.
.. versionchanged:: 1.5
Allow the ``query`` option to be a string to enable alternative
encodings.
If a keyword argument ``anchor`` is present, its string
representation will be used as a named anchor in the generated URL
(e.g. if ``anchor`` is passed as ``foo`` and the resource URL is
``http://example.com/resource/url``, the resulting generated URL will
be ``http://example.com/resource/url#foo``).
.. note::
If ``anchor`` is passed as a string, it should be UTF-8 encoded. If
``anchor`` is passed as a Unicode object, it will be converted to
UTF-8 before being appended to the URL.
.. versionchanged:: 1.5
The ``anchor`` option will be escaped instead of using
its raw string representation.
If both ``anchor`` and ``query`` are specified, the anchor element
will always follow the query element,
e.g. ``http://example.com?foo=1#bar``.
If any of the keyword arguments ``scheme``, ``host``, or ``port`` is
passed and is non-``None``, the provided value will replace the named
portion in the generated URL. For example, if you pass
``host='foo.com'``, and the URL that would have been generated
without the host replacement is ``http://example.com/a``, the result
will be ``http://foo.com/a``.
If ``scheme`` is passed as ``https``, and an explicit ``port`` is not
#.........这里部分代码省略.........
开发者ID:AdrianTeng,项目名称:pyramid,代码行数:101,代码来源:url.py
示例18: page_url
def page_url(page):
params = request.GET.copy()
params['batch_start'] = str(page * batch_size)
return '%s?%s' % (url, urlencode(params))
开发者ID:mindreframer,项目名称:python-pyramid-stuff,代码行数:4,代码来源:panels.py
注:本文中的pyramid.encode.urlencode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论