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

Python filters.safemarkdown函数代码示例

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

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



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

示例1: thing_attr

 def thing_attr(self, thing, attr):
     if attr == "_fullname":
         return "LiveUpdateEvent_" + thing._id
     elif attr == "viewer_count":
         if thing.state == "live":
             return thing.active_visitors
         else:
             return None
     elif attr == "viewer_count_fuzzed":
         if thing.state == "live":
             return thing.active_visitors_fuzzed
         else:
             return None
     elif attr == "description_html":
         return filters.spaceCompress(
             filters.safemarkdown(thing.description, nofollow=True) or "")
     elif attr == "resources_html":
         return filters.spaceCompress(
             filters.safemarkdown(thing.resources, nofollow=True) or "")
     elif attr == "websocket_url":
         if thing.state == "live":
             return websockets.make_url(
                 "/live/" + c.liveupdate_event._id, max_age=24 * 60 * 60)
         else:
             return None
     else:
         return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:rrmckinley,项目名称:reddit-plugin-liveupdate,代码行数:27,代码来源:pages.py


示例2: thing_attr

 def thing_attr(self, thing, attr):
     if attr == "_fullname":
         return "LiveUpdateEvent_" + thing._id
     elif attr == "viewer_count":
         if thing.state == "live":
             return thing.active_visitors
         else:
             return None
     elif attr == "viewer_count_fuzzed":
         if thing.state == "live":
             return thing.active_visitors_fuzzed
         else:
             return None
     elif attr == "total_views":
         # this requires an extra query, so we'll only show it in places
         # where we're just getting one event.
         if not hasattr(thing, "total_views"):
             return None
         return thing.total_views
     elif attr == "description_html":
         return filters.spaceCompress(
             filters.safemarkdown(thing.description, nofollow=True) or "")
     elif attr == "resources_html":
         return filters.spaceCompress(
             filters.safemarkdown(thing.resources, nofollow=True) or "")
     elif attr == "websocket_url":
         if thing.state == "live":
             return websockets.make_url(
                 "/live/" + thing._id, max_age=24 * 60 * 60)
         else:
             return None
     else:
         return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:reddit,项目名称:reddit-plugin-liveupdate,代码行数:33,代码来源:pages.py


示例3: thing_attr

 def thing_attr(self, thing, attr):
     from r2.lib.scraper import get_media_embed
     if attr == "media_embed":
        if (thing.media_object and
            not isinstance(thing.media_object, basestring)):
            media_embed = get_media_embed(thing.media_object)
            if media_embed:
                return dict(scrolling = media_embed.scrolling,
                            width = media_embed.width,
                            height = media_embed.height,
                            content = media_embed.content)
        return dict()
     elif attr == "editted" and not isinstance(thing.editted, bool):
         return (time.mktime(thing.editted.astimezone(pytz.UTC).timetuple())
                 - time.timezone)
     elif attr == 'subreddit':
         return thing.subreddit.name
     elif attr == 'subreddit_id':
         return thing.subreddit._fullname
     elif attr == 'selftext':
         if not thing.expunged:
             return thing.selftext
         else:
             return ''
     elif attr == 'selftext_html':
         if not thing.expunged:
             return safemarkdown(thing.selftext)
         else:
             return safemarkdown(_("[removed]"))
     return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:nborwankar,项目名称:reddit,代码行数:30,代码来源:jsontemplates.py


示例4: thing_attr

 def thing_attr(self, thing, attr):
     from r2.lib.media import get_media_embed
     if attr in ("media_embed", "secure_media_embed"):
         media_object = getattr(thing, attr.replace("_embed", "_object"))
         if media_object and not isinstance(media_object, basestring):
             media_embed = get_media_embed(media_object)
             if media_embed:
                 return {
                     "scrolling": media_embed.scrolling,
                     "width": media_embed.width,
                     "height": media_embed.height,
                     "content": media_embed.content,
                 }
         return {}
     elif attr == "clicked":
         # this hasn't been used in years.
         return False
     elif attr == "editted" and not isinstance(thing.editted, bool):
         return (time.mktime(thing.editted.astimezone(pytz.UTC).timetuple())
                 - time.timezone)
     elif attr == 'subreddit':
         return thing.subreddit.name
     elif attr == 'subreddit_id':
         return thing.subreddit._fullname
     elif attr == 'selftext':
         if not thing.expunged:
             return thing.selftext
         else:
             return ''
     elif attr == 'selftext_html':
         if not thing.expunged:
             return safemarkdown(thing.selftext)
         else:
             return safemarkdown(_("[removed]"))
     return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:Dakta,项目名称:reddit,代码行数:35,代码来源:jsontemplates.py


