Skip to content

Instantly share code, notes, and snippets.

@gthank
Created June 9, 2017 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gthank/81bd9b9c570b3dce3293a339fbd71335 to your computer and use it in GitHub Desktop.
Save gthank/81bd9b9c570b3dce3293a339fbd71335 to your computer and use it in GitHub Desktop.
# 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