Ticket #6160: twisted-python-test-test_utilpy3.2.patch

File twisted-python-test-test_utilpy3.2.patch, 4.2 KB (added by Petit_Dejeuner, 22 months ago)

Newer update version, handles indentifiers with numbers and underscores properly.

  • twisted/python/_utilpy3.py

    Only in Twisted-New: build
    Only in Twisted-New/twisted: __init__.pyc
    Only in Twisted-New/twisted: _version.pyc
    Only in Twisted-New/twisted: copyright.pyc
    Only in Twisted-New/twisted/python: __init__.pyc
    diff -ur Twisted/twisted/python/_utilpy3.py Twisted-New/twisted/python/_utilpy3.py
    old new  
    88 
    99from __future__ import division, absolute_import 
    1010 
    11 import sys, errno, warnings 
     11import sys, errno, warnings, string 
    1212 
    1313class FancyEqMixin: 
    1414    """ 
     
    170170    @type mname: C{str} 
    171171    @param mname: The name to convert to a label.  This must be a string 
    172172    which could be used as a Python identifier.  Strings which do not take 
    173     this form will result in unpredictable behavior. 
     173    this form will raise an AssertionError. 
    174174 
    175175    @rtype: C{str} 
    176176    """ 
     177    #check that mname is a valid indentifier 
     178    assert (mname[0] in string.letters) or (mname[0] == '_') #check that the first character is valid 
     179    assert all(map(lambda char : (char in string.letters) or (char in string.digits) or (char == '_'), mname)) #check that each character after the first is valid 
     180     
    177181    labelList = [] 
    178182    word = '' 
    179183    lastWasUpper = False 
    180184    for letter in mname: 
    181         if letter.isupper() == lastWasUpper: 
    182             # Continuing a word. 
     185        currentIsUpper = letter.isupper() or (lastWasUpper and (letter in (string.digits + string.punctuation))) #If an all caps is broken up by digits or punctuation it will remain one word 
     186        if letter == "_": 
     187            labelList.append(word) 
     188            word = '' 
     189        elif currentIsUpper == lastWasUpper: 
     190            # Continuing a word. Runs if word is a series of lowercase or capital letters. 
    183191            word += letter 
    184192        else: 
    185193            # breaking a word OR beginning a word 
     
    189197                    # keep going 
    190198                    word += letter 
    191199                else: 
    192                     # acronym 
    193                     # we're processing the lowercase letter after the acronym-then-capital 
    194                     lastWord = word[:-1] 
    195                     firstLetter = word[-1] 
    196                     labelList.append(lastWord) 
    197                     word = firstLetter + letter 
     200                    #acronym 
     201                    labelList.append(word) 
     202                    word = letter.upper() 
    198203            else: 
    199204                # definitely breaking: lower to upper 
    200205                labelList.append(word) 
    201206                word = letter 
    202         lastWasUpper = letter.isupper() 
     207        lastWasUpper = currentIsUpper 
    203208    if labelList: 
    204209        labelList[0] = labelList[0].capitalize() 
    205210    else: 
    206211        return mname.capitalize() 
    207212    labelList.append(word) 
    208     return ' '.join(labelList) 
     213 
     214    # removes excess spaces 
     215    labelList = map(lambda a_string : a_string.strip(), labelList) 
     216    labelList = filter(lambda char :char not in string.whitespace, labelList) 
     217    final_name = ' '.join(labelList).strip() 
     218     
     219    return final_name 
  • twisted/python/test/test_utilpy3.py

    Only in Twisted-New/twisted/python: compat.pyc
    Only in Twisted-New/twisted/python: dist.pyc
    Only in Twisted-New/twisted/python: hashlib.pyc
    Only in Twisted-New/twisted/python/test: test_util.pyc
    diff -ur Twisted/twisted/python/test/test_utilpy3.py Twisted-New/twisted/python/test/test_utilpy3.py
    old new  
    398398            ('foo', 'Foo'), 
    399399            ('fooBar', 'Foo Bar'), 
    400400            ('fooBarBaz', 'Foo Bar Baz'), 
     401            ('FOObar', 'FOO Bar'), 
     402            ('fooBAR', 'Foo BAR'), 
     403            ('F22BAR', 'F22BAR'), 
     404            ('F22jam', 'F22 Jam'), 
     405            ('FOO_BAR', 'FOO BAR'), 
     406            ('spam_AND_eggs', 'Spam AND Eggs'), 
     407            ('rmswaveRMSWAVErmswaveRMSWAVE', 'Rmswave RMSWAVE Rmswave RMSWAVE'), 
     408            ('MyMilkshakesBR1NG_AL2_th3', 'My Milkshakes BR1NG AL2 Th3'), 
    401409            ] 
    402410        for inp, out in nameData: 
    403411            got = util.nameToLabel(inp)