<s> from __future__ import absolute_import <EOL> import warnings <EOL> from raven . _compat import PY2 , text_type <EOL> from raven . exceptions import InvalidDsn <EOL> from raven . transport . threaded import ThreadedHTTPTransport <EOL> from raven . utils . encoding import to_string <EOL> from raven . utils . urlparse import parse_qsl , urlparse <EOL> ERR_UNKNOWN_SCHEME = '<STR_LIT>' <EOL> DEFAULT_TRANSPORT = ThreadedHTTPTransport <EOL> class RemoteConfig ( object ) : <EOL> def __init__ ( self , base_url = None , project = None , public_key = None , <EOL> secret_key = None , transport = None , options = None ) : <EOL> if base_url : <EOL> base_url = base_url . rstrip ( '<STR_LIT:/>' ) <EOL> store_endpoint = '<STR_LIT>' % ( base_url , project ) <EOL> else : <EOL> store_endpoint = None <EOL> self . base_url = base_url <EOL> self . project = project <EOL> self . public_key = public_key <EOL> self . secret_key = secret_key <EOL> self . options = options or { } <EOL> self . store_endpoint = store_endpoint <EOL> self . _transport_cls = transport or DEFAULT_TRANSPORT <EOL> def __unicode__ ( self ) : <EOL> return text_type ( self . base_url ) <EOL> def is_active ( self ) : <EOL> return all ( [ self . base_url , self . project , self . public_key , self . secret_key ] ) <EOL> def get_transport ( self ) : <EOL> if not self . store_endpoint : <EOL> return <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> parsed = urlparse ( self . store_endpoint ) <EOL> self . _transport = self . _transport_cls ( parsed , ** self . options ) <EOL> return self . _transport <EOL> def get_public_dsn ( self ) : <EOL> url = urlparse ( self . base_url ) <EOL> netloc = url . hostname <EOL> if url . port : <EOL> netloc += '<STR_LIT>' % url . port <EOL> return '<STR_LIT>' % ( self . public_key , netloc , url . path , self . project ) <EOL> @ classmethod <EOL> def from_string ( cls , value , transport = None , transport_registry = None ) : <EOL> if PY2 : <EOL> value = to_string ( value ) <EOL> url = urlparse ( value ) <EOL> if url . scheme not in ( '<STR_LIT:http>' , '<STR_LIT>' ) : <EOL> warnings . warn ( '<STR_LIT>' ) <EOL> if transport is None : <EOL> if not transport_registry : <EOL> from raven . transport import TransportRegistry , default_transports <EOL> transport_registry = TransportRegistry ( default_transports ) <EOL> if not transport_registry . supported_scheme ( url . scheme ) : <EOL> raise InvalidDsn ( ERR_UNKNOWN_SCHEME . format ( url . scheme , value ) ) <EOL> transport = transport_registry . get_transport_cls ( url . scheme ) <EOL> netloc = url . hostname <EOL> if url . port : <EOL> netloc += '<STR_LIT>' % url . port <EOL> path_bits = url . path . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) <EOL> if len ( path_bits ) > <NUM_LIT:1> : <EOL> path = path_bits [ <NUM_LIT:0> ] <EOL> else : <EOL> path = '<STR_LIT>' <EOL> project = path_bits [ - <NUM_LIT:1> ] <EOL> if not all ( [ netloc , project , url . username , url . password ] ) : <EOL> raise InvalidDsn ( '<STR_LIT>' % url . geturl ( ) ) <EOL> base_url = '<STR_LIT>' % ( url . scheme . rsplit ( '<STR_LIT:+>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] , netloc , path ) <EOL> return cls ( <EOL> base_url = base_url , <EOL> project = project , <EOL> public_key = url . username , <EOL> secret_key = url . password , <EOL> options = dict ( parse_qsl ( url . query ) ) , <EOL> transport = transport , <EOL> ) </s>
