 try : 
 from urllib . parse import urljoin 
 try : <EOL> from urllib . parse import urljoin <EOL> except ImportError : <EOL> from urlparse import urljoin <EOL> try : <EOL> FileNotFoundError <EOL> except NameError : <EOL> FileNotFoundError = IOError <EOL> from io import BytesIO <EOL> import requests <EOL> import warnings <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . conf import settings <EOL> from django . utils . encoding import filepath_to_uri <EOL> from localdevstorage . base import BaseStorage <EOL> class HttpStorage ( BaseStorage ) : <EOL> def __init__ ( self , location = None , base_url = None , fallback_url = None , fallback_domain = None ) : <EOL> self . fallback_url = fallback_url or getattr ( settings , '<STR_LIT>' , None ) <EOL> if self . fallback_url : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> self . fallback_domain = fallback_domain or getattr ( settings , '<STR_LIT>' , None ) <EOL> if not ( self . fallback_url or self . fallback_domain ) : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' ) <EOL> self . session = requests . Session ( ) <EOL> username = getattr ( settings , '<STR_LIT>' , None ) <EOL> password = getattr ( settings , '<STR_LIT>' , None ) <EOL> if username and password : <EOL> self . session . auth = ( username , password ) <EOL> super ( BaseStorage , self ) . __init__ ( location , base_url ) <EOL> def _exists_upstream ( self , name ) : <EOL> try : <EOL> response = self . session . head ( self . _path ( name ) ) <EOL> return response . status_code == <NUM_LIT:200> <EOL> except FileNotFoundError : <EOL> return False <EOL> def _url ( self , name ) : <EOL> return urljoin ( '<STR_LIT:/>' , filepath_to_uri ( name ) ) <EOL> def _path ( self , name ) : <EOL> if self . fallback_domain : <EOL> return urljoin ( self . fallback_domain , self . _url ( name ) ) <EOL> return self . fallback_url + name <EOL> def _get ( self , name ) : <EOL> response = self . session . get ( self . _path ( name ) ) <EOL> if response . status_code != <NUM_LIT:200> : <EOL> raise FileNotFoundError ( ) <EOL> return BytesIO ( response . content ) </s>
