-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Switch LGPL'd chardet for MIT licensed charset_normalizer
- Loading branch information
Showing
4 changed files
with
39 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import sys | ||
|
||
try: | ||
import chardet | ||
except ImportError: | ||
import charset_normalizer as chardet | ||
|
||
# This code exists for backwards compatibility reasons. | ||
# I don't like it either. Just look the other way. :) | ||
|
||
for package, alias in (('urllib3', 'urllib3'), ('idna', 'idna'), ('charset_normalizer', 'chardet')): | ||
for package in ('urllib3', 'idna'): | ||
locals()[package] = __import__(package) | ||
locals()[alias] = locals()[package] | ||
# This traversal is apparently necessary such that the identities are | ||
# preserved (requests.packages.urllib3.* is urllib3.*) | ||
for mod in list(sys.modules): | ||
if mod == package or mod.startswith(package + '.'): | ||
sys.modules['requests.packages.' + mod.replace(package, alias)] = sys.modules[mod] | ||
sys.modules['requests.packages.' + mod] = sys.modules[mod] | ||
|
||
target = chardet.__name__ | ||
for mod in list(sys.modules): | ||
if mod == target or mod.startswith(target + '.'): | ||
sys.modules['requests.packages.' + target.replace(target, 'chardet')] = sys.modules[mod] | ||
# Kinda cool, though, right? |
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