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行


##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)

-------------------------2014-4-14 01:43:14-------------------------------------

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

-----------------------2014-4-15 07:43:37---------------------------------------

问题已经解决,是正则表达式的问题,以前用的版本是python3.3.2,更新为python3.3.4后问题就解决了。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值