Esempio n. 1
0
def nodeprep(u):
    chars = list(six.text_type(u))
    i = 0
    while i < len(chars):
        c = chars[i]
        # map to nothing
        if stringprep.in_table_b1(c):
            del chars[i]
        else:
            # case fold
            chars[i] = stringprep.map_table_b2(c)
            i += 1
    # NFKC
    chars = stringprep.unicodedata.normalize("NFKC", "".join(chars))
    for c in chars:
        if (stringprep.in_table_c11(c) or stringprep.in_table_c12(c)
                or stringprep.in_table_c21(c) or stringprep.in_table_c22(c)
                or stringprep.in_table_c3(c) or stringprep.in_table_c4(c)
                or stringprep.in_table_c5(c) or stringprep.in_table_c6(c)
                or stringprep.in_table_c7(c) or stringprep.in_table_c8(c)
                or stringprep.in_table_c9(c) or c in "\"&'/:<>@"):
            raise UnicodeError("Invalid node character")

    bidi(chars)

    return chars
Esempio n. 2
0
def nodeprep(u):
    chars = list(unicode(u))
    i = 0
    while i < len(chars):
        c = chars[i]
        # map to nothing
        if stringprep.in_table_b1(c):
            del chars[i]
        else:
            # case fold
            chars[i] = stringprep.map_table_b2(c)
            i += 1
    # NFKC
    chars = stringprep.unicodedata.normalize("NFKC", "".join(chars))
    for c in chars:
        if (stringprep.in_table_c11(c) or
            stringprep.in_table_c12(c) or
            stringprep.in_table_c21(c) or
            stringprep.in_table_c22(c) or
            stringprep.in_table_c3(c) or
            stringprep.in_table_c4(c) or
            stringprep.in_table_c5(c) or
            stringprep.in_table_c6(c) or
            stringprep.in_table_c7(c) or
            stringprep.in_table_c8(c) or
            stringprep.in_table_c9(c) or
            c in "\"&'/:<>@"):
            raise UnicodeError("Invalid node character")

    bidi(chars)

    return chars
Esempio n. 3
0
def nameprep(label):
    forbidden = {'"', '&', "'", '/', ':', '<', '>', '@'}
    if label is None:
        return None
    try:
        label = encodings.idna.nameprep(label)
    except:
        return None
    for c in label:
        if stringprep.in_table_c11(c) or stringprep.in_table_c21(c) or c in forbidden:
            return None
    return label
Esempio n. 4
0
def nodeprep( foo, errors='strict' ):
    if foo is None:
        return None
    if isinstance( foo, str ):
        foo = foo.decode( 'utf-8' )
    ofoo = u''
    for x in foo:
        if not stringprep.in_table_b1( x ):
            ofoo += stringprep.map_table_b2( x )
    foo = unicodedata.normalize( 'NFKC', ofoo )
    ofoo = u''
    first_is_randal = False
    if len(foo):
        first_is_randal = stringprep.in_table_d1( foo[0] )
        if first_is_randal:
            if not stringprep.in_table_d1( foo[-1] ):
                raise UnicodeError, "Section 6.3 [end]"
    for x in range(len(foo)):
        if errors=='strict' and stringprep.in_table_a1( foo[x] ):
            raise UnicodeError, "Unassigned Codepoint"
        if stringprep.in_table_c11( foo[x] ):
            raise UnicodeError, "In table C.1.1"
        if stringprep.in_table_c12( foo[x] ):
            raise UnicodeError, "In table C.1.2"
        if stringprep.in_table_c21( foo[x] ):
            raise UnicodeError, "In table C.2.1"
        if stringprep.in_table_c22( foo[x] ):
            raise UnicodeError, "In table C.2.2"
        if stringprep.in_table_c3( foo[x] ):
            raise UnicodeError, "In table C.3"
        if stringprep.in_table_c4( foo[x] ):
            raise UnicodeError, "In table C.4"
        if stringprep.in_table_c5( foo[x] ):
            raise UnicodeError, "In table C.5"
        if stringprep.in_table_c6( foo[x] ):
            raise UnicodeError, "In table C.6"
        if stringprep.in_table_c7( foo[x] ):
            raise UnicodeError, "In table C.7"
        if stringprep.in_table_c8( foo[x] ):
            raise UnicodeError, "In table C.8"
        if stringprep.in_table_c9( foo[x] ):
            raise UnicodeError, "In table C.9"
        if foo[x] in "\"&'/;<>@":
            raise UnicodeError, "In nodeprep banned list"
        if x:
            if first_is_randal and stringprep.in_table_d2( foo[x] ):
                raise UnicodeError, "Section 6.2"
            if not first_is_randal and x!=(len(foo)-1) and stringprep.in_table_d1( foo[x] ):
                raise UnicodeError, "Section 6.3"
        else:
            first = False
    return foo
Esempio n. 5
0
 def update_event(self, inp=-1):
     self.set_output_val(0, stringprep.in_table_c11(self.input(0)))