From 568720334aa630ea504b2ce3b8c324f0a557d6e6 Mon Sep 17 00:00:00 2001 From: k clair Date: Tue, 9 Oct 2012 13:14:36 -0700 Subject: add source files from upstream --- .../packages/oauthlib/oauth2/draft25/utils.py | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 requests-0.14.0/requests/packages/oauthlib/oauth2/draft25/utils.py (limited to 'requests-0.14.0/requests/packages/oauthlib/oauth2/draft25/utils.py') diff --git a/requests-0.14.0/requests/packages/oauthlib/oauth2/draft25/utils.py b/requests-0.14.0/requests/packages/oauthlib/oauth2/draft25/utils.py new file mode 100644 index 0000000..75d5fcc --- /dev/null +++ b/requests-0.14.0/requests/packages/oauthlib/oauth2/draft25/utils.py @@ -0,0 +1,39 @@ +""" +oauthlib.utils +~~~~~~~~~~~~~~ + +This module contains utility methods used by various parts of the OAuth 2 spec. +""" + +import urllib +import urlparse + + +def host_from_uri(uri): + """Extract hostname and port from URI. + + Will use default port for HTTP and HTTPS if none is present in the URI. + """ + default_ports = { + u'HTTP': u'80', + u'HTTPS': u'443', + } + + sch, netloc, path, par, query, fra = urlparse.urlparse(uri) + if u':' in netloc: + netloc, port = netloc.split(u':', 1) + else: + port = default_ports.get(sch.upper()) + + return netloc, port + + +def escape(u): + """Escape a string in an OAuth-compatible fashion. + + TODO: verify whether this can in fact be used for OAuth 2 + + """ + if not isinstance(u, unicode): + raise ValueError('Only unicode objects are escapable.') + return urllib.quote(u.encode('utf-8'), safe='~') -- cgit v1.2.3