本文整理汇总了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
示例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)))
示例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)),
)
示例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'))
示例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)))
示例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.'
示例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)
示例8: loc
def loc(s):
"""A noop function for strings that are not ready to be localized."""
return strip_whitespace(s)
示例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]
示例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)