示例5: POST_edit

    def POST_edit(self, form, jquery, title, description, resources, nsfw):
        """Configure the thread.

        Requires the `settings` permission for this thread.

        See also: [/live/*thread*/about.json](#GET_live_{thread}_about.json).

        """
        if not is_event_configuration_valid(form):
            return

        changes = {}
        if title != c.liveupdate_event.title:
            changes["title"] = title
        if description != c.liveupdate_event.description:
            changes["description"] = description
            changes["description_html"] = safemarkdown(description, nofollow=True) or ""
        if resources != c.liveupdate_event.resources:
            changes["resources"] = resources
            changes["resources_html"] = safemarkdown(resources, nofollow=True) or ""
        _broadcast(type="settings", payload=changes)

        c.liveupdate_event.title = title
        c.liveupdate_event.description = description
        c.liveupdate_event.resources = resources
        c.liveupdate_event.nsfw = nsfw
        c.liveupdate_event._commit()

        form.set_html(".status", _("saved"))
        form.refresh()
开发者ID:Safturento,项目名称:reddit-plugin-liveupdate,代码行数:30,代码来源:controllers.py


示例6: thing_attr

    def thing_attr(self, thing, attr):
        if attr not in self._public_attrs and not thing.can_view(c.user):
            return None

        if attr == "_ups" and thing.hide_subscribers:
            return 0
        # Don't return accounts_active counts in /subreddits
        elif (attr == "accounts_active" and isinstance(c.site, SubSR)):
            return None
        elif attr == 'description_html':
            return safemarkdown(thing.description)
        elif attr == 'public_description_html':
            return safemarkdown(thing.public_description)
        elif attr in ('is_banned', 'is_contributor', 'is_moderator',
                      'is_subscriber'):
            if c.user_is_loggedin:
                check_func = getattr(thing, attr)
                return bool(check_func(c.user))
            return None
        elif attr == 'submit_text_html':
            return safemarkdown(thing.submit_text)
        elif attr == 'community_rules':
            if thing.community_rules:
                return thing.community_rules.split('\n')
            return []
        else:
            return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:Sinacosa,项目名称:reddit,代码行数:27,代码来源:jsontemplates.py


示例7: thing_attr

    def thing_attr(self, thing, attr):
        if attr not in self._public_attrs and not thing.can_view(c.user):
            return None

        if attr == "_ups" and thing.hide_subscribers:
            return 0
        # Don't return accounts_active counts in /subreddits
        elif attr == "accounts_active" and isinstance(c.site, SubSR):
            return None
        elif attr == "description_html":
            return safemarkdown(thing.description)
        elif attr == "public_description_html":
            return safemarkdown(thing.public_description)
        elif attr in ("is_banned", "is_contributor", "is_moderator", "is_subscriber"):
            if c.user_is_loggedin:
                check_func = getattr(thing, attr)
                return bool(check_func(c.user))
            return None
        elif attr == "submit_text_html":
            return safemarkdown(thing.submit_text)
        elif attr == "community_rules":
            if thing.community_rules:
                return thing.community_rules.split("\n")
            return []
        elif attr == "user_sr_style_enabled":
            if c.user_is_loggedin:
                return c.user.use_subreddit_style(thing)
            else:
                return True
        else:
            return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:nickdevereaux,项目名称:reddit,代码行数:31,代码来源:jsontemplates.py


示例8: GET_comments

    def GET_comments(self, link):
        if not link:
            self.abort404()
        if not link.subreddit_slow.can_view(c.user):
            abort(403, 'forbidden')

        links = list(wrap_links(link))
        if not links:
            # they aren't allowed to see this link
            return self.abort(403, 'forbidden')
        link = links[0]

        wrapper = make_wrapper(render_class = StarkComment,
                               target = "_top")
        b = TopCommentBuilder(link, CommentSortMenu.operator('confidence'),
                              wrap = wrapper)

        listing = NestedListing(b, num = 10, # TODO: add config var
                                parent_name = link._fullname)

        raw_bar = strings.comments_panel_text % dict(
            fd_link=link.permalink)

        md_bar = safemarkdown(raw_bar, target="_top")

        res = RedditMin(content=CommentsPanel(link=link,
                                              listing=listing.listing(),
                                              expanded=auto_expand_panel(link),
                                              infobar=md_bar))

        return res.render()
开发者ID:AD42,项目名称:reddit,代码行数:31,代码来源:toolbar.py


