Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to get regex to work on python > 3.6 #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicochidt
Copy link

@nicochidt nicochidt commented Sep 18, 2019

If we try to load python-whois on python3.7 it fails with the following traceback:

/bin/pwhois netflix               [12:53:30]
Traceback (most recent call last):
  File "/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\s'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/bin/pwhois", line 3, in <module>
    import argparse, pythonwhois, json, datetime, sys
  File "/lib/python3.7/site-packages/pythonwhois/__init__.py", line 1, in <module>
    from . import net, parse
  File "/lib/python3.7/site-packages/pythonwhois/parse.py", line 363, in <module>
    registrant_regexes = [preprocess_regex(regex) for regex in registrant_regexes]
  File "/lib/python3.7/site-packages/pythonwhois/parse.py", line 363, in <listcomp>
    registrant_regexes = [preprocess_regex(regex) for regex in registrant_regexes]
  File "/lib/python3.7/site-packages/pythonwhois/parse.py", line 205, in preprocess_regex
    regex = re.sub(r"\\s\*\(\?P<([^>]+)>\.\+\)", r"\s*(?P<\1>\S.*)", regex)
  File "/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \s at position 0

It is solved by adding the proper scape sequence in the regex expresion.

@mewforest
Copy link

mewforest commented Jun 21, 2022

It have to be merged, because it fixes library on latest Python, i.e. it works now in Python 3.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants