forked from tkrajina/gpxpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port to Python 3, whilst retaining compatibility with Python 2, from …
…a single codebase. Also fixed a defect in gpx.reduce_points() revealed by Python 3 being stricter which object comparisons.
- Loading branch information
1 parent
8916e42
commit 166afba
Showing
8 changed files
with
194 additions
and
136 deletions.
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
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,51 @@ | ||
"""Utilities for assisting with portability between Python 2 and Python 3. | ||
""" | ||
|
||
try: | ||
# Python 2 | ||
#noinspection PyCompatibility | ||
base = basestring | ||
def is_string(s): | ||
return isinstance(s, base) | ||
except NameError: | ||
# Python 3 | ||
def is_string(s): | ||
return isinstance(s, str) | ||
|
||
try: | ||
# Python 2 | ||
#noinspection PyCompatibility | ||
unicode() | ||
|
||
def has_unicode_type(): | ||
return True | ||
|
||
except NameError: | ||
# Python 3 | ||
def has_unicode_type(): | ||
return False | ||
|
||
|
||
try: | ||
# Python 2 | ||
trial_dict = dict() | ||
trial_dict.has_key('foo') | ||
def has_key(d, key): | ||
return d.has_key(key) | ||
except AttributeError: | ||
# Python 3 | ||
def has_key(d, key): | ||
return key in d | ||
finally: | ||
del trial_dict | ||
|
||
|
||
try: | ||
# Python 2.x and Python 3.2+ | ||
is_callable = callable | ||
except NameError: | ||
# Python 3.0 and Python 3.1 | ||
from collections import Callable | ||
|
||
def is_callable(x): | ||
return isinstance(x, Callable) |
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.