<s> import __builtin__ <EOL> import os <EOL> import os . path <EOL> import sys <EOL> import glob <EOL> import ConfigParser <EOL> import ssl <EOL> CONF_DIR = os . path . expanduser ( "<STR_LIT>" ) <EOL> CERT_DIR = os . path . join ( CONF_DIR , "<STR_LIT>" ) <EOL> SESSION_DIR = os . path . join ( CONF_DIR , "<STR_LIT>" ) <EOL> ARCHIVE_DIR = os . path . join ( CONF_DIR , "<STR_LIT>" ) <EOL> PLUGIN_DIR = os . path . join ( CONF_DIR , "<STR_LIT>" ) <EOL> def check_config_dir ( ) : <EOL> existed = True <EOL> if not os . path . exists ( CONF_DIR ) : <EOL> os . mkdir ( CONF_DIR , <NUM_LIT:0> <NUM_LIT> ) <EOL> if not os . path . exists ( CERT_DIR ) : <EOL> os . mkdir ( CERT_DIR , <NUM_LIT:0> <NUM_LIT> ) <EOL> existed = False <EOL> if not os . path . exists ( os . path . join ( CERT_DIR , "<STR_LIT>" ) ) : <EOL> os . mkdir ( os . path . join ( CERT_DIR , "<STR_LIT>" ) , <NUM_LIT:0> <NUM_LIT> ) <EOL> if not os . path . exists ( SESSION_DIR ) : <EOL> os . mkdir ( SESSION_DIR , <NUM_LIT:0> <NUM_LIT> ) <EOL> if not os . path . exists ( ARCHIVE_DIR ) : <EOL> os . mkdir ( ARCHIVE_DIR , <NUM_LIT:0> <NUM_LIT> ) <EOL> if not os . path . exists ( PLUGIN_DIR ) : <EOL> os . mkdir ( PLUGIN_DIR , <NUM_LIT:0> <NUM_LIT> ) <EOL> return existed <EOL> def load_plugins ( ) : <EOL> sys . path . append ( os . path . join ( CONF_DIR , "<STR_LIT>" ) ) <EOL> for f in glob . glob ( os . path . join ( PLUGIN_DIR , "<STR_LIT>" ) ) : <EOL> m , ext = os . path . splitext ( os . path . basename ( f ) ) <EOL> __builtin__ . __dict__ . update ( __import__ ( m , globals ( ) , locals ( ) , "<STR_LIT:.>" ) . __dict__ ) <EOL> class Configuration ( object ) : <EOL> """<STR_LIT>""" <EOL> ssl_map = { "<STR_LIT>" : ssl . PROTOCOL_SSLv3 , "<STR_LIT>" : ssl . PROTOCOL_SSLv23 , <EOL> "<STR_LIT>" : ssl . PROTOCOL_SSLv2 , "<STR_LIT>" : ssl . PROTOCOL_TLSv1 } <EOL> def __init__ ( self ) : <EOL> self . ip = '<STR_LIT:127.0.0.1>' <EOL> self . port = <NUM_LIT> <EOL> self . proxy = None <EOL> self . target = None <EOL> self . timeout = <NUM_LIT:10> <EOL> self . delay = <NUM_LIT:0> <EOL> self . autosave = True <EOL> self . history = True <EOL> self . color_enabled = True <EOL> self . term_width = "<STR_LIT>" <EOL> self . viewer = '<STR_LIT>' <EOL> self . external_viewer = '<STR_LIT>' <EOL> self . editor = '<STR_LIT>' <EOL> self . editor_play = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> self . diff_editor = "<STR_LIT>" <EOL> self . ssl_hostname = None <EOL> self . ssl_reverse = False <EOL> self . ssl_verify = "<STR_LIT>" <EOL> self . update_content_length = True <EOL> self . _ssl_version = ssl . PROTOCOL_SSLv23 <EOL> self . _values = { "<STR_LIT:port>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:target>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> def _get_ssl_version ( self ) : <EOL> for k , v in self . ssl_map . items ( ) : <EOL> if v == self . _ssl_version : <EOL> return k <EOL> def _set_ssl_version ( self , v ) : <EOL> try : <EOL> self . _ssl_version = self . ssl_map [ v ] <EOL> except KeyError : <EOL> raise Exception ( "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( self . ssl_map . keys ( ) ) ) <EOL> ssl_version = property ( _get_ssl_version , _set_ssl_version ) <EOL> def __repr__ ( self ) : <EOL> return str ( self ) <EOL> def __str__ ( self ) : <EOL> max_l = max ( [ len ( x ) for x in self . _values . keys ( ) ] ) + <NUM_LIT:1> <EOL> return "<STR_LIT:\n>" . join ( sorted ( [ ( s + "<STR_LIT::>" ) . ljust ( max_l ) + str ( getattr ( self , s ) ) for s in self . _values ] ) ) <EOL> def import_env ( self ) : <EOL> if "<STR_LIT>" in os . environ : <EOL> conf . proxy = os . environ [ "<STR_LIT>" ] <EOL> print "<STR_LIT>" , conf . proxy , "<STR_LIT>" <EOL> def import_dict ( self , d ) : <EOL> for v in self . _values : <EOL> if hasattr ( d , v ) : <EOL> setattr ( self , v , getattr ( d , v ) ) <EOL> def load ( self ) : <EOL> if os . path . exists ( os . path . join ( CONF_DIR , "<STR_LIT>" ) ) : <EOL> c = ConfigParser . RawConfigParser ( ) <EOL> c . read ( os . path . join ( CONF_DIR , "<STR_LIT>" ) ) <EOL> if not c . has_section ( "<STR_LIT>" ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> for k , v in self . _values . items ( ) : <EOL> if c . has_option ( "<STR_LIT>" , k ) : <EOL> setattr ( self , k , getattr ( c , v ) . __call__ ( "<STR_LIT>" , k ) ) <EOL> def save ( self , force = False ) : <EOL> import abrupt . session <EOL> if abrupt . session . session_name != "<STR_LIT:default>" and not force : <EOL> from abrupt . color import error <EOL> print error ( """<STR_LIT>""" ) <EOL> return <EOL> c = ConfigParser . RawConfigParser ( ) <EOL> c . add_section ( '<STR_LIT>' ) <EOL> for s in self . _values : <EOL> p = getattr ( self , s ) <EOL> if not p is None : <EOL> c . set ( '<STR_LIT>' , s , p ) <EOL> with open ( os . path . join ( CONF_DIR , "<STR_LIT>" ) , "<STR_LIT:w>" ) as f : <EOL> c . write ( f ) <EOL> conf = Configuration ( ) </s>
