<s> from __future__ import absolute_import , unicode_literals <EOL> """<STR_LIT>""" <EOL> import os <EOL> import datetime <EOL> try : <EOL> from urllib import quote <EOL> except ImportError : <EOL> from urllib . parse import quote <EOL> try : <EOL> from urlparse import urlparse <EOL> except ImportError : <EOL> from urllib . parse import urlparse <EOL> from oauthlib . common import unicode_type , urldecode <EOL> def list_to_scope ( scope ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( scope , unicode_type ) or scope is None : <EOL> return scope <EOL> elif isinstance ( scope , list ) : <EOL> return "<STR_LIT:U+0020>" . join ( scope ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def scope_to_list ( scope ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( scope , list ) or scope is None : <EOL> return scope <EOL> else : <EOL> return scope . split ( "<STR_LIT:U+0020>" ) <EOL> def params_from_uri ( uri ) : <EOL> params = dict ( urldecode ( urlparse ( uri ) . query ) ) <EOL> if '<STR_LIT>' in params : <EOL> params [ '<STR_LIT>' ] = scope_to_list ( params [ '<STR_LIT>' ] ) <EOL> return params <EOL> def host_from_uri ( uri ) : <EOL> """<STR_LIT>""" <EOL> default_ports = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> sch , netloc , path , par , query , fra = urlparse ( uri ) <EOL> if '<STR_LIT::>' in netloc : <EOL> netloc , port = netloc . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> else : <EOL> port = default_ports . get ( sch . upper ( ) ) <EOL> return netloc , port <EOL> def escape ( u ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( u , unicode_type ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return quote ( u . encode ( '<STR_LIT:utf-8>' ) , safe = b'<STR_LIT>' ) <EOL> def generate_age ( issue_time ) : <EOL> """<STR_LIT>""" <EOL> td = datetime . datetime . now ( ) - issue_time <EOL> age = ( td . microseconds + ( td . seconds + td . days * <NUM_LIT> * <NUM_LIT> ) * <NUM_LIT:10> ** <NUM_LIT:6> ) / <NUM_LIT:10> ** <NUM_LIT:6> <EOL> return unicode_type ( age ) <EOL> def is_secure_transport ( uri ) : <EOL> """<STR_LIT>""" <EOL> if os . environ . get ( '<STR_LIT>' ) : <EOL> return True <EOL> return uri . lower ( ) . startswith ( '<STR_LIT>' ) </s>
