<s> import six <EOL> from six . moves import urllib <EOL> import requests <EOL> def sort_url_by_qs_keys ( url ) : <EOL> parsed = urllib . parse . urlparse ( url ) <EOL> path = parsed . path <EOL> query = parsed . query <EOL> if not query : <EOL> path , query = parsed . path . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) <EOL> queries = urllib . parse . parse_qsl ( query , True ) <EOL> sorted_query = sorted ( queries , key = lambda x : x [ <NUM_LIT:0> ] ) <EOL> encoded_sorted_query = urllib . parse . urlencode ( sorted_query , True ) <EOL> url_parts = ( parsed . scheme , parsed . netloc , path , <EOL> parsed . params , encoded_sorted_query , <EOL> parsed . fragment ) <EOL> return urllib . parse . urlunparse ( url_parts ) <EOL> class FakeHTTPResponse ( object ) : <EOL> def __init__ ( self , status = <NUM_LIT:200> , headers = None , data = None , * args , ** kwargs ) : <EOL> data = data or '<STR_LIT>' <EOL> self . data = six . StringIO ( data ) <EOL> self . read = self . data . read <EOL> self . status = status <EOL> self . headers = headers or { '<STR_LIT>' : len ( data ) } <EOL> if not kwargs . get ( '<STR_LIT>' , False ) : <EOL> self . body = None <EOL> def getheader ( self , name , default = None ) : <EOL> return self . headers . get ( name . lower ( ) , default ) <EOL> def getheaders ( self ) : <EOL> return self . headers or { } <EOL> def read ( self , amt ) : <EOL> self . data . read ( amt ) <EOL> def release_conn ( self ) : <EOL> pass <EOL> def close ( self ) : <EOL> self . data . close ( ) <EOL> def fake_response ( status_code = <NUM_LIT:200> , headers = None , content = None , ** kwargs ) : <EOL> r = requests . models . Response ( ) <EOL> r . status_code = status_code <EOL> r . headers = headers or { } <EOL> r . raw = FakeHTTPResponse ( status_code , headers , content , kwargs ) <EOL> return r </s>
