Skip to content

Instantly share code, notes, and snippets.

@maxkoryukov
maxkoryukov / Issue.md
Created May 28, 2017 09:59 — forked from Ashton-W/Issue.md
GitHub Markdown toggle code block
Click to toggle contents of `code` ``` CODE! ```
Click to toggle contents of other `code` ```
@maxkoryukov
maxkoryukov / iri2uri.py
Created August 23, 2018 22:38
Python: convert IRI (in two words: URL with non-ascii characters) into valid URI. This func makes it easy to open any URL in python with urllib2. ORIGINAL: https://blog.elsdoerfer.name/2008/12/12/opening-iris-in-python/
def asciify_url(url, force_quote=False):
r"""
SOURCE: https://blog.elsdoerfer.name/2008/12/12/opening-iris-in-python/
Attempts to make a unicode url usuable with ``urllib/urllib2``.
More specifically, it attempts to convert the unicode object ``url``,
which is meant to represent a IRI, to an unicode object that,
containing only ASCII characters, is a valid URI. This involves: