Skip to content

Commit

Permalink
Add python 3 support - closes python-mechanize#9
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolas committed Dec 18, 2018
1 parent 6dbb1c5 commit 3b1d404
Show file tree
Hide file tree
Showing 41 changed files with 332 additions and 178 deletions.
118 changes: 114 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,115 @@
/build/
/dist/
/docs/_*
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
*.py[co]
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ language: python
python:
# - 2.6 disabled as the TestLoader.discover() method is not available on python < 2.7
- 2.7
- 3.6
- pypy

matrix:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ You may control the browser's policy by using the methods of
# Sometimes it's useful to process bad headers or bad HTML:
response = br.response() # this is a copy of response
headers = response.info() # currently, this is a mimetools.Message
headers = response.info() # currently, this is a email.mime.message.MIMEMessage
headers["Content-type"] = "text/html; charset=utf-8"
response.set_data(response.get_data().replace("<!---", "<!--"))
br.set_response(response)
Expand Down
2 changes: 1 addition & 1 deletion mechanize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import absolute_import


import logging

Expand Down
2 changes: 1 addition & 1 deletion mechanize/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

from __future__ import absolute_import

from ._urllib2_fork import HTTPPasswordMgr
from .polyglot import is_string, iteritems

Expand Down
6 changes: 4 additions & 2 deletions mechanize/_clientcookie.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import re
import time
from .polyglot import (
Expand All @@ -17,6 +15,10 @@
]


def cmp(a, b):
return (a > b) - (a < b)


def effective_request_host(request):
"""Return the effective request-host, as defined by RFC 2965."""
return eff_request_host(request)[1]
Expand Down
2 changes: 1 addition & 1 deletion mechanize/_debug.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import absolute_import


import logging

Expand Down
58 changes: 29 additions & 29 deletions mechanize/_entities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: BSD Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>

