Пример #1
0
def unquote_value(value):
    """Unquote a configuration value."""
    if not value:
        return ''
    if value[0] in '"\'' and value[0] == value[-1]:
        value = value[1:-1].decode('string-escape')
    return soft_unicode(value)
def escape_rtf(val):
  if val == colander.null or val == None:
    val = u''
  val = soft_unicode(val)
  r = ''
  prevc = None
  for c in val:
    if (c == '\n' and prevc != '\r') or (c == '\r' and prevc != '\n'):
      r += '\line '
    elif (c == '\n' and prevc == '\r') or (c == '\r' and prevc == '\n'):
      pass
    elif c in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ':
      r += c
    else:
      r += '\u{}?'.format(ord(c))
    prevc = c
  return r
Пример #3
0
def do_format(value, *args, **kwargs):
    """Apply the given values to a `printf-style`_ format string, like
    ``string % values``.

    .. sourcecode:: jinja

        {{ "%s, %s!"|format(greeting, name) }}
        Hello, World!

    In most cases it should be more convenient and efficient to use the
    ``%`` operator or :meth:`str.format`.

    .. code-block:: text

        {{ "%s, %s!" % (greeting, name) }}
        {{ "{}, {}!".format(greeting, name) }}

    .. _printf-style: https://docs.python.org/library/stdtypes.html
        #printf-style-string-formatting
    """
    if args and kwargs:
        raise FilterArgumentError(
            "can't handle positional and keyword arguments at the same time")
    return soft_unicode(value) % (kwargs or args)
Пример #4
0
def do_trim(value, chars=None):
    """Strip leading and trailing characters, by default whitespace."""
    return soft_unicode(value).strip(chars)
Пример #5
0
def do_wordcount(s):
    """Count the words in that string."""
    return len(_word_re.findall(soft_unicode(s)))
Пример #6
0
def do_capitalize(s):
    """Capitalize a value. The first character will be uppercase, all others
    lowercase.
    """
    return soft_unicode(s).capitalize()
Пример #7
0
def do_lower(s):
    """Convert a value to lowercase."""
    return soft_unicode(s).lower()
Пример #8
0
def do_upper(s):
    """Convert a value to uppercase."""
    return soft_unicode(s).upper()
 def p(s):
   if s is colander.null or s is None:
     return u''
   return soft_unicode(s)
 def sk(x):
   return collator.sort_key(soft_unicode(x))
Пример #11
0
def nl2br(val):
    result = soft_unicode(Markup.escape(val)).replace("\n", Markup("<br />\n"))
    return Markup(result)
Пример #12
0
 def converter(self, value=None):
     """Convert values to stripped unicode values"""
     return soft_unicode(value).strip()
Пример #13
0
def do_trim(value):
    """Strip leading and trailing whitespace."""
    return soft_unicode(value).strip()
Пример #14
0
 def converter(self, value=None):
     """Convert values to stripped unicode values"""
     return soft_unicode(value).strip()