This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 193
Implement Python 2.7 support #33
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
513e57e
Implement Python 2.7 support
alekstorm 0d3a4f5
Move most Python 2/3 compatibility logic into new compat.py
alekstorm bca22f4
Fix SSL verify_mode monkey-patching on Python 2.7
alekstorm 6c82103
Fixup coverage test config for new `compat` module
alekstorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[run] | ||
omit=hyper/httplib_compat.py | ||
omit = | ||
hyper/compat.py | ||
hyper/httplib_compat.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
- "3.3" | ||
|
||
install: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
hyper/compat | ||
~~~~~~~~~ | ||
|
||
Normalizes the Python 2/3 API for internal use. | ||
""" | ||
import sys | ||
import zlib | ||
|
||
# Syntax sugar. | ||
_ver = sys.version_info | ||
|
||
#: Python 2.x? | ||
is_py2 = (_ver[0] == 2) | ||
|
||
#: Python 3.x? | ||
is_py3 = (_ver[0] == 3) | ||
|
||
if is_py2: | ||
from urlparse import urlparse | ||
|
||
def to_byte(char): | ||
return ord(char) | ||
|
||
def decode_hex(b): | ||
return b.decode('hex') | ||
|
||
# The standard zlib.compressobj() accepts only positional arguments. | ||
def zlib_compressobj(level=6, method=zlib.DEFLATED, wbits=15, memlevel=8, | ||
strategy=zlib.Z_DEFAULT_STRATEGY): | ||
return zlib.compressobj(level, method, wbits, memlevel, strategy) | ||
|
||
elif is_py3: | ||
from urllib.parse import urlparse | ||
|
||
def to_byte(char): | ||
return char | ||
|
||
def decode_hex(b): | ||
return bytes.fromhex(b) | ||
|
||
zlib_compressobj = zlib.compressobj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just plain better than what I was doing before, I was clearly exhausted when I wrote that line of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, understood.