• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.query_string函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中r2.lib.utils.query_string函数的典型用法代码示例。如果您正苦于以下问题:Python query_string函数的具体用法?Python query_string怎么用?Python query_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了query_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: run

 def run(self, password = None):
     if not c.user_is_loggedin:
         #TODO return a real error page
         d = dict(dest=reddit_link(request.path, url = True) + utils.query_string(request.GET))
         return redirect_to("/login" + utils.query_string(d))
     if (password is not None) and not valid_password(c.user, password):
         c.errors.add(errors.WRONG_PASSWORD)
开发者ID:cmak,项目名称:reddit,代码行数:7,代码来源:validator.py


示例2: listing

    def listing(self, next_suggestions=None):
        self.things, prev, next, bcount, acount = self.get_items()

        self.next_suggestions = next_suggestions
        self._max_num = max(acount, bcount)
        self.after = None
        self.before = None

        if self.nextprev and self.prev_link and prev and bcount > 1:
            p = request.GET.copy()
            p.update({"after": None, "before": prev._fullname, "count": bcount})
            self.before = prev._fullname
            self.prev = request.path + utils.query_string(p)
            p_first = request.GET.copy()
            p_first.update({"after": None, "before": None, "count": None})
            self.first = request.path + utils.query_string(p_first)
        if self.nextprev and self.next_link and next:
            p = request.GET.copy()
            p.update({"after": next._fullname, "before": None, "count": acount})
            self.after = next._fullname
            self.next = request.path + utils.query_string(p)

        for count, thing in enumerate(self.things):
            thing.rowstyle = getattr(thing, "rowstyle", "")
            thing.rowstyle += " " + ("even" if (count % 2) else "odd")

        # TODO: need name for template -- must be better way
        return Wrapped(self)
开发者ID:kvindasAB,项目名称:reddit,代码行数:28,代码来源:listing.py


示例3: listing

    def listing(self, next_suggestions=None):
        self.things, prev, next, bcount, acount = self.get_items()

        self.next_suggestions = next_suggestions
        self._max_num = max(acount, bcount)
        self.after = None
        self.before = None

        if self.nextprev and self.prev_link and prev and bcount > 1:
            p = self.params.copy()
            p.update({"after": None, "before": prev._fullname, "count": bcount})
            self.before = prev._fullname
            self.prev = request.path + utils.query_string(p)
            p_first = self.params.copy()
            p_first.update({"after": None, "before": None, "count": None})
            self.first = request.path + utils.query_string(p_first)
        if self.nextprev and self.next_link and next:
            p = self.params.copy()
            p.update({"after": next._fullname, "before": None, "count": acount})
            self.after = next._fullname
            self.next = request.path + utils.query_string(p)

        for count, thing in enumerate(self.things):
            thing.rowstyle_cls = getattr(thing, "rowstyle_cls", "")
            thing.rowstyle_cls += " " + ("even" if (count % 2) else "odd")
            thing.rowstyle = CachedVariable("rowstyle")

        survey_action = c.cookies.get("survey_action")
        if feature.is_enabled("show_survey") and not survey_action and g.live_config["survey_info"]:
            self.survey = ast.literal_eval(g.live_config["survey_info"])
            self.show_survey = True

        # TODO: need name for template -- must be better way
        return Wrapped(self)
开发者ID:zeantsoi,项目名称:reddit,代码行数:34,代码来源:listing.py


示例4: listing

    def listing(self, next_suggestions=None):
        self.things, prev, next, bcount, acount = self.get_items()

        self.next_suggestions = next_suggestions
        self._max_num = max(acount, bcount)
        self.after = None
        self.before = None

        if self.nextprev and self.prev_link and prev and bcount > 1:
            p = request.GET.copy()
            p.update({'after':None, 'before':prev._fullname, 'count':bcount})
            self.before = prev._fullname
            self.prev = (request.path + utils.query_string(p))
            p_first = request.GET.copy()
            p_first.update({'after':None, 'before':None, 'count':None})
            self.first = (request.path + utils.query_string(p_first))
        if self.nextprev and self.next_link and next:
            p = request.GET.copy()
            p.update({'after':next._fullname, 'before':None, 'count':acount})
            self.after = next._fullname
            self.next = (request.path + utils.query_string(p))

        for count, thing in enumerate(self.things):
            thing.rowstyle = getattr(thing, 'rowstyle', "")
            thing.rowstyle += ' ' + ('even' if (count % 2) else 'odd')

        #TODO: need name for template -- must be better way
        return Wrapped(self)
