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

Python text.shorten_line函数代码示例

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

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



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

示例1: render_timeline_event

 def render_timeline_event(self, context, field, event):
     bp_resource, bp, bc = event[3]
     compat_format_0_11_2 = 'oneliner'
     if hasattr(context, '_hints'):
          compat_format_0_11_2 = None
     if bc: # A blog comment
         if field == 'url':
             return context.href.blog(bp.name) + '#comment-%d' % bc.number
         elif field == 'title':
             return tag('Blog: ', tag.em(bp.title), ' comment added')
         elif field == 'description':
             comment = compat_format_0_11_2 and shorten_line(bc.comment) \
                         or bc.comment
             return format_to(self.env, compat_format_0_11_2,
                         context(resource=bp_resource), comment)
     else: # A blog post
         if field == 'url':
             return context.href.blog(bp.name)
         elif field == 'title':
             return tag('Blog: ', tag.em(bp.title),
                     bp.version > 1 and ' edited' or ' created')
         elif field == 'description':
             comment = compat_format_0_11_2 and shorten_line(bp.version_comment) \
                         or bp.version_comment
             return format_to(self.env, compat_format_0_11_2,
                     context(resource=bp_resource), comment)
开发者ID:renwofei423,项目名称:tracfullblog,代码行数:26,代码来源:web_ui.py


示例2: short_value

 def short_value(self):
     if self.is_scalar:
         if isinstance(self.value, basestring):
             value = self.value
             if not isinstance(self.value, unicode):
                 value = unicode(self.value, 'utf-8', 'replace')
             return tag.q(shorten_line(value, 60)).generate()
         else:
             return shorten_line(repr(self.value), 60)
     elif self.is_collection:
         if isinstance(self.value, (dict, DictMixin)):
             return u'{…}'
         elif isinstance(self.value, list):
             return u'[…]'
         elif isinstance(self.value, tuple):
             return u'(…)'
         elif isinstance(self.value, set):
             return u'set([…])'
         elif isinstance(self.value, frozenset):
             return u'frozenset([…])'
     else:
         try:
             return tag.code(shorten_line(str(self.value), 60))
         except:
             return '?'
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:25,代码来源:debugger.py


示例3: _ticket_links

def _ticket_links(env, formatter, t, a_class=""):
    """Build links to tickets."""
    tkt_id = str(t.get("id"))
    status = t.get("status")
    summary = to_unicode(t.get("summary"))
    owner = to_unicode(t.get("owner"))
    description = to_unicode(t.get("description"))
    url = t.get("href")

    if status == "closed":
        a_class = a_class + "closed"
    else:
        a_class = a_class + "open"

    # Reduce content for tooltips.
    markup = format_to_html(env, formatter.context, description)
    extractor = TextExtractor()
    extractor.feed(markup)
    tip = tag.span(shorten_line(extractor.getvalue()))

    ticket = tag.a("#" + tkt_id, href=url)
    ticket(tip, class_="tip", target="_blank")
    ticket = tag.div(ticket, class_=a_class, align="left")
    # Fix stripping of regular leading space in IE.
    blank = " "
    ticket(Markup(blank), summary, " (", owner, ")")

    summary = tag(summary, " (", owner, ")")
    ticket_short = tag.span(tag.a("#" + tkt_id, href=url, target="_blank", title_=summary), class_=a_class)
    return ticket, ticket_short
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:30,代码来源:macros.py


示例4: render_timeline_event

 def render_timeline_event(self, context, field, event):
     ticket,summary,status,resolution,type, started, comment = event[4]
     if field == 'url':
         return context.href.ticket(ticket.id)
     elif field == 'title':
         title = TicketSystem(self.env).format_summary(summary, status,
                                                       resolution, type)
         return tag('Work ', started and 'stopped' or 'started',
                    ' on Ticket ', tag.em('#', ticket.id, title=title),
                    ' (', shorten_line(summary), ') ')
     elif field == 'description':
         if self.config['timeline'].getbool('abbreviated_messages'):
             comment = shorten_line(comment)
         markup = format_to_oneliner(self.env, context(resource=ticket),
                                     comment)
         return markup
开发者ID:lexqt,项目名称:EduTracTicketWorklog,代码行数:16,代码来源:timeline_hook.py


示例5: get_search_results

 def get_search_results(self, req, terms, filters):
     """
     Search through requirements.
     
     The search term may be <x y z> or x-y-z; both are interpreted as
     component, fp, and object.
     """
     
     if not 'requirement' in filters:
         return
     
     if re.match(r'^([a-zA-Z_\d]+)-([a-zA-Z_\d]+)-([a-zA-Z_\d]+)$', terms[0]):
         terms = string.split(terms[0], '-')
         
     db = self.env.get_db_cnx()
     sql, args = search_to_sql(db, ['b.newvalue'], terms)
     sql2, args2 = search_to_sql(db, ['a.component', 'a.fp', 'a.object',
                                      'a.description', 'a.creator'], terms)
     
     cursor = db.cursor()
     cursor.execute("SELECT DISTINCT a.component, a.fp, a.object, "
                    "a.description, a.creator, a.time "
                    "FROM requirement a "
                    "LEFT JOIN requirement_change b "
                    "ON a.component = b.component AND a.fp = b.fp AND a.object = b.object "
                    "WHERE (b.field='comment' AND %s ) OR %s" % (sql, sql2),
                    args + args2)
     
     for component, fp, object, desc, creator, date in cursor:
         requirement = '<%s %s %s> ' % (component, fp, object)
         yield (req.href.requirement('%s-%s-%s' % (component, fp, object)),
                requirement + shorten_line(desc),
                date, creator, shorten_result(desc, terms))
开发者ID:cyphactor,项目名称:lifecyclemanager,代码行数:33,代码来源:api.py


示例6: _link_refs

 def _link_refs(self, req, refs_text, verbose_link=False):
     items_tag = None
     items, verbose_items = [], []
     elem = verbose_elem = "#%s" % refs_text
     try:
         c = self.cursor
         c.execute("SELECT id,name FROM assets_feature WHERE id ='%s'" % refs_text)
         row = c.fetchone()
         if row:
             title = shorten_line(row[1])
             attr = {
                 "class_": "assigned",
                 "href": "/splice/tractab/SPLICE/projects/feature/" + str(row[0]),
                 "title": title,
             }
             elem = tag.a("#%s %s" % (refs_text, title), **attr)
             verbose_elem = tag.a("#%s %s" % (refs_text, title), **attr)
     except ResourceNotFound:
         pass  # not supposed to happen, just in case
     items.extend([elem, ", "])
     verbose_items.extend([verbose_elem, tag.br()])
     if items:
         items_tag = [tag.span(items[:-1], id="tref_ticketid")]
         if verbose_link:
             vattr = {"id": "tref_summary", "class_": "tref-display-none"}
             items_tag.append(tag.span(verbose_items[:-1], **vattr))
     return tag(items_tag)
开发者ID:karlamalta,项目名称:ProjetoFinal,代码行数:27,代码来源:web_ui.py


示例7: get_search_results

    def get_search_results(self, req, terms, filters):
        if not 'wiki' in filters:
            return
        db = self.env.get_db_cnx()
        sql_query, args = search_to_sql(db, ['w1.name', 'w1.author', 'w1.text'],
                                        terms)
        cursor = db.cursor()
        cursor.execute("SELECT w1.name,w1.time,w1.author,w1.text "
                       "FROM wiki w1,"
                       "(SELECT name,max(version) AS ver "
                       "FROM wiki GROUP BY name) w2 "
                       "WHERE w1.version = w2.ver AND w1.name = w2.name "
                       "AND " + sql_query, args)

        wiki_realm = Resource('wiki')
        for name, ts, author, text in cursor:
            page = wiki_realm(id=name)
            if 'WIKI_VIEW' in req.perm(page):
                yield (get_resource_url(self.env, page, req.href),
                       '%s: %s' % (name, shorten_line(text)),
                       datetime.fromtimestamp(ts, utc), author,
                       shorten_result(text, terms))
        
        # Attachments
        for result in AttachmentModule(self.env).get_search_results(
            req, wiki_realm, terms):
            yield result
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:27,代码来源:web_ui.py


