コード例 #1
0
def make_safe_path_portion(ustr):
    ustr = really_unicode(ustr)
    s = ustr.encode('latin-1', 'ignore')
    s = AsciiDammit.asciiDammit(s)
    s = s.lower()
    s = '-'.join(re_path_portion_fragment.findall(s))
    s = s.replace('--', '-')
    return s
コード例 #2
0
def make_safe_path_portion(ustr):
    ustr = really_unicode(ustr)
    s = ustr.encode('latin-1', 'ignore')
    s = AsciiDammit.asciiDammit(s)
    s = s.lower()
    s = '-'.join(re_path_portion_fragment.findall(s))
    s = s.replace('--', '-')
    return s
コード例 #3
0
ファイル: helpers.py プロジェクト: dastanforever/allura
def make_safe_path_portion(ustr, relaxed=True):
    """Return an ascii representation of ``ustr`` that conforms to mount point
    naming :attr:`rules <re_tool_mount_point_fragment>`.

    Will return an empty string if no char in ``ustr`` is latin1-encodable.

    :param relaxed: Use relaxed mount point naming rules (allows more
        characters. See :attr:`re_relaxed_tool_mount_point_fragment`.
    :returns: The converted string.

    """
    regex = (re_relaxed_tool_mount_point_fragment if relaxed else
             re_tool_mount_point_fragment)
    ustr = really_unicode(ustr)
    s = ustr.encode('latin1', 'ignore')
    s = AsciiDammit.asciiDammit(s)
    if not relaxed:
        s = s.lower()
    s = '-'.join(regex.findall(s))
    s = s.replace('--', '-')
    return s
コード例 #4
0
ファイル: helpers.py プロジェクト: lym/allura-git
def make_safe_path_portion(ustr, relaxed=True):
    """Return an ascii representation of ``ustr`` that conforms to mount point
    naming :attr:`rules <re_tool_mount_point_fragment>`.

    Will return an empty string if no char in ``ustr`` is latin1-encodable.

    :param relaxed: Use relaxed mount point naming rules (allows more
        characters. See :attr:`re_relaxed_tool_mount_point_fragment`.
    :returns: The converted string.

    """
    regex = (re_relaxed_tool_mount_point_fragment
             if relaxed else re_tool_mount_point_fragment)
    ustr = really_unicode(ustr)
    s = ustr.encode('latin1', 'ignore')
    s = AsciiDammit.asciiDammit(s)
    if not relaxed:
        s = s.lower()
    s = '-'.join(regex.findall(s))
    s = s.replace('--', '-')
    return s