本文整理汇总了Python中sumo.urlresolvers.split_path函数的典型用法代码示例。如果您正苦于以下问题:Python split_path函数的具体用法?Python split_path怎么用?Python split_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了split_path函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _clean_next_url
def _clean_next_url(request):
if 'next' in request.POST:
url = request.POST.get('next')
elif 'next' in request.GET:
url = request.GET.get('next')
elif 'HTTP_REFERER' in request.META:
url = request.META.get('HTTP_REFERER').decode('latin1', 'ignore')
else:
return None
site = Site.objects.get_current()
if not is_safe_url(url, site.domain):
return None
parsed_url = urlparse.urlparse(url)
# Don't redirect right back to login, logout, register, or
# change email pages
locale, register_url = split_path(reverse(
'users.browserid_register'))
locale, change_email_url = split_path(reverse(
'users.change_email'))
LOOPING_NEXT_URLS = [settings.LOGIN_URL, settings.LOGOUT_URL,
register_url, change_email_url]
for looping_url in LOOPING_NEXT_URLS:
if looping_url in parsed_url.path:
return None
# TODO?HACK: can't use urllib.quote_plus because mod_rewrite quotes the
# next url value already.
url = url.replace(' ', '+')
return url
开发者ID:Web5design,项目名称:kuma,代码行数:31,代码来源:views.py
示例2: redirect_url
def redirect_url(self, source_locale=settings.LANGUAGE_CODE):
"""If I am a redirect, return the URL to which I redirect.
Otherwise, return None.
"""
# If a document starts with REDIRECT_HTML and contains any <a> tags
# with hrefs, return the href of the first one. This trick saves us
# from having to parse the HTML every time.
if self.html.startswith(REDIRECT_HTML):
anchors = PyQuery(self.html)('a[href]')
if anchors:
# Articles with a redirect have a link that has the locale
# hardcoded into it, and so by simply redirecting to the given
# link, we end up possibly losing the locale. So, instead,
# we strip out the locale and replace it with the original
# source locale only in the case where an article is going
# from one locale and redirecting it to a different one.
# This only applies when it's a non-default locale because we
# don't want to override the redirects that are forcibly
# changing to (or staying within) a specific locale.
full_url = anchors[0].get('href')
(dest_locale, url) = split_path(full_url)
if (source_locale != dest_locale
and dest_locale == settings.LANGUAGE_CODE):
return '/' + source_locale + '/' + url
return full_url
开发者ID:klrmn,项目名称:kitsune,代码行数:27,代码来源:models.py
示例3: process_request
def process_request(self, request):
prefixer = Prefixer(request)
set_url_prefixer(prefixer)
full_path = prefixer.fix(prefixer.shortened_path)
if 'lang' in request.GET:
# Blank out the locale so that we can set a new one. Remove lang
# from the query params so we don't have an infinite loop.
prefixer.locale = ''
new_path = prefixer.fix(prefixer.shortened_path)
query = dict((smart_str(k), v) for
k, v in request.GET.iteritems() if k != 'lang')
return HttpResponsePermanentRedirect(urlparams(new_path, **query))
if full_path != request.path:
query_string = request.META.get('QUERY_STRING', '')
full_path = urllib.quote(full_path.encode('utf-8'))
if query_string:
full_path = '%s?%s' % (full_path, query_string)
response = HttpResponsePermanentRedirect(full_path)
# Vary on Accept-Language if we changed the locale
old_locale = prefixer.locale
new_locale, _ = split_path(full_path)
if old_locale != new_locale:
response['Vary'] = 'Accept-Language'
return response
request.path_info = '/' + prefixer.shortened_path
request.locale = prefixer.locale
tower.activate(prefixer.locale)
开发者ID:Reinmar,项目名称:kuma,代码行数:34,代码来源:middleware.py
示例4: process_request
def process_request(self, request):
prefixer = Prefixer(request)
set_url_prefixer(prefixer)
full_path = prefixer.fix(prefixer.shortened_path)
if "lang" in request.GET:
# Blank out the locale so that we can set a new one. Remove lang
# from the query params so we don't have an infinite loop.
prefixer.locale = ""
new_path = prefixer.fix(prefixer.shortened_path)
query = dict((smart_str(k), v) for k, v in request.GET.iteritems() if k != "lang")
return HttpResponseRedirect(urlparams(new_path, **query))
if full_path != request.path:
query_string = request.META.get("QUERY_STRING", "")
full_path = urllib.quote(full_path.encode("utf-8"))
if query_string:
full_path = "%s?%s" % (full_path, query_string)
response = HttpResponseRedirect(full_path)
# Vary on Accept-Language if we changed the locale
old_locale = prefixer.locale
new_locale, _ = split_path(full_path)
if old_locale != new_locale:
response["Vary"] = "Accept-Language"
return response
request.path_info = "/" + prefixer.shortened_path
request.LANGUAGE_CODE = prefixer.locale
tower.activate(prefixer.locale)
开发者ID:jasdeepdhillon13,项目名称:kitsune,代码行数:33,代码来源:middleware.py
示例5: from_url
def from_url(cls, url, id_only=False):
"""Returns the question that the URL represents.
If the question doesn't exist or the URL isn't a question URL,
this returns None.
If id_only is requested, we just return the question id and
we don't validate the existence of the question (this saves us
from making a million or so db calls).
"""
parsed = urlparse(url)
locale, path = split_path(parsed.path)
path = '/' + path
try:
view, view_args, view_kwargs = resolve(path)
except Http404:
return None
import questions.views # Views import models; models import views.
if view != questions.views.answers:
return None
question_id = view_kwargs['question_id']
if id_only:
return int(question_id)
try:
question = cls.objects.get(id=question_id)
except cls.DoesNotExist:
return None
return question
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:35,代码来源:models.py
示例6: request
def request(self, **request):
"""Make a request, but prepend a locale if there isn't one already."""
# Fall back to defaults as in the superclass's implementation:
path = request.get("PATH_INFO", self.defaults.get("PATH_INFO", "/"))
locale, shortened = split_path(path)
if not locale:
request["PATH_INFO"] = "/%s/%s" % (settings.LANGUAGE_CODE, shortened)
return super(LocalizingClient, self).request(**request)
开发者ID:unixeO,项目名称:kitsune,代码行数:8,代码来源:__init__.py
示例7: _clean_next_url
def _clean_next_url(request):
if 'next' in request.POST:
url = request.POST.get('next')
elif 'next' in request.GET:
url = request.GET.get('next')
elif 'HTTP_REFERER' in request.META:
url = request.META.get('HTTP_REFERER').decode('latin1', 'ignore')
else:
url = None
if url:
parsed_url = urlparse.urlparse(url)
# Don't redirect outside of site_domain.
# Don't include protocol+domain, so if we are https we stay that way.
# http://bugzil.la/847190
relative_url_prefix = urllib.quote_plus(urllib.quote_plus('//'))
if url.upper().startswith(relative_url_prefix):
url = None
if parsed_url.scheme:
site_domain = Site.objects.get_current().domain
url_domain = parsed_url.netloc
if site_domain != url_domain:
url = None
else:
url = u'?'.join([getattr(parsed_url, x) for x in
('path', 'query') if getattr(parsed_url, x)])
# Don't redirect right back to login, logout, register, or change email
# pages
locale, register_url = split_path(reverse('users.browserid_register'))
locale, change_email_url = split_path(
reverse('users.change_email'))
for looping_url in [settings.LOGIN_URL, settings.LOGOUT_URL,
register_url, change_email_url]:
if looping_url in parsed_url.path:
url = None
# TODO?HACK: can't use urllib.quote_plus because mod_rewrite quotes the
# next url value already.
if url:
url = url.replace(' ', '+')
return url
开发者ID:GPHemsley,项目名称:kuma,代码行数:42,代码来源:views.py
示例8: process_request
def process_request(self, request):
prefixer = Prefixer(request)
set_url_prefixer(prefixer)
full_path = prefixer.fix(prefixer.shortened_path)
if 'lang' in request.GET:
# Blank out the locale so that we can set a new one. Remove lang
# from the query params so we don't have an infinite loop.
prefixer.locale = ''
new_path = prefixer.fix(prefixer.shortened_path)
query = dict((smart_str(k), v) for
k, v in request.GET.iteritems() if k != 'lang')
# 'lang' is only used on the language selection page. If this is
# present it is safe to set language preference for the current
# user.
if request.user.is_anonymous():
cookie = settings.LANGUAGE_COOKIE_NAME
request.session[cookie] = request.GET['lang']
return HttpResponseRedirect(urlparams(new_path, **query))
if full_path != request.path:
query_string = request.META.get('QUERY_STRING', '')
full_path = urllib.quote(full_path.encode('utf-8'))
if query_string:
full_path = '%s?%s' % (full_path, query_string)
response = HttpResponseRedirect(full_path)
# Vary on Accept-Language if we changed the locale
old_locale = prefixer.locale
new_locale, _ = split_path(full_path)
if old_locale != new_locale:
response['Vary'] = 'Accept-Language'
return response
request.path_info = '/' + prefixer.shortened_path
request.LANGUAGE_CODE = prefixer.locale
tower.activate(prefixer.locale)
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:42,代码来源:middleware.py
示例9: from_url
def from_url(url, required_locale=None, id_only=False):
"""Return the approved Document the URL represents, None if there isn't
one.
Return None if the URL is a 404, the URL doesn't point to the right
view, or the indicated document doesn't exist.
To limit the universe of discourse to a certain locale, pass in a
`required_locale`. To fetch only the ID of the returned Document, set
`id_only` to True.
"""
# Extract locale and path from URL:
path = urlparse(url)[2] # never has errors AFAICT
locale, path = split_path(path)
if required_locale and locale != required_locale:
return None
path = '/' + path
try:
view, view_args, view_kwargs = resolve(path)
except Http404:
return None
import wiki.views # Views import models; models import views.
if view != wiki.views.document:
return None
# Map locale-slug pair to Document ID:
doc_query = Document.objects.exclude(current_revision__isnull=True)
if id_only:
doc_query = doc_query.only('id')
try:
return doc_query.get(
locale=locale,
slug=view_kwargs['document_slug'])
except Document.DoesNotExist:
return None
开发者ID:pmclanahan,项目名称:kuma,代码行数:38,代码来源:models.py
示例10: get_soapbox_messages
def get_soapbox_messages(url):
_, path = split_path(url)
return Message.objects.match(path)
开发者ID:hardfire,项目名称:kuma,代码行数:3,代码来源:helpers.py
注:本文中的sumo.urlresolvers.split_path函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论