示例8: train

    def train(self, req, log_id, spam=True):
        environ = {}
        for name, value in req.environ.items():
            if not name.startswith('HTTP_'):
                environ[name] = value

        entry = LogEntry.fetch(self.env, log_id)
        if entry:
            self.log.debug('Marking as %s: %r submitted by "%s"',
                           spam and 'spam' or 'ham',
                           shorten_line(entry.content),
                           entry.author)
            fakeenv = environ.copy()
            for header in entry.headers.splitlines():
                name, value = header.split(':', 1)
                if name == 'Cookie': # breaks SimpleCookie somehow
                    continue
                cgi_name = 'HTTP_%s' % name.strip().replace('-', '_').upper()
                fakeenv[cgi_name] = value.strip()
            fakeenv['REQUEST_METHOD'] = 'POST'
            fakeenv['PATH_INFO'] = entry.path
            fakeenv['wsgi.input'] = StringIO('')
            fakeenv['REMOTE_ADDR'] = entry.ipnr
            if entry.authenticated:
                fakeenv['REMOTE_USER'] = entry.author

            for strategy in self.strategies:
                strategy.train(Request(fakeenv, None),
                               entry.author or 'anonymous',
                               entry.content, spam=spam)

            entry.update(rejected=spam)
开发者ID:lamby,项目名称:pkg-trac-spamfilter,代码行数:32,代码来源:api.py


示例9: changeset_added

    def changeset_added(self, repos, changeset):
        """Called after a changeset has been added to a repository."""
        #Index the commit message
        so = FullTextSearchObject(
                self.project, changeset.resource,
                title=u'[%s]: %s' % (changeset.rev,
                                       shorten_line(changeset.message)),
                oneline=shorten_result(changeset.message),
                body=changeset.message,
                author=changeset.author,
                created=changeset.date,
                changed=changeset.date,
                )
        self.backend.create(so, quiet=True)
        self._update_changeset(changeset)

        # Index the file contents of this revision, a changeset can involve
        # thousands of files - so submit in batches to avoid exceeding the
        # available file handles
        sos = (so for so in self._changes(repos, changeset))
        for chunk in grouper(sos, 25):
            try:
                self.backend.add(chunk, quiet=True)
                self.log.debug("Indexed %i repository changes at revision %i",
                               len(chunk), changeset.rev)
            finally:
                for so in chunk:
                    if hasattr(so.body, 'close'):
                        so.body.close()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:29,代码来源:fulltextsearch.py


示例10: _link_tickets

    def _link_tickets(self, req, tickets, fetch_tickets=False):
        items = []

        for i, word in enumerate(re.split(r'([;,\s]+)', tickets or '')):
            if i % 2:
                items.append(word)
            elif word:
                try:
                    ticketid = int(word)
                except ValueError:
                    return None
                word = '#%s' % word

                if fetch_tickets:
                    try:
                        ticket = Ticket(self.env, ticketid)
                        if 'TICKET_VIEW' in req.perm(ticket.resource):
                            word = \
                                tag.a(
                                    '#%s' % ticket.id,
                                    class_=ticket['status'],
                                    href=req.href.ticket(int(ticket.id)),
                                    title=shorten_line(ticket['summary'])
                                )
                    except ResourceNotFound:
                        pass

                items.append(word)

        if items:
            return tag(items)
        else:
            return None
开发者ID:lexqt,项目名称:EduTracMasterTickets,代码行数:33,代码来源:web_ui.py


示例11: format_summary

 def format_summary(self, summary, status=None, resolution=None, type=None):
     summary = shorten_line(summary)
     if type:
         summary = type + ': ' + summary
     if status:
         if status == 'closed' and resolution:
             status += ': ' + resolution
         return "%s (%s)" % (summary, status)
     else:
         return summary
开发者ID:twisted-infra,项目名称:twisted-trac-source,代码行数:10,代码来源:api.py


