2013-12-11 22:09:25 +00:00
|
|
|
import collections
|
2013-07-10 20:25:57 +00:00
|
|
|
import HydrusConstants as HC
|
2013-07-17 20:56:13 +00:00
|
|
|
import HydrusTags
|
2013-07-10 20:25:57 +00:00
|
|
|
import os
|
|
|
|
import random
|
2013-12-11 22:09:25 +00:00
|
|
|
import threading
|
2014-06-18 21:53:48 +00:00
|
|
|
import weakref
|
2015-03-25 22:04:19 +00:00
|
|
|
import HydrusData
|
2013-07-31 21:26:38 +00:00
|
|
|
|
|
|
|
tinest_gif = '\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x00\xFF\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x00\x3B'
|
2013-07-10 20:25:57 +00:00
|
|
|
|
2014-02-12 23:09:38 +00:00
|
|
|
class FakeHTTPConnectionManager():
|
2013-07-31 21:26:38 +00:00
|
|
|
|
2014-02-12 23:09:38 +00:00
|
|
|
def __init__( self ):
|
2013-11-06 18:22:07 +00:00
|
|
|
|
2014-02-12 23:09:38 +00:00
|
|
|
self._fake_responses = {}
|
2013-07-31 21:26:38 +00:00
|
|
|
|
|
|
|
|
2015-07-22 19:40:39 +00:00
|
|
|
def Request( self, method, url, request_headers = None, body = '', return_everything = False, return_cookies = False, report_hooks = None, temp_path = None ):
|
2015-03-25 22:04:19 +00:00
|
|
|
|
|
|
|
if request_headers is None: request_headers = {}
|
|
|
|
if report_hooks is None: report_hooks = []
|
2013-07-31 21:26:38 +00:00
|
|
|
|
2014-02-12 23:09:38 +00:00
|
|
|
( response, size_of_response, response_headers, cookies ) = self._fake_responses[ ( method, url ) ]
|
2013-07-31 21:26:38 +00:00
|
|
|
|
2015-03-25 22:04:19 +00:00
|
|
|
if temp_path is not None:
|
2013-11-06 18:22:07 +00:00
|
|
|
|
2014-02-12 23:09:38 +00:00
|
|
|
with open( temp_path, 'wb' ) as f: f.write( response )
|
|
|
|
|
2015-03-25 22:04:19 +00:00
|
|
|
response = 'path written to temporary path'
|
2013-11-06 18:22:07 +00:00
|
|
|
|
2013-07-31 21:26:38 +00:00
|
|
|
|
2014-02-12 23:09:38 +00:00
|
|
|
if return_everything: return ( response, size_of_response, response_headers, cookies )
|
|
|
|
elif return_cookies: return ( response, cookies )
|
|
|
|
else: return response
|
2013-07-31 21:26:38 +00:00
|
|
|
|
|
|
|
|
2015-03-25 22:04:19 +00:00
|
|
|
def SetResponse( self, method, url, response, size_of_response = 100, response_headers = None, cookies = None ):
|
|
|
|
|
|
|
|
if response_headers is None: response_headers = {}
|
|
|
|
if cookies is None: cookies = []
|
2013-07-31 21:26:38 +00:00
|
|
|
|
2014-02-12 23:09:38 +00:00
|
|
|
self._fake_responses[ ( method, url ) ] = ( response, size_of_response, response_headers, cookies )
|
2013-07-31 21:26:38 +00:00
|
|
|
|
|
|
|
|
2013-12-04 22:44:16 +00:00
|
|
|
class FakeWebSessionManager():
|
|
|
|
|
|
|
|
def GetCookies( self, *args, **kwargs ): return { 'session_cookie' : 'blah' }
|
|
|
|
|