<s> import os <EOL> import sys <EOL> import pickle <EOL> import struct <EOL> import uuid <EOL> import time <EOL> from threading import Event <EOL> from sleekxmpp import ClientXMPP <EOL> from sleekxmpp . jid import JID <EOL> from sleekxmpp . xmlstream . handler import Callback <EOL> from sleekxmpp . xmlstream . matcher import StanzaPath <EOL> from sleekxmpp . xmlstream . tostring import tostring <EOL> from sleekxmpp . exceptions import IqError <EOL> from sleekxmpp . plugins . xep_0060 . stanza . pubsub_event import EventItem <EOL> from baboon . baboon . monitor import FileEvent <EOL> from baboon . baboon . config import config <EOL> from baboon . common import proxy_socket <EOL> from baboon . common . eventbus import eventbus <EOL> from baboon . common . logger import logger <EOL> from baboon . common import pyrsync <EOL> from baboon . common . stanza import rsync <EOL> from baboon . common . errors . baboon_exception import BaboonException <EOL> @ logger <EOL> class CommonTransport ( ClientXMPP ) : <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> ClientXMPP . __init__ ( self , config [ '<STR_LIT:user>' ] [ '<STR_LIT>' ] , config [ '<STR_LIT:user>' ] [ <EOL> '<STR_LIT>' ] ) <EOL> self . connected = Event ( ) <EOL> self . disconnected = Event ( ) <EOL> self . rsync_running = Event ( ) <EOL> self . rsync_finished = Event ( ) <EOL> self . wait_close = False <EOL> self . failed_auth = False <EOL> self . register_plugin ( '<STR_LIT>' ) <EOL> self . register_handler ( Callback ( '<STR_LIT>' , StanzaPath ( <EOL> '<STR_LIT>' ) , self . _pubsub_event ) ) <EOL> self . pubsub = self . plugin [ "<STR_LIT>" ] <EOL> self . register_plugin ( '<STR_LIT>' ) <EOL> self . form = self . plugin [ '<STR_LIT>' ] <EOL> self . pubsub_addr = config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . server_addr = config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . add_event_handler ( '<STR_LIT>' , self . start ) <EOL> self . add_event_handler ( '<STR_LIT>' , self . _on_failed_auth ) <EOL> self . add_event_handler ( '<STR_LIT>' , self . stream_err ) <EOL> self . add_event_handler ( '<STR_LIT:message>' , self . message ) <EOL> self . add_event_handler ( '<STR_LIT>' , self . message_form ) <EOL> self . add_event_handler ( '<STR_LIT>' , self . message_form ) <EOL> self . register_handler ( Callback ( '<STR_LIT>' , <EOL> StanzaPath ( '<STR_LIT>' ) , <EOL> self . _handle_rsync_finished ) ) <EOL> eventbus . register ( '<STR_LIT>' , self . _on_new_rsync ) <EOL> def __enter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . open ( ) <EOL> while not self . connected . is_set ( ) : <EOL> if self . failed_auth : <EOL> raise BaboonException ( "<STR_LIT>" ) <EOL> self . connected . wait ( <NUM_LIT:1> ) <EOL> return self <EOL> def __exit__ ( self , type , value , traceback ) : <EOL> """<STR_LIT>""" <EOL> self . close ( ) <EOL> def open ( self , block = False ) : <EOL> """<STR_LIT>""" <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . use_ipv6 = False <EOL> if self . connect ( use_ssl = False , use_tls = False ) : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . disconnected . clear ( ) <EOL> self . process ( block = block ) <EOL> else : <EOL> self . logger . error ( "<STR_LIT>" ) <EOL> def stream_err ( self , iq ) : <EOL> """<STR_LIT>""" <EOL> self . logger . error ( iq [ '<STR_LIT:text>' ] ) <EOL> def _on_failed_auth ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . logger . error ( "<STR_LIT>" ) <EOL> eventbus . fire ( '<STR_LIT>' ) <EOL> self . failed_auth = True <EOL> self . close ( ) <EOL> def start ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . send_presence ( ) <EOL> self . get_roster ( ) <EOL> self . connected . set ( ) <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . connected . clear ( ) <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> self . disconnect ( wait = True ) <EOL> self . disconnected . set ( ) <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> def _pubsub_event ( self , msg ) : <EOL> """<STR_LIT>""" <EOL> if msg [ '<STR_LIT:type>' ] in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> msg [ '<STR_LIT>' ] ) <EOL> items = msg [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> for item in items : <EOL> notif_msg = "<STR_LIT>" <EOL> if isinstance ( item , EventItem ) : <EOL> self . logger . info ( item [ '<STR_LIT>' ] . get ( '<STR_LIT:status>' ) ) <EOL> notif_msg += item [ '<STR_LIT>' ] . get ( '<STR_LIT:status>' ) <EOL> for err_f in item [ '<STR_LIT>' ] : <EOL> if err_f . text : <EOL> err = "<STR_LIT>" % err_f . text <EOL> self . logger . warning ( err ) <EOL> notif_msg = "<STR_LIT>" % ( notif_msg , err ) <EOL> if item [ '<STR_LIT>' ] . get ( '<STR_LIT:type>' ) == '<STR_LIT:error>' : <EOL> eventbus . fire ( '<STR_LIT>' , notif_msg ) <EOL> else : <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> msg [ '<STR_LIT>' ] ) <EOL> def _on_new_rsync ( self , project , files , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . connected . wait ( ) <EOL> self . rsync ( project , files = files ) <EOL> eventbus . fire ( '<STR_LIT>' , project , files ) <EOL> def _handle_rsync_finished ( self , iq ) : <EOL> """<STR_LIT>""" <EOL> node = iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . logger . debug ( "<STR_LIT>" % node ) <EOL> iq . reply ( ) . send ( ) <EOL> self . rsync_running . clear ( ) <EOL> self . rsync_finished . set ( ) <EOL> if not self . wait_close : <EOL> self . merge_verification ( node ) <EOL> def message_form ( self , form ) : <EOL> self . logger . debug ( "<STR_LIT>" % form ) <EOL> try : <EOL> expected_type = '<STR_LIT>' <EOL> if expected_type in form [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:value>' ] : <EOL> node = form [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:value>' ] <EOL> jid = form [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT:value>' ] <EOL> user = JID ( jid ) . user <EOL> self . logger . info ( "<STR_LIT>" % ( user , node ) ) <EOL> self . logger . info ( "<STR_LIT>" % ( node , user ) ) <EOL> self . logger . info ( "<STR_LIT>" % ( node , user ) ) <EOL> except KeyError : <EOL> pass <EOL> def message ( self , msg ) : <EOL> self . logger . info ( "<STR_LIT>" % msg ) <EOL> def rsync_error ( self , msg ) : <EOL> """<STR_LIT>""" <EOL> self . logger . error ( msg ) <EOL> self . rsync_running . clear ( ) <EOL> self . rsync_finished . set ( ) <EOL> @ logger <EOL> class WatchTransport ( CommonTransport ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( WatchTransport , self ) . __init__ ( ) <EOL> self . streamer_addr = config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . register_plugin ( '<STR_LIT>' ) <EOL> self . register_plugin ( '<STR_LIT>' ) <EOL> self . add_event_handler ( '<STR_LIT>' , self . _on_socks_connected ) <EOL> def start ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . send_presence ( ) <EOL> self . get_roster ( ) <EOL> self . adhoc = self . plugin [ "<STR_LIT>" ] <EOL> self . streamer = self . plugin [ "<STR_LIT>" ] <EOL> try : <EOL> streamhost_used = self . streamer . handshake ( self . server_addr , <EOL> self . streamer_addr ) <EOL> except IqError as e : <EOL> self . logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . close ( ) <EOL> return <EOL> self . sid = streamhost_used [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> def _on_socks_connected ( self , event ) : <EOL> """<STR_LIT:U+0020>""" <EOL> proxy_sock = self . streamer . get_socket ( self . sid ) <EOL> proxy_listener = proxy_socket . listen ( self . sid , proxy_sock , <EOL> self . _on_socks5_data ) <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . connected . set ( ) <EOL> for project in config [ '<STR_LIT>' ] : <EOL> self . _get_pending_users ( project ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . wait_close = True <EOL> if self . rsync_running . is_set ( ) : <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> self . rsync_finished . wait ( ) <EOL> self . logger . info ( "<STR_LIT>" ) <EOL> if hasattr ( self , '<STR_LIT>' ) and self . streamer : <EOL> self . streamer . close ( ) <EOL> super ( WatchTransport , self ) . close ( ) <EOL> def rsync ( self , project , files = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . connected . is_set ( ) : <EOL> self . connected . wait ( ) <EOL> self . rsync_running . set ( ) <EOL> self . rsync_finished . clear ( ) <EOL> max_stanza_size = int ( config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> iq = self . _build_iq ( project , files ) <EOL> try : <EOL> to_xml = tostring ( iq . xml ) <EOL> size = sys . getsizeof ( to_xml ) <EOL> if size >= max_stanza_size : <EOL> iqs = self . _split_iq ( size , project , files ) <EOL> self . logger . warning ( '<STR_LIT>' <EOL> % len ( iqs ) ) <EOL> else : <EOL> iqs = [ iq ] <EOL> for iq in iqs : <EOL> iq . send ( ) <EOL> self . logger . debug ( '<STR_LIT>' % <EOL> ( iqs . index ( iq ) + <NUM_LIT:1> , len ( iqs ) ) ) <EOL> except IqError as e : <EOL> self . rsync_error ( e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:text>' ] ) <EOL> except Exception as e : <EOL> self . rsync_error ( e ) <EOL> def _build_iq ( self , project , files ) : <EOL> """<STR_LIT>""" <EOL> iq = self . Iq ( sto = self . server_addr , stype = '<STR_LIT>' ) <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] = self . sid <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] = str ( uuid . uuid4 ( ) ) <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] = project <EOL> for f in files : <EOL> if f . event_type == FileEvent . MODIF : <EOL> iq [ '<STR_LIT>' ] . add_file ( f . src_path ) <EOL> elif f . event_type == FileEvent . CREATE : <EOL> iq [ '<STR_LIT>' ] . add_create_file ( f . src_path ) <EOL> elif f . event_type == FileEvent . DELETE : <EOL> iq [ '<STR_LIT>' ] . add_delete_file ( f . src_path ) <EOL> return iq <EOL> def _split_iq ( self , size , project , files ) : <EOL> """<STR_LIT>""" <EOL> iqs = [ ] <EOL> chunk_num = size / int ( config [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) + <NUM_LIT:1> <EOL> step = len ( files ) / chunk_num <EOL> chunks = list ( self . _get_chunks ( files , step ) ) <EOL> for chunk in chunks : <EOL> iqs . append ( self . _build_iq ( project , chunk ) ) <EOL> return iqs <EOL> def _get_chunks ( self , files , step ) : <EOL> """<STR_LIT>""" <EOL> for i in xrange ( <NUM_LIT:0> , len ( files ) , step ) : <EOL> yield files [ i : i + step ] <EOL> def _on_socks5_data ( self , sid , data , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> deltas = [ ] <EOL> ret = { '<STR_LIT>' : self . boundjid . bare } <EOL> ret [ '<STR_LIT>' ] = data [ '<STR_LIT>' ] <EOL> ret [ '<STR_LIT>' ] = data [ '<STR_LIT>' ] <EOL> all_hashes = data [ '<STR_LIT>' ] <EOL> for elem in all_hashes : <EOL> relpath = elem [ <NUM_LIT:0> ] <EOL> hashes = elem [ <NUM_LIT:1> ] <EOL> project_path = config [ '<STR_LIT>' ] [ data [ '<STR_LIT>' ] ] [ '<STR_LIT:path>' ] <EOL> project_path = os . path . expanduser ( project_path ) <EOL> fullpath = os . path . join ( project_path , relpath ) <EOL> if os . path . exists ( fullpath ) and os . path . isfile ( fullpath ) : <EOL> patchedfile = open ( fullpath , '<STR_LIT:rb>' ) <EOL> delta = pyrsync . rsyncdelta ( patchedfile , hashes , <EOL> blocksize = <NUM_LIT> ) <EOL> delta = ( relpath , delta ) <EOL> deltas . append ( delta ) <EOL> else : <EOL> pass <EOL> ret [ '<STR_LIT>' ] = deltas <EOL> self . streamer . send ( sid , proxy_socket . pack ( ret ) ) <EOL> def merge_verification ( self , project ) : <EOL> """<STR_LIT>""" <EOL> iq = self . Iq ( sto = self . server_addr , stype = '<STR_LIT>' ) <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] = project <EOL> try : <EOL> iq . send ( ) <EOL> except IqError as e : <EOL> self . logger . error ( e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:text>' ] ) <EOL> def _get_pending_users ( self , node ) : <EOL> """<STR_LIT>""" <EOL> iq = self . Iq ( sto = self . pubsub_addr , stype = '<STR_LIT>' ) <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT:action>' ] = '<STR_LIT>' <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] . add_field ( var = '<STR_LIT>' , value = node ) <EOL> try : <EOL> iq . send ( ) <EOL> except IqError : <EOL> pass <EOL> @ logger <EOL> class AdminTransport ( CommonTransport ) : <EOL> def __init__ ( self , logger_enabled = True ) : <EOL> super ( AdminTransport , self ) . __init__ ( ) <EOL> self . logger . disabled = not logger_enabled <EOL> def create_project ( self , project ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> node_config = self . pubsub . get_node_config ( self . pubsub_addr ) <EOL> node_config_form = node_config [ '<STR_LIT>' ] [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> node_config_form . field [ '<STR_LIT>' ] . set_value ( <EOL> '<STR_LIT>' ) <EOL> node_config_form . field [ '<STR_LIT>' ] . set_value ( True ) <EOL> self . pubsub . create_node ( self . pubsub_addr , project , <EOL> config = node_config_form ) <EOL> self . pubsub . modify_subscriptions ( self . pubsub_addr , project , <EOL> [ ( config [ '<STR_LIT:user>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' ) ] ) <EOL> self . pubsub . modify_affiliations ( self . pubsub_addr , project , <EOL> [ ( self . server_addr , '<STR_LIT>' ) ] ) <EOL> return ( <NUM_LIT:200> , '<STR_LIT>' % project ) <EOL> except IqError as e : <EOL> status_code = int ( e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:code>' ] ) <EOL> msg = "<STR_LIT>" "<STR_LIT>" % project <EOL> if status_code == <NUM_LIT> : <EOL> msg = '<STR_LIT>' % project <EOL> return ( status_code , msg ) <EOL> def delete_project ( self , project ) : <EOL> try : <EOL> self . pubsub . delete_node ( self . pubsub_addr , project ) <EOL> return ( <NUM_LIT:200> , '<STR_LIT>' % project ) <EOL> except IqError as e : <EOL> status_code = int ( e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:code>' ] ) <EOL> msg = "<STR_LIT>" "<STR_LIT>" % project <EOL> if status_code == <NUM_LIT> : <EOL> msg = '<STR_LIT>' % project <EOL> elif status_code == <NUM_LIT> : <EOL> msg = '<STR_LIT>' % project <EOL> return ( status_code , msg ) <EOL> def join_project ( self , project ) : <EOL> try : <EOL> ret_iq = self . pubsub . subscribe ( self . pubsub_addr , project ) <EOL> status = ret_iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if status == '<STR_LIT>' : <EOL> return ( <NUM_LIT> , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> elif status == '<STR_LIT>' : <EOL> return ( <NUM_LIT:200> , "<STR_LIT>" % <EOL> project ) <EOL> else : <EOL> return ( <NUM_LIT> , "<STR_LIT>" <EOL> "<STR_LIT>" % project ) <EOL> except IqError as e : <EOL> status_code = int ( e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:code>' ] ) <EOL> msg = "<STR_LIT>" % project <EOL> if status_code == <NUM_LIT> : <EOL> msg = "<STR_LIT>" % project <EOL> return ( status_code , msg ) <EOL> def unjoin_project ( self , project ) : <EOL> try : <EOL> self . pubsub . unsubscribe ( self . pubsub_addr , project ) <EOL> return ( <NUM_LIT:200> , "<STR_LIT>" % project ) <EOL> except IqError as e : <EOL> status_code = int ( e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:code>' ] ) <EOL> msg = "<STR_LIT>" % project <EOL> if status_code == <NUM_LIT> : <EOL> msg = "<STR_LIT>" % project <EOL> elif status_code == <NUM_LIT> : <EOL> msg = "<STR_LIT>" % project <EOL> return ( status_code , msg ) <EOL> def get_project_users ( self , project ) : <EOL> try : <EOL> ret = self . pubsub . get_node_subscriptions ( self . pubsub_addr , project ) <EOL> return ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> except IqError : <EOL> pass <EOL> def accept_pending ( self , project , user ) : <EOL> self . _allow_pending ( project , user , '<STR_LIT:true>' ) <EOL> return ( <NUM_LIT:200> , "<STR_LIT>" % ( user , <EOL> project ) ) <EOL> def reject ( self , project , user ) : <EOL> self . _allow_pending ( project , user , '<STR_LIT:false>' ) <EOL> return ( <NUM_LIT:200> , "<STR_LIT>" % ( user , <EOL> project ) ) <EOL> def kick ( self , project , user ) : <EOL> subscriptions = [ ( user , '<STR_LIT:none>' ) ] <EOL> try : <EOL> self . pubsub . modify_subscriptions ( self . pubsub_addr , project , <EOL> subscriptions = subscriptions ) <EOL> return ( <NUM_LIT:200> , "<STR_LIT>" % ( user , <EOL> project ) ) <EOL> except IqError as e : <EOL> status_code = int ( e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:code>' ] ) <EOL> msg = "<STR_LIT>" <EOL> if status_code == <NUM_LIT> : <EOL> msg = "<STR_LIT>" <EOL> elif status_code == <NUM_LIT> : <EOL> msg = "<STR_LIT>" % project <EOL> return ( status_code , msg ) <EOL> def first_git_init ( self , project , url ) : <EOL> iq = self . Iq ( sto = self . server_addr , stype = '<STR_LIT>' ) <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT>' ] = project <EOL> iq [ '<STR_LIT>' ] [ '<STR_LIT:url>' ] = url <EOL> try : <EOL> iq . send ( timeout = <NUM_LIT> ) <EOL> return ( <NUM_LIT:200> , "<STR_LIT>" % <EOL> project ) <EOL> except IqError as e : <EOL> status_code = int ( e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:code>' ] ) <EOL> msg = "<STR_LIT>" <EOL> if status_code == <NUM_LIT> : <EOL> msg = e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:text>' ] <EOL> return ( status_code , msg ) <EOL> def _allow_pending ( self , project , user , allow ) : <EOL> """<STR_LIT>""" <EOL> payload = self . form . make_form ( ftype = '<STR_LIT>' ) <EOL> payload . add_field ( var = '<STR_LIT>' , ftype = '<STR_LIT>' , <EOL> value = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> payload . add_field ( var = '<STR_LIT>' , value = '<STR_LIT>' ) <EOL> payload . add_field ( var = '<STR_LIT>' , value = project ) <EOL> payload . add_field ( var = '<STR_LIT>' , value = user ) <EOL> payload . add_field ( var = '<STR_LIT>' , value = allow ) <EOL> message = self . make_message ( self . pubsub_addr ) <EOL> message . appendxml ( payload . xml ) <EOL> message . send ( ) <EOL> class RegisterTransport ( CommonTransport ) : <EOL> def __init__ ( self , callback = None ) : <EOL> super ( RegisterTransport , self ) . __init__ ( ) <EOL> self . callback = callback <EOL> self . register_plugin ( '<STR_LIT>' ) <EOL> self . add_event_handler ( '<STR_LIT>' , self . register ) <EOL> def register ( self , iq ) : <EOL> """<STR_LIT>""" <EOL> resp = self . Iq ( ) <EOL> resp [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> resp [ '<STR_LIT>' ] [ '<STR_LIT:username>' ] = self . boundjid . user <EOL> resp [ '<STR_LIT>' ] [ '<STR_LIT:password>' ] = self . password <EOL> try : <EOL> resp . send ( now = True ) <EOL> if self . callback : <EOL> self . callback ( <NUM_LIT:200> , '<STR_LIT>' % <EOL> config [ '<STR_LIT:user>' ] [ '<STR_LIT>' ] ) <EOL> except IqError as e : <EOL> if self . callback : <EOL> status_code = int ( e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:code>' ] ) <EOL> msg = "<STR_LIT>" <EOL> if status_code == <NUM_LIT> : <EOL> msg = "<STR_LIT>" "<STR_LIT>" <EOL> elif status_code == <NUM_LIT> : <EOL> msg = e . iq [ '<STR_LIT:error>' ] [ '<STR_LIT:text>' ] <EOL> self . callback ( status_code , msg , fatal = True ) <EOL> self . close ( ) </s>