示例12: _index_milestone

 def _index_milestone(self, milestone):
     so = FullTextSearchObject(
         self.project,
         milestone.resource,
         title=u"%s: %s" % (milestone.name, shorten_line(milestone.description)),
         changed=milestone.completed or milestone.due or datetime.now(utc),
         involved=(),
         popularity=0,  # FIXME
         oneline=shorten_result(milestone.description),
         body=milestone.description,
     )
     self.backend.create(so, quiet=True)
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-solr,代码行数:12,代码来源:fulltextsearch.py


示例13: render_timeline_event

 def render_timeline_event(self, context, field, event):
     bp_resource, bp, bc = event[3]
     compat_format_0_11_2 = "oneliner"
     if hasattr(context, "_hints"):
         compat_format_0_11_2 = None
     if bc:  # A blog comment
         if field == "url":
             return context.href.blog(bp.name) + "#comment-%d" % bc.number
         elif field == "title":
             return tag("Blog: ", tag.em(bp.title), " comment added")
         elif field == "description":
             comment = compat_format_0_11_2 and shorten_line(bc.comment) or bc.comment
             return format_to(self.env, compat_format_0_11_2, context(resource=bp_resource), comment)
     else:  # A blog post
         if field == "url":
             return context.href.blog(bp.name)
         elif field == "title":
             return tag("Blog: ", tag.em(bp.title), bp.version > 1 and " edited" or " created")
         elif field == "description":
             comment = compat_format_0_11_2 and shorten_line(bp.version_comment) or bp.version_comment
             return format_to(self.env, compat_format_0_11_2, context(resource=bp_resource), comment)
开发者ID:kzhamaji,项目名称:TracFullBlogPlugin,代码行数:21,代码来源:web_ui.py


示例14: _link_textarea

 def _link_textarea(self, req, refs_text):
     items = []
     for ref_id in sorted(cnv_text2list(refs_text)):
         elem = u"#%s" % ref_id
         try:
             ticket = Ticket(self.env, ref_id)
             if "TICKET_VIEW" in req.perm(ticket.resource):
                 title = shorten_line(ticket["summary"])
                 elem = u"#%s %s" % (ref_id, title)
         except ResourceNotFound:
             pass  # not supposed to happen, just in case
         items.extend([elem, u", "])
     return u"".join(item for item in items[:-1])
开发者ID:karlamalta,项目名称:ProjetoFinal,代码行数:13,代码来源:web_ui.py


示例15: test

    def test(self, req, author, content, ip):
        i = req.args.getfirst(self.name)
        h = req.args.getfirst(self.name_hidden)
        r = self.getlink(req)

        if i and h:
            i = shorten_line(javascript_quote(i), 50)
            h = shorten_line(javascript_quote(h), 50)
            return -abs(self.karma_points), \
                   N_("Both trap fields says this is spam (%s, %s)"), i, h
        elif i:
            i = shorten_line(javascript_quote(i), 50)
            return -abs(self.karma_points), \
                   N_("Invisible trap field says this is spam (%s)"), i
        elif h:
            h = shorten_line(javascript_quote(h), 50)
            return -abs(self.karma_points), \
                   N_("Hidden trap field says this is spam (%s)"), h
        elif r:
            r = shorten_line(javascript_quote(r), 50)
            return -abs(self.karma_points), \
                   N_("Register trap field starts with HTTP URL (%s)"), r
开发者ID:Puppet-Finland,项目名称:trac,代码行数:22,代码来源:trapfield.py


示例16: _link

 def _link(resource):
     if resource.realm == 'tag':
         # Keep realm selection in tag links.
         return builder.a(resource.id,
                          href=self.get_href(req, tag=resource))
     elif resource.realm == 'ticket':
         # Return resource link including ticket status dependend
         #   class to allow for common Trac ticket link style.
         ticket = Ticket(env, resource.id)
         return builder.a('#%s' % ticket.id,
                          class_=ticket['status'],
                          href=formatter.href.ticket(ticket.id),
                          title=shorten_line(ticket['summary']))
     return render_resource_link(env, context, resource, 'compact')
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:14,代码来源:macros.py


示例17: render_property

 def render_property(self, name, mode, context, props):
     repos, value = props[name]
     if name == 'transplant_source':
         try:
             chgset = MercurialChangeset(repos, value)
             link = tag.a(chgset.rev, class_="changeset",
                          title=shorten_line(chgset.message),
                          href=context.href.changeset(short(value),
                                                      repos.reponame))
         except LookupError:
             link = tag.a(hex(value), class_="missing changeset",
                          title=_("no such changeset"), rel="nofollow")
         return RenderedProperty(name=_("Transplant:"), content=link,
                                 name_attributes=[("class", "property")])
开发者ID:dokipen,项目名称:trac-hg-plugin,代码行数:14,代码来源:backend.py


示例18: get_timeline_events

    def get_timeline_events(self, req, start, stop, filters):
        if 'changeset' in filters:
            format = req.args.get('format')
            wiki_format = self.wiki_format_messages
            show_files = self.timeline_show_files
            db = self.env.get_db_cnx()
            repos = self.env.get_repository(req.authname)
            for chgset in repos.get_changesets(start, stop):
                message = chgset.message or '--'
                if wiki_format:
                    shortlog = wiki_to_oneliner(message, self.env, db,
                                                shorten=True)
                else:
                    shortlog = shorten_line(message)

                if format == 'rss':
                    title = Markup(u'변경사항 [%s]: %s', chgset.rev, shortlog)
                    href = req.abs_href.changeset(chgset.rev)
                    if wiki_format:
                        message = wiki_to_html(message, self.env, req, db,
                                               absurls=True)
                    else:
                        message = html.PRE(message)
                else:
                    title = Markup(u'변경사항 <em>[%s]</em> : %s에 의해 수정됨', chgset.rev,
                                   chgset.author)
                    href = req.href.changeset(chgset.rev)

                    if wiki_format:
                        if self.timeline_long_messages:
                            message = wiki_to_html(message, self.env, req, db,
                                                   absurls=True)
                        else:
                            message = wiki_to_oneliner(message, self.env, db,
                                                       shorten=True)
                    else:
                        message = shortlog

                if show_files and req.perm.has_permission('BROWSER_VIEW'):
                    files = []
                    for chg in chgset.get_changes():
                        if show_files > 0 and len(files) >= show_files:
                            files.append(html.LI(Markup('&hellip;')))
                            break
                        files.append(html.LI(html.DIV(class_=chg[2]),
                                             chg[0] or '/'))
                    message = html.UL(files, class_="changes") + message

                yield 'changeset', href, title, chgset.date, chgset.author,\
                      message
开发者ID:yeoupooh,项目名称:tow,代码行数:50,代码来源:changeset.py


示例19: get_search_results

 def get_search_results(self, req, terms, filters):
     if not 'changeset' in filters:
         return
     repos = self.env.get_repository(req.authname)
     db = self.env.get_db_cnx()
     sql, args = search_to_sql(db, ['message', 'author'], terms)
     cursor = db.cursor()
     cursor.execute("SELECT rev,time,author,message "
                    "FROM revision WHERE " + sql, args)
     for rev, date, author, log in cursor:
         if not repos.authz.has_permission_for_changeset(rev):
             continue
         yield (req.href.changeset(rev),
                '[%s]: %s' % (rev, shorten_line(log)),
                date, author, shorten_result(log, terms))
开发者ID:yeoupooh,项目名称:tow,代码行数:15,代码来源:changeset.py


示例20: _format_revision_link

 def _format_revision_link(self, formatter, ns, reponame, rev, label,
                           fullmatch=None):
     rev, params, fragment = formatter.split_link(rev)
     try:
         repos = RepositoryManager(self.env).get_repository(reponame)
         if repos:
             changeset = repos.get_changeset(rev)
             return tag.a(label, class_="changeset",
                          title=shorten_line(changeset.message),
                          href=(formatter.href.changeset(rev) +
                                params + fragment))
     except NoSuchChangeset:
         pass
     return tag.a(label, class_="missing changeset", rel="nofollow",
                  href=formatter.href.changeset(rev))
开发者ID:dafrito,项目名称:trac-mirror,代码行数:15,代码来源:revision_links.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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