开发者ID:aburan28,项目名称:reddit,代码行数:28,代码来源:listing.py


示例5: GET_search

    def GET_search(self, query, num, reverse, after, count, sort):
        """Search links page."""
        if query and '.' in query:
            url = sanitize_url(query, require_scheme = True)
            if url:
                return self.redirect("/submit" + query_string({'url':url}))

        q = IndextankQuery(query, c.site, sort)

        num, t, spane = self._search(q, num = num, after = after, reverse = reverse,
                                     count = count)

        if not isinstance(c.site,FakeSubreddit) and not c.cname:
            all_reddits_link = "%s/search%s" % (subreddit.All.path,
                                                query_string({'q': query}))
            d =  {'reddit_name':      c.site.name,
                  'reddit_link':      "http://%s/"%get_domain(cname = c.cname),
                  'all_reddits_link': all_reddits_link}
            infotext = strings.searching_a_reddit % d
        else:
            infotext = None

        res = SearchPage(_('search results'), query, t, num, content=spane,
                         nav_menus = [SearchSortMenu(default=sort)],
                         search_params = dict(sort = sort),
                         infotext = infotext).render()

        return res
开发者ID:JediWatchman,项目名称:reddit,代码行数:28,代码来源:front.py


示例6: GET_search

    def GET_search(self, query, num, time, reverse, after, count, langs, sort):
        """Search links page."""
        if query and '.' in query:
            url = sanitize_url(query, require_scheme=True)
            if url:
                return self.redirect("/submit" + query_string({'url': url}))

        if langs and self.verify_langs_regex.match(langs):
            langs = langs.split(',')
        else:
            langs = c.content_langs

        subreddits = None
        authors = None
        if c.site == subreddit.Friends and c.user_is_loggedin and c.user.friends:
            authors = c.user.friends
        elif isinstance(c.site, MultiReddit):
            subreddits = c.site.sr_ids
        elif not isinstance(c.site, FakeSubreddit):
            subreddits = [c.site._id]

        q = LinkSearchQuery(
            q=query,
            timerange=time,
            langs=langs,
            subreddits=subreddits,
            authors=authors,
            sort=SearchSortMenu.operator(sort))

        num, t, spane = self._search(
            q, num=num, after=after, reverse=reverse, count=count)

        if not isinstance(c.site, FakeSubreddit) and not c.cname:
            all_reddits_link = "%s/search%s" % (subreddit.All.path,
                                                query_string({
                                                    'q': query
                                                }))
            d = {
                'reddit_name': c.site.name,
                'reddit_link': "http://%s/" % get_domain(cname=c.cname),
                'all_reddits_link': all_reddits_link
            }
            infotext = strings.searching_a_reddit % d
        else:
            infotext = None

        res = SearchPage(
            _('search results'),
            query,
            t,
            num,
            content=spane,
            nav_menus=[TimeMenu(default=time),
                       SearchSortMenu(default=sort)],
            search_params=dict(sort=sort, t=time),
            infotext=infotext).render()

        return res
开发者ID:szimpatikus,项目名称:szimpatikus.hu,代码行数:58,代码来源:front.py


示例7: listing

    def listing(self):
        self.things, prev, next, bcount, acount = self.get_items()

        self.max_num = max(acount, bcount)

        if self.nextprev and self.prev_link and prev and bcount > 1:
            p = request.get.copy()
            p.update({'after':None, 'before':prev._fullname, 'count':bcount})
            self.prev = (request.path + utils.query_string(p))
        if self.nextprev and self.next_link and next:
            p = request.get.copy()
            p.update({'after':next._fullname, 'before':None, 'count':acount})
            self.next = (request.path + utils.query_string(p))
        #TODO: need name for template -- must be better way
        return Wrapped(self)
开发者ID:cmak,项目名称:reddit,代码行数:15,代码来源:listing.py


示例8: GET_search

    def GET_search(self, query, num, reverse, after, count, sort, restrict_sr):
        """Search links page."""
        if query and '.' in query:
            url = sanitize_url(query, require_scheme = True)
            if url:
                return self.redirect("/submit" + query_string({'url':url}))

        if not restrict_sr:
            site = DefaultSR()
        else:
            site = c.site

        try:
            q = IndextankQuery(query, site, sort)

            num, t, spane = self._search(q, num = num, after = after, reverse = reverse,
                                         count = count)
            res = SearchPage(_('search results'), query, t, num, content=spane,
                             nav_menus = [SearchSortMenu(default=sort)],
                             search_params = dict(sort = sort),
                             simple=False, site=c.site, restrict_sr=restrict_sr).render()

            return res
        except (IndextankException, socket.error), e:
            return self.search_fail(e)
开发者ID:donslice,项目名称:reddit,代码行数:25,代码来源:front.py


示例9: GET_oldinfo

    def GET_oldinfo(self, article, type, dest, rest=None, comment=''):
        """Legacy: supporting permalink pages from '06,
           and non-search-engine-friendly links"""
        if not (dest in ('comments','related','details')):
                dest = 'comments'
        if type == 'ancient':
            #this could go in config, but it should never change
            max_link_id = 10000000
            new_id = max_link_id - int(article._id)
            return self.redirect('/info/' + to36(new_id) + '/' + rest)
        if type == 'old':
            new_url = "/%s/%s/%s" % \
                      (dest, article._id36, 
                       quote_plus(title_to_url(article.title).encode('utf-8')))
            if not c.default_sr:
                new_url = "/r/%s%s" % (c.site.name, new_url)
            if comment:
                new_url = new_url + "/%s" % comment._id36
            if c.extension:
                new_url = new_url + "/.%s" % c.extension

            new_url = new_url + query_string(request.get)

            # redirect should be smarter and handle extensions, etc.
            return self.redirect(new_url, code=301)
开发者ID:JediWatchman,项目名称:reddit,代码行数:25,代码来源:front.py


示例10: GET_button_content

    def GET_button_content(self, url, title, css, vote, newwindow, width, link):
            
        
        # no buttons on domain listings
        if isinstance(c.site, DomainSR):
            c.site = Default
            return self.redirect(request.path + query_string(request.GET))

        #disable css hack 
        if (css != 'http://blog.wired.com/css/diggsocial.css' and
            css != 'http://www.wired.com/css/diggsocial.css'): 
            css = None 

        if link:
            url = link.url
        wrapper = make_wrapper(Button if vote else ButtonNoBody,
                               url = url, 
                               target = "_new" if newwindow else "_parent",
                               title = title, vote = vote, bgcolor = c.bgcolor,
                               width = width, css = css,
                               button = self.buttontype())

        l = self.get_wrapped_link(url, link, wrapper)
        res = l.render()
        c.response.content = spaceCompress(res)
        return c.response
开发者ID:kevinrose,项目名称:diggit,代码行数:26,代码来源:buttons.py


示例11: GET_search

    def GET_search(self, query, num, reverse, after, count, sort, restrict_sr):
        """Search links page."""
        if query and "." in query:
            url = sanitize_url(query, require_scheme=True)
            if url:
                return self.redirect("/submit" + query_string({"url": url}))

        if not restrict_sr:
            site = DefaultSR()
        else:
            site = c.site

        try:
            cleanup_message = None
            try:
                q = IndextankQuery(query, site, sort)
                if query:
                    query = query.replace("proddit:", "reddit:")

                q = IndextankQuery(query, site, sort)
                num, t, spane = self._search(q, num=num, after=after, reverse=reverse, count=count)
            except InvalidIndextankQuery:

                # strip the query down to a whitelist
                cleaned = re.sub("[^\w\s]+", "", query)
                cleaned = cleaned.lower()

                # if it was nothing but mess, we have to stop
                if not cleaned.strip():
                    num, t, spane = 0, 0, []
                    cleanup_message = strings.completely_invalid_search_query
                else:
                    q = IndextankQuery(cleaned, site, sort)

                    num, t, spane = self._search(q, num=num, after=after, reverse=reverse, count=count)
                    cleanup_message = strings.invalid_search_query % {"clean_query": cleaned}
                cleanup_message += " "
                cleanup_message += strings.search_help % {"search_help": self.search_help_page}

            if query:
                query = query.replace("reddit:", "proddit:")

            res = SearchPage(
                _("search results"),
                query,
                t,
                num,
                content=spane,
                nav_menus=[SearchSortMenu(default=sort)],
                search_params=dict(sort=sort),
                infotext=cleanup_message,
                simple=False,
                site=c.site,
                restrict_sr=restrict_sr,
            ).render()

            return res
        except (IndextankException, socket.error), e:

            return self.search_fail(e)
开发者ID:xolar,项目名称:proddit,代码行数:60,代码来源:front.py


示例12: _sign_url

    def _sign_url(self, url, token):
        """Sign a url for imgix's secured sources.

        Based very heavily on the example code in the docs:
            http://www.imgix.com/docs/tutorials/securing-images

        Arguments:

        * url -- a UrlParser instance of the url to sign.  This object may be
                 modified by the function, so make a copy beforehand if that is
                 a concern.
        * token -- a string token provided by imgix for request signing

        Returns a UrlParser instance with signing parameters.
        """
        # Build the signing value
        signvalue = token + url.path
        if url.query_dict:
          signvalue += query_string(url.query_dict)

        # Calculate MD5 of the signing value.
        signature = hashlib.md5(signvalue).hexdigest()

        url.update_query(s=signature)
        return url
开发者ID:AjaxGb,项目名称:reddit,代码行数:25,代码来源:imgix.py


示例13: GET_s

    def GET_s(self, urloid):
        """/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()

        listing = hot_links_by_url_listing(path, sr=c.site, num=1)
        link = listing.things[0] if listing.things else None

        if link:
            # we were able to find it, let's send them to the
            # toolbar (if enabled) or comments (if not)
            return self.redirect(add_sr("/tb/" + link._id36))
        else:
            # It hasn't been submitted yet. Give them a chance to
            qs = utils.query_string({"url": path})
            return self.redirect(add_sr("/submit" + qs))
开发者ID:pra85,项目名称:reddit,代码行数:25,代码来源:toolbar.py


示例14: GET_search

    def GET_search(self, query, num, reverse, after, count, sort, restrict_sr, syntax):
        """Search links page."""
        if query and "." in query:
            url = sanitize_url(query, require_scheme=True)
            if url:
                return self.redirect("/submit" + query_string({"url": url}))

        if not restrict_sr:
            site = DefaultSR()
        else:
            site = c.site

        if not syntax:
            syntax = SearchQuery.default_syntax

        try:
            cleanup_message = None
            try:
                q = SearchQuery(query, site, sort, syntax=syntax)
                results, etime, spane = self._search(q, num=num, after=after, reverse=reverse, count=count)
            except InvalidQuery:
                # Clean the search of characters that might be causing the
                # InvalidQuery exception. If the cleaned search boils down
                # to an empty string, the search code is expected to bail
                # out early with an empty result set.
                cleaned = re.sub("[^\w\s]+", " ", query)
                cleaned = cleaned.lower().strip()

                q = SearchQuery(cleaned, site, sort)
                results, etime, spane = self._search(q, num=num, after=after, reverse=reverse, count=count)
                if cleaned:
                    cleanup_message = strings.invalid_search_query % {"clean_query": cleaned}
                    cleanup_message += " "
                    cleanup_message += strings.search_help % {"search_help": self.search_help_page}
                else:
                    cleanup_message = strings.completely_invalid_search_query

            res = SearchPage(
                _("search results"),
                query,
                etime,
                results.hits,
                content=spane,
                nav_menus=[SearchSortMenu(default=sort)],
                search_params=dict(sort=sort),
                infotext=cleanup_message,
                simple=False,
                site=c.site,
                restrict_sr=restrict_sr,
                syntax=syntax,
                converted_data=q.converted_data,
                facets=results.subreddit_facets,
                sort=sort,
            ).render()

            return res
        except SearchException + (socket.error,) as e:
            return self.search_fail(e)
开发者ID:nod3x,项目名称:reddit,代码行数:58,代码来源:front.py


示例15: GET_search

    def GET_search(self, query, num, reverse, after, count, sort, restrict_sr,
                   syntax):
        """Search links page."""
        if query and '.' in query:
            url = sanitize_url(query, require_scheme = True)
            if url:
                return self.redirect("/submit" + query_string({'url':url}))

        if not restrict_sr:
            site = DefaultSR()
        else:
            site = c.site
        
        if not syntax:
            syntax = SearchQuery.default_syntax

        try:
            cleanup_message = None
            try:
                q = SearchQuery(query, site, sort, syntax=syntax)
                num, t, spane = self._search(q, num=num, after=after, 
                                             reverse = reverse, count = count)
            except InvalidQuery:
                # strip the query down to a whitelist
                cleaned = re.sub("[^\w\s]+", " ", query)
                cleaned = cleaned.lower()

                # if it was nothing but mess, we have to stop
                if not cleaned.strip():
                    num, t, spane = 0, 0, []
                    cleanup_message = strings.completely_invalid_search_query
                else:
                    q = SearchQuery(cleaned, site, sort)
                    num, t, spane = self._search(q, num=num, after=after,
                                                 reverse=reverse, count=count)
                    cleanup_message = strings.invalid_search_query % {
                                          "clean_query": cleaned
                                      }
                cleanup_message += " "
                cleanup_message += strings.search_help % {"search_help":
                                                          self.search_help_page
                                                          }
            
            res = SearchPage(_('search results'), query, t, num, content=spane,
                             nav_menus=[SearchSortMenu(default=sort)],
                             search_params=dict(sort=sort),
                             infotext=cleanup_message,
                             simple=False, site=c.site,
                             restrict_sr=restrict_sr,
                             syntax=syntax,
                             converted_data=q.converted_data
                             ).render()

            return res
        except SearchException + (socket.error,) as e:
            return self.search_fail(e)
开发者ID:DanHoerst,项目名称:reddit,代码行数:56,代码来源:front.py


示例16: build

    def build(self, base_path=''):
        params = dict(request.GET)
        if self.dest:
            params[self.query_param] = self.dest
        elif self.query_param in params:
            del params[self.query_param]

        self.base_path = base_path
        base_path += query_string(params)
        self.path = base_path.replace('//', '/')
开发者ID:Arinzeokeke,项目名称:reddit,代码行数:10,代码来源:menus.py


示例17: intermediate_redirect

 def intermediate_redirect(cls, form_path):
     """
     Generates a /login or /over18 redirect from the current
     fullpath, after having properly reformated the path via
     format_output_url.  The reformatted original url is encoded
     and added as the "dest" parameter of the new url.
     """
     from r2.lib.template_helpers import add_sr
     dest = cls.format_output_url(request.fullpath)
     path = add_sr(form_path + query_string({"dest": dest}))
     return cls.redirect(path)
开发者ID:Craigus,项目名称:lesswrong,代码行数:11,代码来源:base.py


示例18: intermediate_redirect

    def intermediate_redirect(cls, form_path, sr_path=True, fullpath=None):
        """
        Generates a /login or /over18 redirect from the specified or current
        fullpath, after having properly reformated the path via
        format_output_url.  The reformatted original url is encoded
        and added as the "dest" parameter of the new url.
        """
        from r2.lib.template_helpers import add_sr
        params = dict(dest=cls.format_output_url(fullpath or request.fullurl))
        if c.extension == "widget" and request.GET.get("callback"):
            params['callback'] = request.GET.get("callback")

        path = add_sr(cls.format_output_url(form_path) +
                      query_string(params), sr_path=sr_path)
        abort(302, location=path)
开发者ID:GodOfConquest,项目名称:reddit,代码行数:15,代码来源:base.py


示例19: intermediate_redirect

    def intermediate_redirect(cls, form_path):
        """
        Generates a /login or /over18 redirect from the current
        fullpath, after having properly reformated the path via
        format_output_url.  The reformatted original url is encoded
        and added as the "dest" parameter of the new url.
        """
        from r2.lib.template_helpers import add_sr

        params = dict(dest=cls.format_output_url(request.fullpath))
        if c.extension == "widget" and request.GET.get("callback"):
            params["callback"] = request.GET.get("callback")

        path = add_sr(cls.format_output_url(form_path) + query_string(params))
        return cls.redirect(path)
开发者ID:ketralnis,项目名称:reddit,代码行数:15,代码来源:base.py


示例20: GET_s

    def GET_s(self, urloid):
        """/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()

        listing = hot_links_by_url_listing(path, sr=c.site, num=1)
        link = listing.things[0] if listing.things else None

        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
            # toolbar (if enabled) or comments (if not)
            return self.redirect(add_sr("/tb/" + link._id36))
        else:
            # It hasn't been submitted yet. Give them a chance to
            qs = utils.query_string({"url": path})
            return self.redirect(add_sr("/submit?" + qs))
开发者ID:Acceto,项目名称:reddit,代码行数:47,代码来源:toolbar.py



注:本文中的r2.lib.utils.query_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.randstr函数代码示例发布时间:2022-05-26
下一篇:
Python utils.progress函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap