• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python stringprep.in_table_d1函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中stringprep.in_table_d1函数的典型用法代码示例。如果您正苦于以下问题:Python in_table_d1函数的具体用法?Python in_table_d1怎么用?Python in_table_d1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了in_table_d1函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: check_bidi

def check_bidi(data):
    """
    1) The characters in section 5.8 MUST be prohibited.

    2) If a string contains any RandALCat character, the string MUST NOT
       contain any LCat character.

    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 data:
        return data

    has_lcat = False
    has_randal = False

    for c in data:
        if stringprep.in_table_c8(c):
            raise StringPrepError("BIDI violation: seciton 6 (1)")
        if stringprep.in_table_d1(c):
            has_randal = True
        elif stringprep.in_table_d2(c):
            has_lcat = True

    if has_randal and has_lcat:
        raise StringPrepError("BIDI violation: section 6 (2)")

    first_randal = stringprep.in_table_d1(data[0])
    last_randal = stringprep.in_table_d1(data[-1])
    if has_randal and not (first_randal and last_randal):
        raise StringPrepError("BIDI violation: section 6 (3)")
开发者ID:pnakos,项目名称:my_project,代码行数:32,代码来源:stringprep_profiles.py


示例2: nodeprep

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
开发者ID:dwd,项目名称:Polymer,代码行数:52,代码来源:nodeprep.py


示例3: _checkBidi

    def _checkBidi(self, data):
        hasL = False
        hasRorAL = False
        for char in data:
            if stringprep.in_table_d1(char):
                hasRorAL = True
            elif stringprep.in_table_d2(char):
                hasL = True

        if hasL and hasRorAL:
            raise XmppStringPrepError('String contains RandALCat characters and LCat characters')
        if hasRorAL and (not stringprep.in_table_d1(data[0]) or not stringprep.in_table_d1(data[-1])):
            raise XmppStringPrepError('RandALCat character MUST be the first character of the string, and a RandALCat character MUST be the last character of the string')
        return data
开发者ID:webiumsk,项目名称:WOT-0.9.12-CT,代码行数:14,代码来源:xmpp_string_grep.py


示例4: check_bidirectionals

	def check_bidirectionals(self, string):
		found_LCat = False
		found_RandALCat = False

		for c in string:
			if stringprep.in_table_d1(c):
				found_RandALCat = True
			if stringprep.in_table_d2(c):
				found_LCat = True

		if found_LCat and found_RandALCat:
			raise UnicodeError, "Violation of BIDI Requirement 2"

		if found_RandALCat and not (stringprep.in_table_d1(string[0]) and
									stringprep.in_table_d1(string[-1])):
			raise UnicodeError, "Violation of BIDI Requirement 3"
开发者ID:pacoqueen,项目名称:bbinn,代码行数:16,代码来源:xmpp_stringprep.py


示例5: _check_bidi

def _check_bidi(s):
    """Enforce bidirectional character check from RFC 3454 (stringprep)"""

    r_and_al_cat = False
    l_cat = False

    for c in s:
        if not r_and_al_cat and stringprep.in_table_d1(c):
            r_and_al_cat = True

        if not l_cat and stringprep.in_table_d2(c):
            l_cat = True

    if r_and_al_cat and l_cat:
        raise SASLPrepError('Both RandALCat and LCat characters present')

    if r_and_al_cat and not (stringprep.in_table_d1(s[0]) and
                             stringprep.in_table_d1(s[-1])):
        raise SASLPrepError('RandALCat character not at both start and end')
开发者ID:dcafferty,项目名称:asyncssh,代码行数:19,代码来源:saslprep.py


示例6: saslprep

def saslprep(s, allow_unassigned = False):
    '''
    Prepare Unicode string s according to SASLprep: Stringprep Profile for
    User Names and Passwords, a.k.a. RFC 4013

    If the optional parameter allow_unassigned is set to True,
    unassigned codepoints will be allowed. This is recommended for
    query terms and other non-storing situations only.

    The return value is a Unicode string appropriately prepared.

    Disallowed input leads to a ValueError.
    '''
    if type(s) != type(u''):
        raise TypeError("input must be a Unicode string")
    # phase 1: mapping
    s = u''.join([ stringprep.in_table_c12(ch) and u' ' or ch for ch in unichars(s) if not stringprep.in_table_b1(ch) ])
    # phase 2: normalization
    s = unicodedata.normalize('NFKC', s)
    # phase 3: prohibition
    for ch in unichars(s):
        if stringprep.in_table_c12(ch):
            raise ValueError("prohibited non-ASCII space character")
        if stringprep.in_table_c21(ch):
            raise ValueError("prohibited ASCII control character")
        if stringprep.in_table_c22(ch):
            raise ValueError("prohibited non-ASCII control character")
        if stringprep.in_table_c3(ch):
            raise ValueError("prohibited private use character")
        if stringprep.in_table_c4(ch):
            raise ValueError("prohibited non-character code point")
        if stringprep.in_table_c5(ch):
            raise ValueError("prohibited surrogate code point")
        if stringprep.in_table_c6(ch):
            raise ValueError("prohibited character inappropriate for plain text")
        if stringprep.in_table_c7(ch):
            raise ValueError("prohibited character inappropriate for canonical representation")
        if stringprep.in_table_c8(ch):
            raise ValueError("prohibited character changing display properties, or a deprecated character")
        if stringprep.in_table_c9(ch):
            raise ValueError("prohibited tagging character")
    # phase 4: bidi check
    bidi_map = ''.join([ stringprep.in_table_d1(ch) and 'r' or stringprep.in_table_d2(ch) and 'l' or 'x' for ch in unichars(s) ])
    if 'r' in bidi_map:
        if 'l' in bidi_map:
            raise ValueError("prohibited mixture of strong left-to-right and right-to-left text")
        if bidi_map[0] != 'r' or bidi_map[-1] != 'r':
            raise ValueError("string containing right-to-left text must start and end with right-to-left text")
    # phase 5: unassigned check
    if not allow_unassigned:
        for ch in unichars(s):
            if stringprep.in_table_a1(ch):
                raise ValueError("prohibited unassigned code point")
    return s
开发者ID:galaxy001,项目名称:libtorrent,代码行数:54,代码来源:saslprep.py


示例7: _process

 def _process(self, value):
     for code in force_text(value):
         # TODO: Is this long enough?
         if stringprep.in_table_c12(code) or stringprep.in_table_c21_c22(code) or \
             stringprep.in_table_c3(code) or stringprep.in_table_c4(code) or \
             stringprep.in_table_c5(code) or stringprep.in_table_c6(code) or \
             stringprep.in_table_c7(code) or stringprep.in_table_c8(code) or \
                 stringprep.in_table_c9(code):
             self.invalid = False
         if stringprep.in_table_d1(code):
             self.r_and_al_cat = True
         if stringprep.in_table_d2(code):
             self.l_cat = True
开发者ID:davidoc,项目名称:django-password-policies,代码行数:13,代码来源:validators.py


示例8: nameprep

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
开发者ID:RockySteveJobs,项目名称:python-for-android,代码行数:49,代码来源:idna.py


示例9: check_bidirectional

    def check_bidirectional(unistr):
        contains_randalcat = False
        contains_lcat = False

        for c in unistr:
            if stringprep.in_table_c8(c):
                raise IdentifierError(IdentifierErrors.restriction_bidirectional_prohibited)
            if stringprep.in_table_d1(c):
                contains_randalcat = True
            if stringprep.in_table_d2(c):
                contains_lcat = True

        if contains_randalcat:
            if contains_lcat:
                raise IdentifierError(IdentifierErrors.restriction_bidirectional_mixed)
            if not all(map(stringprep.in_table_d1,[unistr[0],unistr[-1]])):
                raise IdentifierError(IdentifierErrors.restriction_bidirectional_affix)
开发者ID:orbisvicis,项目名称:Slugathon,代码行数:17,代码来源:stringutils.py


示例10: nameprep

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
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:19,代码来源:idna.py


示例11: __call__

 def __call__(self, value):
     super(BidirectionalValidator, self).__call__(value)
     if self.r_and_al_cat:
         if self.l_cat or not stringprep.in_table_d1(self.first) or \
         not stringprep.in_table_d1(self.last):
             raise ValidationError(self.message, code=self.code)
开发者ID:PolicyStat,项目名称:django-password-policies,代码行数:6,代码来源:validators.py


示例12: sasl_prep

def sasl_prep(data):
    """
    implement SASLPrep profile as per RFC4013:
    it defines the "SASLprep" profile of the "stringprep" algorithm [StringPrep].
    The profile is designed for use in Simple Authentication and Security
    Layer ([SASL]) mechanisms, such as [PLAIN], [CRAM-MD5], and
    [DIGEST-MD5].  It may be applicable where simple user names and
    passwords are used.  This profile is not intended for use in
    preparing identity strings that are not simple user names (e.g.,
    email addresses, domain names, distinguished names), or where
    identity or password strings that are not character data, or require
    different handling (e.g., case folding).
    """

    # mapping
    prepared_data = ''
    for c in data:
        if stringprep.in_table_c12(c):
            # non-ASCII space characters [StringPrep, C.1.2] that can be mapped to SPACE (U+0020)
            prepared_data += ' '
        elif stringprep.in_table_b1(c):
            # the "commonly mapped to nothing" characters [StringPrep, B.1] that can be mapped to nothing.
            pass
        else:
            prepared_data += c

    # normalizing
    # This profile specifies using Unicode normalization form KC
    # The repertoire is Unicode 3.2 as per RFC 4013 (2)

    prepared_data = unicode32.normalize('NFKC', prepared_data)

    if not prepared_data:
        raise LDAPSASLPrepError('SASLprep error: unable to normalize string')

    # prohibit
    for c in prepared_data:
        if stringprep.in_table_c12(c):
            # Non-ASCII space characters [StringPrep, C.1.2]
            raise LDAPSASLPrepError('SASLprep error: non-ASCII space character present')
        elif stringprep.in_table_c21(c):
            # ASCII control characters [StringPrep, C.2.1]
            raise LDAPSASLPrepError('SASLprep error: ASCII control character present')
        elif stringprep.in_table_c22(c):
            # Non-ASCII control characters [StringPrep, C.2.2]
            raise LDAPSASLPrepError('SASLprep error: non-ASCII control character present')
        elif stringprep.in_table_c3(c):
            # Private Use characters [StringPrep, C.3]
            raise LDAPSASLPrepError('SASLprep error: private character present')
        elif stringprep.in_table_c4(c):
            # Non-character code points [StringPrep, C.4]
            raise LDAPSASLPrepError('SASLprep error: non-character code point present')
        elif stringprep.in_table_c5(c):
            # Surrogate code points [StringPrep, C.5]
            raise LDAPSASLPrepError('SASLprep error: surrogate code point present')
        elif stringprep.in_table_c6(c):
            # Inappropriate for plain text characters [StringPrep, C.6]
            raise LDAPSASLPrepError('SASLprep error: inappropriate for plain text character present')
        elif stringprep.in_table_c7(c):
            # Inappropriate for canonical representation characters [StringPrep, C.7]
            raise LDAPSASLPrepError('SASLprep error: inappropriate for canonical representation character present')
        elif stringprep.in_table_c8(c):
            # Change display properties or deprecated characters [StringPrep, C.8]
            raise LDAPSASLPrepError('SASLprep error: change display property or deprecated character present')
        elif stringprep.in_table_c9(c):
            # Tagging characters [StringPrep, C.9]
            raise LDAPSASLPrepError('SASLprep error: tagging character present')

    # check bidi
    # if a string contains any r_and_al_cat character, the string MUST NOT contain any l_cat character.
    flag_r_and_al_cat = False
    flag_l_cat = False
    for c in prepared_data:
        if stringprep.in_table_d1(c):
            flag_r_and_al_cat = True
        elif stringprep.in_table_d2(c):
            flag_l_cat = True

        if flag_r_and_al_cat and flag_l_cat:
            raise LDAPSASLPrepError('SASLprep error: string cannot contain (R or AL) and L bidirectional chars')

    # If a string contains any r_and_al_cat character, a r_and_al_cat character MUST be the first character of the string
    # and a r_and_al_cat character MUST be the last character of the string.
    if flag_r_and_al_cat and not stringprep.in_table_d1(prepared_data[0]) and not stringprep.in_table_d2(prepared_data[-1]):
        raise LDAPSASLPrepError('r_and_al_cat character present, must be first and last character of the string')

    return prepared_data
开发者ID:cwaldbieser,项目名称:python3-ldap,代码行数:87,代码来源:sasl.py


示例13: saslprep

def saslprep(text, strict=True):
    """
    Return a processed version of the given string, using the SASLPrep
    profile of stringprep.

    :param text: The string to process, in UTF-8.
    :param strict: If ``True``, prevent the use of unassigned code points.
    """

    if sys.version_info < (3, 0):
        if type(text) == str:
            text = text.decode("utf-8")

    # Mapping:
    #
    #  -  non-ASCII space characters [StringPrep, C.1.2] that can be
    #     mapped to SPACE (U+0020), and
    #
    #  -  the 'commonly mapped to nothing' characters [StringPrep, B.1]
    #     that can be mapped to nothing.
    buffer = ""
    for char in text:
        if stringprep.in_table_c12(char):
            buffer += " "
        elif not stringprep.in_table_b1(char):
            buffer += char

    # Normalization using form KC
    text = unicodedata.normalize("NFKC", buffer)

    # Check for bidirectional string
    buffer = ""
    first_is_randal = False
    if text:
        first_is_randal = stringprep.in_table_d1(text[0])
        if first_is_randal and not stringprep.in_table_d1(text[-1]):
            raise SASLPrepFailure("Section 6.3 [end]")

    # Check for prohibited characters
    for x in range(len(text)):
        if strict and stringprep.in_table_a1(text[x]):
            raise SASLPrepFailure("Unassigned Codepoint")
        if stringprep.in_table_c12(text[x]):
            raise SASLPrepFailure("In table C.1.2")
        if stringprep.in_table_c21(text[x]):
            raise SASLPrepFailure("In table C.2.1")
        if stringprep.in_table_c22(text[x]):
            raise SASLPrepFailure("In table C.2.2")
        if stringprep.in_table_c3(text[x]):
            raise SASLPrepFailure("In table C.3")
        if stringprep.in_table_c4(text[x]):
            raise SASLPrepFailure("In table C.4")
        if stringprep.in_table_c5(text[x]):
            raise SASLPrepFailure("In table C.5")
        if stringprep.in_table_c6(text[x]):
            raise SASLPrepFailure("In table C.6")
        if stringprep.in_table_c7(text[x]):
            raise SASLPrepFailure("In table C.7")
        if stringprep.in_table_c8(text[x]):
            raise SASLPrepFailure("In table C.8")
        if stringprep.in_table_c9(text[x]):
            raise SASLPrepFailure("In table C.9")
        if x:
            if first_is_randal and stringprep.in_table_d2(text[x]):
                raise SASLPrepFailure("Section 6.2")
            if not first_is_randal and x != len(text) - 1 and stringprep.in_table_d1(text[x]):
                raise SASLPrepFailure("Section 6.3")

    return text
开发者ID:hoangduit,项目名称:emesene,代码行数:69,代码来源:saslprep.py



注:本文中的stringprep.in_table_d1函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python stringprep.in_table_d2函数代码示例发布时间:2022-05-27
下一篇:
Python stringprep.in_table_c12函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap