python3.3 django错误处理“sre_constants.error: nothing to repeat”

python3.3后对于多行正则表达式匹配好像做了点修改,不能匹配非转义字符的多行 正则表达式了。

报错如下:

>>> 
Traceback (most recent call last):
  File "<string>", line 420, in run_nodebug
  File "<模块1>", line 48, in <module>
  File "<模块1>", line 31, in main
  File "C:\Python33\lib\re.py", line 214, in compile
    return _compile(pattern, flags)
  File "C:\Python33\lib\re.py", line 281, in _compile
    p = sre_compile.compile(pattern, flags)
  File "C:\Python33\lib\sre_compile.py", line 498, in compile
    code = _code(p, flags)
  File "C:\Python33\lib\sre_compile.py", line 483, in _code
    _compile(code, p.data, flags)
  File "C:\Python33\lib\sre_compile.py", line 75, in _compile
    elif _simple(av) and op is not REPEAT:
  File "C:\Python33\lib\sre_compile.py", line 362, in _simple
    raise error("nothing to repeat")
sre_constants.error: nothing to repeat
>>> 


根据提示我们需要自己修改下“C:\Python33\Lib\html\parser.py”文件的第56行中locatestarttagend_tolerant的赋值

修改方法就是将原来的多行使用转义字符,变换成1行

python3.3 django错误处理“sre_constants.error: nothing to repeat”

##locatestarttagend_tolerant = re.compile(r"""
##  <[a-zA-Z][-.a-zA-Z0-9:_]*          # tag name
##  (?:[\s/]*                          # optional whitespace before attribute name
##    (?:(?<=[‘"\s/])[^\s/>][^\s/=>]*  # attribute name
##      (?:\s*=+\s*                    # value indicator
##        (?:‘[^‘]*‘                   # LITA-enclosed value
##          |"[^"]*"                   # LIT-enclosed value
##          |(?![‘"])[^>\s]*           # bare value
##         )
##         (?:\s*,)*                   # possibly followed by a comma
##       )?(?:\s|/(?!>))*
##     )*
##   )?
##  \s*                                # trailing whitespace
##""", re.VERBOSE)
locatestarttagend_tolerant = re.compile(r"""\n  <[a-zA-Z][-.a-zA-Z0-9:_]*          # tag name\n  (?:[\s/]*                          # optional whitespace before attribute name\n    (?:(?<=[‘"\s/])[^\s/>][^\s/=>]*  # attribute name\n      (?:\s*=+\s*                    # value indicator\n        (?:‘[^‘]*‘                   # LITA-enclosed value\n          |"[^"]*"                   # LIT-enclosed value\n          |(?![‘"])[^>\s]*           # bare value\n         )\n         (?:\s*,)*                   # possibly followed by a comma\n       )?(?:\s|/(?!>))*\n     )*\n   )?\n  \s*                                # trailing whitespace\n""", re.VERBOSE)

对于错误理解的有点问题,应该还是正则表达式写的有问题,天晚了,改天在搞



python3.3 django错误处理“sre_constants.error: nothing to repeat”,布布扣,bubuko.com

python3.3 django错误处理“sre_constants.error: nothing to repeat”

上一篇:小程序上传文件到微信服务器,及开发者服务器获取上传文件


下一篇:二项堆(一)之 图文解析 和 C语言的实现