示例9: POST_edit

    def POST_edit(self, form, jquery, title, description, timezone):
        if form.has_errors("title", errors.NO_TEXT,
                                    errors.TOO_LONG):
            return

        if form.has_errors("description", errors.TOO_LONG):
            return

        if form.has_errors("timezone", errors.INVALID_TIMEZONE):
            return

        changes = {}
        if title != c.liveupdate_event.title:
            changes["title"] = title
        if description != c.liveupdate_event.description:
            changes["description"] = safemarkdown(description, wrap=False)
        send_websocket_broadcast(type="settings", payload=changes)

        c.liveupdate_event.title = title
        c.liveupdate_event.description = description
        c.liveupdate_event.timezone = timezone.zone
        c.liveupdate_event._commit()

        form.set_html(".status", _("saved"))
        form.refresh()
开发者ID:chromakode,项目名称:reddit-plugin-liveupdate,代码行数:25,代码来源:controllers.py


示例10: GET_document

    def GET_document(self):
        try:
            c.errors = c.errors or ErrorSet()
            # clear cookies the old fashioned way 
            c.cookies = Cookies()

            code =  request.GET.get('code', '')
            try:
                code = int(code)
            except ValueError:
                code = 404
            srname = request.GET.get('srname', '')
            takedown = request.GET.get('takedown', "")

            # StatusBasedRedirect will override this anyway, but we need this
            # here for pagecache to see.
            response.status_int = code

            if srname:
                c.site = Subreddit._by_name(srname)

            if request.GET.has_key('allow_framing'):
                c.allow_framing = bool(request.GET['allow_framing'] == '1')

            if code in (204, 304):
                # NEVER return a content body on 204/304 or downstream
                # caches may become very confused.
                if request.GET.has_key('x-sup-id'):
                    x_sup_id = request.GET.get('x-sup-id')
                    if '\r\n' not in x_sup_id:
                        response.headers['x-sup-id'] = x_sup_id
                return ""
            elif c.render_style not in self.allowed_render_styles:
                return str(code)
            elif c.render_style in extensions.API_TYPES:
                data = request.environ.get('extra_error_data', {'error': code})
                if request.environ.get("WANT_RAW_JSON"):
                    return scriptsafe_dumps(data)
                return websafe_json(json.dumps(data))
            elif takedown and code == 404:
                link = Link._by_fullname(takedown)
                return pages.TakedownPage(link).render()
            elif code == 403:
                return self.send403()
            elif code == 429:
                return self.send429()
            elif code == 500:
                randmin = {'admin': random.choice(self.admins)}
                failien_url = make_failien_url()
                sad_message = safemarkdown(rand_strings.sadmessages % randmin)
                return redditbroke % (failien_url, sad_message)
            elif code == 503:
                return self.send503()
            elif c.site:
                return self.send404()
            else:
                return "page not found"
        except Exception as e:
            return handle_awful_failure("ErrorController.GET_document: %r" % e)
开发者ID:ActivateServices,项目名称:reddit,代码行数:59,代码来源:error.py


示例11: to_serializable

    def to_serializable(self, sr, author, current_user=None):

        return {
            'id': to36(self.id),
            'date': self.date.isoformat(),
            'author': to_serializable_author(author, sr, current_user,
                                             self.is_author_hidden),
            'body': safemarkdown(self.body),
            'isInternal': self.is_internal
        }
开发者ID:zeantsoi,项目名称:reddit,代码行数:10,代码来源:modmail.py


示例12: thing_attr

 def thing_attr(self, thing, attr):
     if attr == "_ups" and thing.hide_subscribers:
         return 0
     # Don't return accounts_active counts in /subreddits
     elif (attr == "accounts_active" and isinstance(c.site, SubSR)):
         return None
     elif attr == 'description_html':
         return safemarkdown(thing.description)
     else:
         return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:jatinpandey,项目名称:reddit,代码行数:10,代码来源:jsontemplates.py


示例13: thing_attr

    def thing_attr(self, thing, attr):
        if attr not in self._public_attrs and not thing.can_view(c.user):
            return None

        if attr == "_ups" and thing.hide_subscribers:
            return 0
        # Don't return accounts_active counts in /subreddits
        elif (attr == "accounts_active" and isinstance(c.site, SubSR)):
            return None
        elif attr == 'description_html':
            return safemarkdown(thing.description)
        elif attr == 'public_description_html':
            return safemarkdown(thing.public_description)
        elif attr == "is_moderator":
            if c.user_is_loggedin:
                return thing.moderator
            return None
        elif attr == "is_contributor":
            if c.user_is_loggedin:
                return thing.contributor
            return None
        elif attr == "is_subscriber":
            if c.user_is_loggedin:
                return thing.subscriber
            return None
        elif attr == 'is_banned':
            if c.user_is_loggedin:
                return thing.banned
            return None
        elif attr == 'submit_text_html':
            return safemarkdown(thing.submit_text)
        elif attr == 'community_rules':
            if thing.community_rules:
                return thing.community_rules.split('\n')
            return []
        elif attr == 'user_sr_style_enabled':
            if c.user_is_loggedin:
                return c.user.use_subreddit_style(thing)
            else:
                return True
        else:
            return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:ActivateServices,项目名称:reddit,代码行数:42,代码来源:jsontemplates.py


示例14: thing_attr

 def thing_attr(self, thing, attr):
     if attr == "was_comment":
         return thing.was_comment
     elif attr == "context":
         return ("" if not thing.was_comment
                 else thing.permalink + "?context=3")
     elif attr == "dest":
         return thing.to.name
     elif attr == "body_html":
         return safemarkdown(thing.body)
     return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:DFectuoso,项目名称:culter,代码行数:11,代码来源:jsontemplates.py


示例15: thing_attr

    def thing_attr(self, thing, attr):
        if attr in self._private_attrs and not thing.can_view(c.user):
            return None

        if attr == "_ups" and thing.hide_subscribers:
            return 0
        # Don't return accounts_active counts in /subreddits
        elif attr == "accounts_active" and isinstance(c.site, SubSR):
            return None
        elif attr == "description_html":
            return safemarkdown(thing.description)
        elif attr in ("is_banned", "is_contributor", "is_moderator", "is_subscriber"):
            if c.user_is_loggedin:
                check_func = getattr(thing, attr)
                return bool(check_func(c.user))
            return None
        elif attr == "submit_text_html":
            return safemarkdown(thing.submit_text)
        else:
            return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:B-DAP,项目名称:reddit,代码行数:20,代码来源:jsontemplates.py


示例16: thing_attr

 def thing_attr(self, thing, attr):
     # Don't reveal revenue information via /r/lounge's subscribers
     if attr == "_ups" and g.lounge_reddit and thing.name == g.lounge_reddit:
         return 0
     # Don't return accounts_active counts in /subreddits
     elif attr == "accounts_active" and isinstance(c.site, SubSR):
         return None
     elif attr == "description_html":
         return safemarkdown(thing.description)
     else:
         return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:ZackiMcWoo,项目名称:reddit,代码行数:11,代码来源:jsontemplates.py


示例17: thing_attr

 def thing_attr(self, thing, attr):
     if attr == "_fullname":
         return "LiveUpdateEvent_" + thing._id
     elif attr == "viewer_count":
         return thing.active_visitors
     elif attr == "viewer_count_fuzzed":
         return thing.active_visitors_fuzzed
     elif attr == "description_html":
         return filters.spaceCompress(
             filters.safemarkdown(thing.description) or "")
     else:
         return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:sol2tice,项目名称:peachtree,代码行数:12,代码来源:pages.py


示例18: send404

    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site._spam and not c.user_is_admin:
            message = (strings.banned_subreddit % dict(link = '/feedback'))

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
开发者ID:rajbot,项目名称:tikical,代码行数:12,代码来源:error.py


示例19: send404

    def send404(self):
        c.response.status_code = 404
        if "usable_error_content" in request.environ:
            return request.environ["usable_error_content"]
        if c.site.spammy() and not c.user_is_admin:
            subject = "the subreddit /r/%s has been incorrectly banned" % c.site.name
            lnk = "/r/redditrequest/submit?url=%s&title=%s" % (
                url_escape("http://%s/r/%s" % (g.domain, c.site.name)),
                ("the subreddit /r/%s has been incorrectly banned" % c.site.name),
            )
            message = strings.banned_subreddit % dict(link=lnk)

            res = pages.RedditError(_("this reddit has been banned"), unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
开发者ID:nstandif,项目名称:reddit,代码行数:16,代码来源:error.py


示例20: thing_attr

 def thing_attr(self, thing, attr):
     if attr == "_ups" and thing.hide_subscribers:
         return 0
     # Don't return accounts_active counts in /subreddits
     elif (attr == "accounts_active" and isinstance(c.site, SubSR)):
         return None
     elif attr == 'description_html':
         return safemarkdown(thing.description)
     elif attr in ('is_banned', 'is_contributor', 'is_moderator',
                   'is_subscriber'):
         if c.user_is_loggedin:
             check_func = getattr(thing, attr)
             return bool(check_func(c.user))
         return None
     else:
         return ThingJsonTemplate.thing_attr(self, thing, attr)
开发者ID:mloesch,项目名称:reddit,代码行数:16,代码来源:jsontemplates.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python filters.spaceCompress函数代码示例发布时间:2022-05-26
下一篇:
Python filters._force_utf8函数代码示例发布时间: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