Created
June 9, 2017 15:44
-
-
Save gthank/81bd9b9c570b3dce3293a339fbd71335 to your computer and use it in GitHub Desktop.
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
# Works on Py3 | |
def parse_version_failsafe(version_string): | |
try: | |
return Version( | |
unicodedata.normalize('NFKD', six.text_type(version_string)) | |
) | |
except (UnicodeError, InvalidVersion): | |
return None | |
# Fails on Py3 | |
def parse_version_failsafe(version_string): | |
uni_version = six.text_type(version_string) | |
try: | |
normalized_version = unicodedata.normalize('NFKD', uni_version) | |
ascii_safe_version = normalized_version.encode('ascii', 'ignore') | |
final_form = six.text_type(ascii_safe_version) | |
return Version(final_form) | |
except (UnicodeError, InvalidVersion): | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment