本文整理汇总了Python中r2.lib.utils.link_from_url函数的典型用法代码示例。如果您正苦于以下问题:Python link_from_url函数的具体用法?Python link_from_url怎么用?Python link_from_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了link_from_url函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: GET_submit
def GET_submit(self, url, title, then):
"""Submit form."""
if url and not request.get.get('resubmit'):
# check to see if the url has already been submitted
links = link_from_url(url)
if links and len(links) == 1:
return self.redirect(links[0].already_submitted_link)
elif links:
infotext = (strings.multiple_submitted
% links[0].resubmit_link())
res = BoringPage(_("seen it"),
content = wrap_links(links),
infotext = infotext).render()
return res
captcha = Captcha() if c.user.needs_captcha() else None
sr_names = (Subreddit.submit_sr_names(c.user) or
Subreddit.submit_sr_names(None))
return FormPage(_("submit"),
show_sidebar = True,
content=NewLink(url=url or '',
title=title or '',
subreddits = sr_names,
captcha=captcha,
then = then)).render()
开发者ID:JediWatchman,项目名称:reddit,代码行数:26,代码来源:front.py
示例2: GET_submit
def GET_submit(self, url, title, then):
"""Submit form."""
resubmit = request.get.get('resubmit')
if url and not resubmit:
# check to see if the url has already been submitted
links = link_from_url(url)
if links and len(links) == 1:
return self.redirect(links[0].already_submitted_link)
elif links:
infotext = (strings.multiple_submitted
% links[0].resubmit_link())
res = BoringPage(_("seen it"),
content = wrap_links(links),
infotext = infotext).render()
return res
if not c.user_is_loggedin:
raise UserRequiredException
if not (c.default_sr or c.site.can_submit(c.user)):
abort(403, "forbidden")
captcha = Captcha() if c.user.needs_captcha() else None
sr_names = (Subreddit.submit_sr_names(c.user) or
Subreddit.submit_sr_names(None))
return FormPage(_("submit"),
show_sidebar = True,
page_classes=['submit-page'],
content=NewLink(url=url or '',
title=title or '',
subreddits = sr_names,
captcha=captcha,
resubmit=resubmit,
then = then)).render()
开发者ID:Falmarri,项目名称:reddit,代码行数:35,代码来源:front.py
示例3: GET_s
def GET_s(self, rest):
"""/s/http://..., show a given URL with the toolbar. if it's
submitted, redirect to /tb/$id36"""
force_html()
path = demangle_url(request.fullpath)
if not path:
# it was malformed
self.abort404()
# if the domain is shame-banned, bail out.
if is_shamed_domain(path)[0]:
self.abort404()
link = utils.link_from_url(path, multiple = False)
if c.cname and not c.authorized_cname:
# In this case, we make some bad guesses caused by the
# cname frame on unauthorised cnames.
# 1. User types http://foo.com/http://myurl?cheese=brie
# (where foo.com is an unauthorised cname)
# 2. We generate a frame that points to
# http://www.reddit.com/r/foo/http://myurl?cnameframe=0.12345&cheese=brie
# 3. Because we accept everything after the /r/foo/, and
# we've now parsed, modified, and reconstituted that
# URL to add cnameframe, we really can't make any good
# assumptions about what we've done to a potentially
# already broken URL, and we can't assume that we've
# rebuilt it in the way that it was originally
# submitted (if it was)
# We could try to work around this with more guesses (by
# having demangle_url try to remove that param, hoping
# that it's not already a malformed URL, and that we
# haven't re-ordered the GET params, removed
# double-slashes, etc), but for now, we'll just refuse to
# do this operation
return self.abort404()
if link:
# we were able to find it, let's send them to the
# link-id-based URL so that their URL is reusable
return self.redirect(add_sr("/tb/" + link._id36))
title = utils.domain(path)
res = Frame(
title=title,
url=match_current_reddit_subdomain(path),
)
# we don't want clients to think that this URL is actually a
# valid URL for search-indexing or the like
request.environ['usable_error_content'] = spaceCompress(res.render())
abort(404)
开发者ID:AD42,项目名称:reddit,代码行数:53,代码来源:toolbar.py
示例4: GET_toolbar
def GET_toolbar(self, link, url):
"""The visible toolbar, with voting buttons and all"""
if not link:
link = utils.link_from_url(url, multiple = False)
if link:
link = list(wrap_links(link, wrapper = FrameToolbar))
if link:
res = link[0]
elif url:
res = FrameToolbar(link = None,
title = None,
url = url,
expanded = False)
else:
self.abort404()
return spaceCompress(res.render())
开发者ID:DFectuoso,项目名称:culter,代码行数:17,代码来源:toolbar.py
注:本文中的r2.lib.utils.link_from_url函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论