Expand All @@ -16,7 +16,7 @@
'acute': '´',
'acy': 'а',
'aelig': 'æ',
'af': '\u2061',
'af': '\\u2061',
'afr': '𝔞',
'agrave': 'à',
'alefsym': 'ℵ',
Expand Down Expand Up @@ -55,7 +55,7 @@
'ape': '≊',
'apid': '≋',
'apos': "'",
'applyfunction': '\u2061',
'applyfunction': '\\u2061',
'approx': '≈',
'approxeq': '≊',
'aring': 'å',
Expand Down Expand Up @@ -390,11 +390,11 @@
'emptysmallsquare': '◻',
'emptyv': '∅',
'emptyverysmallsquare': '▫',
'emsp': '\u2003',
'emsp13': '\u2004',
'emsp14': '\u2005',
'emsp': '\\u2003',
'emsp13': '\\u2004',
'emsp14': '\\u2005',
'eng': 'ŋ',
'ensp': '\u2002',
'ensp': '\\u2002',
'eogon': 'ę',
'eopf': '𝕖',
'epar': '⋕',
Expand Down Expand Up @@ -534,7 +534,7 @@
'gvertneqq': '≩︀',
'gvne': '≩︀',
'hacek': 'ˇ',
'hairsp': '\u200a',
'hairsp': '\\u200a',
'half': '½',
'hamilt': 'ℋ',
'hardcy': 'ъ',
Expand Down Expand Up @@ -567,7 +567,7 @@
'hybull': '⁃',
'hyphen': '‐',
'iacute': 'í',
'ic': '\u2063',
'ic': '\\u2063',
'icirc': 'î',
'icy': 'и',
'idot': 'İ',
Expand Down Expand Up @@ -605,8 +605,8 @@
'intersection': '⋂',
'intlarhk': '⨗',
'intprod': '⨼',
'invisiblecomma': '\u2063',
'invisibletimes': '\u2062',
'invisiblecomma': '\\u2063',
'invisibletimes': '\\u2062',
'iocy': 'ё',
'iogon': 'į',
'iopf': '𝕚',
Expand All @@ -620,7 +620,7 @@
'isins': '⋴',
'isinsv': '⋳',
'isinv': '∈',
'it': '\u2062',
'it': '\\u2062',
'itilde': 'ĩ',
'iukcy': 'і',
'iuml': 'ï',
Expand Down Expand Up @@ -792,7 +792,7 @@
'lrcorner': '⌟',
'lrhar': '⇋',
'lrhard': '⥭',
'lrm': '\u200e',
'lrm': '\\u200e',
'lrtri': '⊿',
'lsaquo': '‹',
'lscr': '𝓁',
Expand Down Expand Up @@ -835,7 +835,7 @@
'mdash': '—',
'mddot': '∺',
'measuredangle': '∡',
'mediumspace': '\u205f',
'mediumspace': '\\u205f',
'mellintrf': 'ℳ',
'mfr': '𝔪',
'mho': '℧',
Expand Down Expand Up @@ -887,10 +887,10 @@
'nearr': '↗',
'nearrow': '↗',
'nedot': '≐̸',
'negativemediumspace': '\u200b',
'negativethickspace': '\u200b',
'negativethinspace': '\u200b',
'negativeverythinspace': '\u200b',
'negativemediumspace': '\\u200b',
'negativethickspace': '\\u200b',
'negativethinspace': '\\u200b',
'negativeverythinspace': '\\u200b',
'nequiv': '≢',
'nesear': '⤨',
'nesim': '≂̸',
Expand Down Expand Up @@ -934,7 +934,7 @@
'nltrie': '⋬',
'nltv': '≪̸',
'nmid': '∤',
'nobreak': '\u2060',
'nobreak': '\\u2060',
'nonbreakingspace': '\xa0',
'nopf': '𝕟',
'not': '¬',
Expand Down Expand Up @@ -1050,7 +1050,7 @@
'nu': 'ν',
'num': '#',
'numero': '№',
'numsp': '\u2007',
'numsp': '\\u2007',
'nvap': '≍⃒',
'nvdash': '⊬',
'nvge': '≥⃒',
Expand Down Expand Up @@ -1201,7 +1201,7 @@
'prurel': '⊰',
'pscr': '𝓅',
'psi': 'ψ',
'puncsp': '\u2008',
'puncsp': '\\u2008',
'qfr': '𝔮',
'qint': '⨌',
'qopf': '𝕢',
Expand Down Expand Up @@ -1307,7 +1307,7 @@
'risingdotseq': '≓',
'rlarr': '⇄',
'rlhar': '⇌',
'rlm': '\u200f',
'rlm': '\\u200f',
'rmoust': '⎱',
'rmoustache': '⎱',
'rnmid': '⫮',
Expand Down Expand Up @@ -1521,9 +1521,9 @@
'thetav': 'ϑ',
'thickapprox': '≈',
'thicksim': '∼',
'thickspace': '\u205f\u200a',
'thinsp': '\u2009',
'thinspace': '\u2009',
'thickspace': '\\u205f\\u200a',
'thinsp': '\\u2009',
'thinspace': '\\u2009',
'thkap': '≈',
'thksim': '∼',
'thorn': 'þ',
Expand Down Expand Up @@ -1659,7 +1659,7 @@
'verticalline': '|',
'verticalseparator': '❘',
'verticaltilde': '≀',
'verythinspace': '\u200a',
'verythinspace': '\\u200a',
'vfr': '𝔳',
'vltri': '⊲',
'vnsub': '⊂⃒',
Expand Down Expand Up @@ -1720,15 +1720,15 @@
'zcy': 'з',
'zdot': 'ż',
'zeetrf': 'ℨ',
'zerowidthspace': '\u200b',
'zerowidthspace': '\\u200b',
'zeta': 'ζ',
'zfr': '𝔷',
'zhcy': 'ж',
'zigrarr': '⇝',
'zopf': '𝕫',
'zscr': '𝓏',
'zwj': '\u200d',
'zwnj': '\u200c',
'zwj': '\\u200d',
'zwnj': '\\u200c',
# }}}
}

Expand Down
6 changes: 3 additions & 3 deletions mechanize/_equiv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: BSD Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>

Expand All @@ -11,7 +11,7 @@
from ._entities import html5_entities
from .polyglot import codepoint_to_chr

space_chars = frozenset(("\t", "\n", "\u000C", " ", "\r"))
space_chars = frozenset(("\t", "\n", "\\u000C", " ", "\r"))
space_chars_bytes = frozenset(item.encode("ascii") for item in space_chars)
ascii_letters_bytes = frozenset(
item.encode("ascii") for item in string.ascii_letters)
Expand Down Expand Up @@ -75,7 +75,7 @@ def __next__(self):
raise TypeError
return self[p:p + 1]

def next(self):
def __next__(self):
# Py2 compat
return self.__next__()

Expand Down
Loading

0 comments on commit 3b1d404

Please sign in to comment.