-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
3,538 additions
and
1,938 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 was deleted.
Oops, something went wrong.
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,45 @@ | ||
import codecs | ||
|
||
WHICH_PYTHON = None | ||
|
||
try: | ||
basestring | ||
WHICH_PYTHON = 2 | ||
except NameError: | ||
WHICH_PYTHON = 3 | ||
|
||
if WHICH_PYTHON == 2: | ||
basestring = basestring | ||
else: | ||
basestring = str | ||
|
||
|
||
def to_unicode(s): | ||
if WHICH_PYTHON == 2: | ||
return unicode(s) | ||
else: | ||
return str(s) | ||
|
||
|
||
def to_string(s): | ||
if WHICH_PYTHON == 2: | ||
if isinstance(s, unicode): | ||
return s | ||
elif isinstance(s, basestring): | ||
return to_unicode(s) | ||
else: | ||
return to_unicode(str(s)) | ||
else: | ||
if isinstance(s, basestring): | ||
return s | ||
else: | ||
return str(s) | ||
|
||
|
||
def write_file(path, s): | ||
if WHICH_PYTHON == 2: | ||
with codecs.open(path, 'w', encoding='utf-8') as f: | ||
return f.write(to_string(s)) | ||
else: | ||
with open(path, 'w') as f: | ||
return f.write(to_string(s)) |
Oops, something went wrong.