当前位置: 首页>>代码示例>>Python>>正文


Python tower.strip_whitespace函数代码示例

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


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

示例1: tweak_message

def tweak_message(message):
    """We piggyback on jinja2's babel_extract() (really, Babel's extract_*
    functions) but they don't support some things we need so this function will
    tweak the message.  Specifically:

        1) We strip whitespace from the msgid.  Jinja2 will only strip
            whitespace from the ends of a string so linebreaks show up in
            your .po files still.

        2) Babel doesn't support context (msgctxt).  We hack that in ourselves
            here.
    """
    if isinstance(message, basestring):
        message = strip_whitespace(message)
    elif isinstance(message, tuple):
        # A tuple of 2 has context, 3 is plural, 4 is plural with context
        if len(message) == 2:
            message = add_context(message[1], message[0])
        elif len(message) == 3:
            singular, plural, num = message
            message = (strip_whitespace(singular),
                       strip_whitespace(plural),
                       num)
        elif len(message) == 4:
            singular, plural, num, ctxt = message
            message = (add_context(ctxt, strip_whitespace(singular)),
                       add_context(ctxt, strip_whitespace(plural)),
                       num)
    return message
开发者ID:ozten,项目名称:tower,代码行数:29,代码来源:extract.py

示例2: test_updated_timestamp

 def test_updated_timestamp(self):
     self._generate()
     r = self.client.get(urlparams(self.url, sort='updated'))
     items = pq(r.content)('.primary .item')
     for idx, c in enumerate(r.context['pager'].object_list):
         eq_(strip_whitespace(items.eq(idx).find('.modified').text()),
             'Updated %s' % strip_whitespace(datetime_filter(c.modified)))
开发者ID:AALEKH,项目名称:zamboni,代码行数:7,代码来源:test_views.py

示例3: test_updated_timestamp

 def test_updated_timestamp(self):
     self._generate()
     r = self.client.get(urlparams(self.url, sort="updated"))
     items = pq(r.content)(".primary .item")
     for idx, c in enumerate(r.context["pager"].object_list):
         eq_(
             strip_whitespace(items.eq(idx).find(".modified").text()),
             "Updated %s" % strip_whitespace(datetime_filter(c.modified)),
         )
开发者ID:mnoorenberghe,项目名称:zamboni,代码行数:9,代码来源:test_views.py

示例4: handle

    def handle(self, *args, **options):
        try:
            apps = settings.DB_LOCALIZE
        except AttributeError:
            raise CommandError('DB_LOCALIZE setting is not defined!')

        strings = []
        for app, models in apps.items():
            for model, params in models.items():
                model_class = get_model(app, model)
                attrs = params['attrs']
                qs = model_class.objects.all().values_list(*attrs).distinct()
                for item in qs:
                    for i in range(len(attrs)):
                        msg = {
                            'id': strip_whitespace(item[i]),
                            'context': 'DB: %s.%s.%s' % (app, model, attrs[i]),
                            'comments': params.get('comments')}
                        strings.append(msg)

        py_file = os.path.expanduser(options.get('outputfile'))
        py_file = os.path.abspath(py_file)

        print 'Outputting db strings to: {filename}'.format(filename=py_file)
        with open(py_file, 'w+') as f:
            f.write(HEADER)
            f.write('from tower import ugettext as _\n\n')
            for s in strings:
                comments = s['comments']
                if comments:
                    for c in comments:
                        f.write(u'# {comment}\n'.format(comment=c).encode('utf8'))

                f.write(u'_("""{id}""", "{context}")\n'.format(id=s['id'], context=s['context'])
                        .encode('utf8'))
开发者ID:rbillings,项目名称:kitsune,代码行数:35,代码来源:extract_db.py

示例5: test_updated_date

 def test_updated_date(self):
     doc = pq(self.client.get(urlparams(self.url, sort='updated')).content)
     for item in doc('.items .item'):
         item = pq(item)
         addon_id = item('.install').attr('data-addon')
         ts = Addon.objects.get(id=addon_id).last_updated
         eq_(item('.updated').text(),
             'Updated %s' % strip_whitespace(datetime_filter(ts)))
开发者ID:PinZhang,项目名称:zamboni,代码行数:8,代码来源:tests.py

示例6: test_created_not_updated

    def test_created_not_updated(self):
        """Don't display the updated date but the created date for themes."""
        r = self.client.get(self.url)
        doc = pq(r.content)
        details = doc('.addon-info li')

        # There's no "Last Updated" entry.
        assert not any('Last Updated' in node.text_content()
                       for node in details)

        # But there's a "Created" entry.
        for detail in details:
            if detail.find('h3').text_content() == 'Created':
                created = detail.find('p').text_content()
                eq_(created,
                    strip_whitespace(datetime_filter(self.addon.created)))
                break  # Needed, or we go in the "else" clause.
        else:
            assert False, 'No "Created" entry found.'
开发者ID:jvillalobos,项目名称:olympia,代码行数:19,代码来源:test_views.py

示例7: _parse_block

 def _parse_block(self, parser, allow_pluralize):
     parse_block = InternationalizationExtension._parse_block
     ref, buffer = parse_block(self, parser, allow_pluralize)
     return ref, strip_whitespace(buffer)
开发者ID:Osmose,项目名称:tower,代码行数:4,代码来源:template.py

示例8: loc

def loc(s):
    """A noop function for strings that are not ready to be localized."""
    return strip_whitespace(s)
开发者ID:aspes,项目名称:zamboni,代码行数:3,代码来源:helpers.py

示例9: render_token_list

 def render_token_list(self, tokens):
     """Strip whitespace from msgid before letting gettext touch it."""
     rendered = super(ShoehornedBlockTranslateNode, self).render_token_list(
         tokens)
     return strip_whitespace(rendered[0]), rendered[1]
开发者ID:dailycavalier,项目名称:webifyme,代码行数:5,代码来源:templatetag.py

示例10: _parse_block

 def _parse_block(self, parser, allow_pluralize):
     ref, buffer = super(I18nExtension, self)._parse_block(parser,
                                                           allow_pluralize)
     return ref, strip_whitespace(buffer)
开发者ID:DonnieThomas,项目名称:bedrock,代码行数:4,代码来源:template.py


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