def nameprep(label): newlabel = [] for c in label: if stringprep.in_table_b1(c): continue newlabel.append(stringprep.map_table_b2(c)) label = u''.join(newlabel) label = unicodedata.normalize('NFKC', label) for c in label: if stringprep.in_table_c12(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): raise UnicodeError('Invalid character %r' % c) RandAL = map(stringprep.in_table_d1, label) for c in RandAL: if c: if filter(stringprep.in_table_d2, label): raise UnicodeError('Violation of BIDI requirement 2') if not RandAL[0] or not RandAL[-1]: raise UnicodeError('Violation of BIDI requirement 3') return label
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
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
def _nodeprep_do_mapping(chars): i = 0 while i < len(chars): c = chars[i] if stringprep.in_table_b1(c): del chars[i] else: replacement = stringprep.map_table_b2(c) if replacement != c: chars[i:(i + 1)] = list(replacement) i += len(replacement)
def __apply_saslgrep_profile(char: str): # Unicode normalization form KC char = stringprep.map_table_b2(char) if SASLprep.__is_non_ascii_space_character(char): return ' ' elif SASLprep.__is_commonly_mapped_to_nothing_character(char): return '' elif SASLprep.__is_prohibited_in_saslgrep(char): raise Exception('Prohibited character was found') elif SASLprep.__is_unassigned_code_point(char): raise Exception('Unassigned Code Points') return char
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
def nameprep(label): # Map newlabel = [] for c in label: if stringprep.in_table_b1(c): # Map to nothing continue newlabel.append(stringprep.map_table_b2(c)) label = "".join(newlabel) # Normalize label = unicodedata.normalize("NFKC", label) # Prohibit for c in label: if ( stringprep.in_table_c12(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) ): raise UnicodeError("Invalid character %r" % c) # Check bidi RandAL = [stringprep.in_table_d1(x) for x in label] for c in RandAL: if c: # There is a RandAL char in the string. Must perform further # tests: # 1) The characters in section 5.8 MUST be prohibited. # This is table C.8, which was already checked # 2) If a string contains any RandALCat character, the string # MUST NOT contain any LCat character. if any(stringprep.in_table_d2(x) for x in label): raise UnicodeError("Violation of BIDI requirement 2") # 3) If a string contains any RandALCat character, a # RandALCat character MUST be the first character of the # string, and a RandALCat character MUST be the last # character of the string. if not RandAL[0] or not RandAL[-1]: raise UnicodeError("Violation of BIDI requirement 3") return label
def nameprep(label): # Map newlabel = [] for c in label: if stringprep.in_table_b1(c): # Map to nothing continue newlabel.append(stringprep.map_table_b2(c)) label = "".join(newlabel) # Normalize label = unicodedata.normalize("NFKC", label) # Prohibit for c in label: if stringprep.in_table_c12(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): raise UnicodeError("Invalid character %r" % c) # Check bidi RandAL = [stringprep.in_table_d1(x) for x in label] for c in RandAL: if c: # There is a RandAL char in the string. Must perform further # tests: # 1) The characters in section 5.8 MUST be prohibited. # This is table C.8, which was already checked # 2) If a string contains any RandALCat character, the string # MUST NOT contain any LCat character. if any(stringprep.in_table_d2(x) for x in label): raise UnicodeError("Violation of BIDI requirement 2") # 3) If a string contains any RandALCat character, a # RandALCat character MUST be the first character of the # string, and a RandALCat character MUST be the last # character of the string. if not RandAL[0] or not RandAL[-1]: raise UnicodeError("Violation of BIDI requirement 3") return label
def canonicaliseUsername(username, ignoreSpaces = False, throws = True): # Read stringprep documentation for the meaning of the tables chars = list(username) for c, char in enumerate(chars): if stringprep.in_table_a1(char): if throws: raise ValueError else: chars[c] = u"" elif stringprep.in_table_b1(char): chars[c] = u"" else: chars[c] = stringprep.map_table_b2(char) chars = list(stringprep.unicodedata.normalize("NFKC", u"".join(chars))) for c, char in enumerate(chars): if ((not ignoreSpaces and stringprep.in_table_c11_c12(char)) or stringprep.in_table_c21_c22(char) or stringprep.in_table_c3(char) or stringprep.in_table_c4(char) or stringprep.in_table_c5(char) or stringprep.in_table_c6(char) or stringprep.in_table_c7(char) or stringprep.in_table_c8(char) or stringprep.in_table_c9(char) or stringprep.unicodedata.category(char) in ("Ps", "Pe", "Pi", "Pf", "Po")): if throws: raise ValueError else: chars[c] = u"" chars = u"".join(chars) if throws: RandAL = map(stringprep.in_table_d1, chars) for c in RandAL: if c: if filter(stringprep.in_table_d2, chars): raise ValueError if not RandAL[0] or not RandAL[-1]: raise ValueError return chars
def nameprep(label): newlabel = [] for c in label: if stringprep.in_table_b1(c): pass newlabel.append(stringprep.map_table_b2(c)) label = ''.join(newlabel) label = unicodedata.normalize('NFKC', label) for c in label: while stringprep.in_table_c12(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): raise UnicodeError('Invalid character %r' % c) RandAL = [stringprep.in_table_d1(x) for x in label] for c in RandAL: while c: if any(stringprep.in_table_d2(x) for x in label): raise UnicodeError('Violation of BIDI requirement 2') if not RandAL[0] or not RandAL[-1]: raise UnicodeError('Violation of BIDI requirement 3') return label
def nameprep(label): newlabel = [] for c in label: if stringprep.in_table_b1(c): continue newlabel.append(stringprep.map_table_b2(c)) label = u''.join(newlabel) label = unicodedata.normalize('NFKC', label) for c in label: if stringprep.in_table_c12(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): raise UnicodeError('Invalid character %r' % c) RandAL = map(stringprep.in_table_d1, label) for c in RandAL: if c: if filter(stringprep.in_table_d2, label): raise UnicodeError('Violation of BIDI requirement 2') if not RandAL[0] or not RandAL[-1]: raise UnicodeError('Violation of BIDI requirement 3') return label
def update_event(self, inp=-1): self.set_output_val(0, stringprep.map_table_b2(self.input(0)))