idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
23,800 | async def on_raw_765 ( self , message ) : target , targetmeta = self . _parse_user ( message . params [ 0 ] ) if target not in self . _pending [ 'metadata' ] : return if target in self . users : self . _sync_user ( target , targetmeta ) self . _metadata_queue . remove ( target ) del self . _metadata_info [ target ] future = self . _pending [ 'metadata' ] . pop ( target ) future . set_result ( None ) | Invalid metadata target . |
23,801 | async def connect ( self ) : self . tls_context = None if self . tls : self . tls_context = self . create_tls_context ( ) ( self . reader , self . writer ) = await asyncio . open_connection ( host = self . hostname , port = self . port , local_addr = self . source_address , ssl = self . tls_context , loop = self . eventloop ) | Connect to target . |
23,802 | def create_tls_context ( self ) : tls_context = ssl . SSLContext ( ssl . PROTOCOL_SSLv23 ) if self . tls_certificate_file : tls_context . load_cert_chain ( self . tls_certificate_file , self . tls_certificate_keyfile , password = self . tls_certificate_password ) for opt in [ 'NO_SSLv2' , 'NO_SSLv3' , 'NO_COMPRESSION' , 'NO_TICKET' ] : if hasattr ( ssl , 'OP_' + opt ) : tls_context . options |= getattr ( ssl , 'OP_' + opt ) if self . tls_verify : tls_context . set_servername_callback ( self . verify_tls ) tls_context . set_default_verify_paths ( ) if sys . platform in DEFAULT_CA_PATHS and path . isdir ( DEFAULT_CA_PATHS [ sys . platform ] ) : tls_context . load_verify_locations ( capath = DEFAULT_CA_PATHS [ sys . platform ] ) tls_context . verify_mode = ssl . CERT_REQUIRED tls_context . verify_flags = ssl . VERIFY_CRL_CHECK_CHAIN return tls_context | Transform our regular socket into a TLS socket . |
23,803 | async def disconnect ( self ) : if not self . connected : return self . writer . close ( ) self . reader = None self . writer = None | Disconnect from target . |
23,804 | async def send ( self , data ) : self . writer . write ( data ) await self . writer . drain ( ) | Add data to send queue . |
23,805 | def identifierify ( name ) : name = name . lower ( ) name = re . sub ( '[^a-z0-9]' , '_' , name ) return name | Clean up name so it works for a Python identifier . |
23,806 | async def _register ( self ) : if self . registered : return self . _registration_attempts += 1 self . connection . throttle = False if self . password : await self . rawmsg ( 'PASS' , self . password ) await self . set_nickname ( self . _attempt_nicknames . pop ( 0 ) ) await self . rawmsg ( 'USER' , self . username , '0' , '*' , self . realname ) | Perform IRC connection registration . |
23,807 | async def _registration_completed ( self , message ) : if not self . registered : self . registered = True self . connection . throttle = True target = message . params [ 0 ] fakemsg = self . _create_message ( 'NICK' , target , source = self . nickname ) await self . on_raw_nick ( fakemsg ) | We re connected and registered . Receive proper nickname and emit fake NICK message . |
23,808 | def _has_message ( self ) : sep = protocol . MINIMAL_LINE_SEPARATOR . encode ( self . encoding ) return sep in self . _receive_buffer | Whether or not we have messages available for processing . |
23,809 | async def join ( self , channel , password = None ) : if self . in_channel ( channel ) : raise AlreadyInChannel ( channel ) if password : await self . rawmsg ( 'JOIN' , channel , password ) else : await self . rawmsg ( 'JOIN' , channel ) | Join channel optionally with password . |
23,810 | async def part ( self , channel , message = None ) : if not self . in_channel ( channel ) : raise NotInChannel ( channel ) if message : await self . rawmsg ( 'PART' , channel , message ) else : await self . rawmsg ( 'PART' , channel ) | Leave channel optionally with message . |
23,811 | async def kick ( self , channel , target , reason = None ) : if not self . in_channel ( channel ) : raise NotInChannel ( channel ) if reason : await self . rawmsg ( 'KICK' , channel , target , reason ) else : await self . rawmsg ( 'KICK' , channel , target ) | Kick user from channel . |
23,812 | async def unban ( self , channel , target , range = 0 ) : if target in self . users : host = self . users [ target ] [ 'hostname' ] else : host = target host = self . _format_host_range ( host , range ) mask = self . _format_host_mask ( '*' , '*' , host ) await self . rawmsg ( 'MODE' , channel , '-b' , mask ) | Unban user from channel . Target can be either a user or a host . See ban documentation for the range parameter . |
23,813 | async def kickban ( self , channel , target , reason = None , range = 0 ) : await self . ban ( channel , target , range ) await self . kick ( channel , target , reason ) | Kick and ban user from channel . |
23,814 | async def quit ( self , message = None ) : if message is None : message = self . DEFAULT_QUIT_MESSAGE await self . rawmsg ( 'QUIT' , message ) await self . disconnect ( expected = True ) | Quit network . |
23,815 | async def cycle ( self , channel ) : if not self . in_channel ( channel ) : raise NotInChannel ( channel ) password = self . channels [ channel ] [ 'password' ] await self . part ( channel ) await self . join ( channel , password ) | Rejoin channel . |
23,816 | async def message ( self , target , message ) : hostmask = self . _format_user_mask ( self . nickname ) chunklen = protocol . MESSAGE_LENGTH_LIMIT - len ( '{hostmask} PRIVMSG {target} :' . format ( hostmask = hostmask , target = target ) ) - 25 for line in message . replace ( '\r' , '' ) . split ( '\n' ) : for chunk in chunkify ( line , chunklen ) : await self . rawmsg ( 'PRIVMSG' , target , chunk or ' ' ) | Message channel or user . |
23,817 | async def set_topic ( self , channel , topic ) : if not self . is_channel ( channel ) : raise ValueError ( 'Not a channel: {}' . format ( channel ) ) elif not self . in_channel ( channel ) : raise NotInChannel ( channel ) await self . rawmsg ( 'TOPIC' , channel , topic ) | Set topic on channel . Users should only rely on the topic actually being changed when receiving an on_topic_change callback . |
23,818 | async def on_raw_error ( self , message ) : error = protocol . ServerError ( ' ' . join ( message . params ) ) await self . on_data_error ( error ) | Server encountered an error and will now close the connection . |
23,819 | async def on_raw_invite ( self , message ) : nick , metadata = self . _parse_user ( message . source ) self . _sync_user ( nick , metadata ) target , channel = message . params target , metadata = self . _parse_user ( target ) if self . is_same_nick ( self . nickname , target ) : await self . on_invite ( channel , nick ) else : await self . on_user_invite ( target , channel , nick ) | INVITE command . |
23,820 | async def on_raw_join ( self , message ) : nick , metadata = self . _parse_user ( message . source ) self . _sync_user ( nick , metadata ) channels = message . params [ 0 ] . split ( ',' ) if self . is_same_nick ( self . nickname , nick ) : for channel in channels : if not self . in_channel ( channel ) : self . _create_channel ( channel ) await self . rawmsg ( 'MODE' , channel ) else : for channel in channels : if self . in_channel ( channel ) : self . channels [ channel ] [ 'users' ] . add ( nick ) for channel in channels : await self . on_join ( channel , nick ) | JOIN command . |
23,821 | async def on_raw_kick ( self , message ) : kicker , kickermeta = self . _parse_user ( message . source ) self . _sync_user ( kicker , kickermeta ) if len ( message . params ) > 2 : channels , targets , reason = message . params else : channels , targets = message . params reason = None channels = channels . split ( ',' ) targets = targets . split ( ',' ) for channel , target in itertools . product ( channels , targets ) : target , targetmeta = self . _parse_user ( target ) self . _sync_user ( target , targetmeta ) if self . is_same_nick ( target , self . nickname ) : self . _destroy_channel ( channel ) else : if self . in_channel ( channel ) : self . _destroy_user ( target , channel ) await self . on_kick ( channel , target , kicker , reason ) | KICK command . |
23,822 | async def on_raw_kill ( self , message ) : by , bymeta = self . _parse_user ( message . source ) target , targetmeta = self . _parse_user ( message . params [ 0 ] ) reason = message . params [ 1 ] self . _sync_user ( target , targetmeta ) if by in self . users : self . _sync_user ( by , bymeta ) await self . on_kill ( target , by , reason ) if self . is_same_nick ( self . nickname , target ) : await self . disconnect ( expected = False ) else : self . _destroy_user ( target ) | KILL command . |
23,823 | async def on_raw_mode ( self , message ) : nick , metadata = self . _parse_user ( message . source ) target , modes = message . params [ 0 ] , message . params [ 1 : ] self . _sync_user ( nick , metadata ) if self . is_channel ( target ) : if self . in_channel ( target ) : self . channels [ target ] [ 'modes' ] = self . _parse_channel_modes ( target , modes ) await self . on_mode_change ( target , modes , nick ) else : target , targetmeta = self . _parse_user ( target ) self . _sync_user ( target , targetmeta ) if self . is_same_nick ( self . nickname , nick ) : self . _mode = self . _parse_user_modes ( nick , modes , current = self . _mode ) await self . on_user_mode_change ( modes ) | MODE command . |
23,824 | async def on_raw_nick ( self , message ) : nick , metadata = self . _parse_user ( message . source ) new = message . params [ 0 ] self . _sync_user ( nick , metadata ) if self . is_same_nick ( self . nickname , nick ) : self . nickname = new self . _rename_user ( nick , new ) await self . on_nick_change ( nick , new ) | NICK command . |
23,825 | async def on_raw_notice ( self , message ) : nick , metadata = self . _parse_user ( message . source ) target , message = message . params self . _sync_user ( nick , metadata ) await self . on_notice ( target , nick , message ) if self . is_channel ( target ) : await self . on_channel_notice ( target , nick , message ) else : await self . on_private_notice ( target , nick , message ) | NOTICE command . |
23,826 | async def on_raw_part ( self , message ) : nick , metadata = self . _parse_user ( message . source ) channels = message . params [ 0 ] . split ( ',' ) if len ( message . params ) > 1 : reason = message . params [ 1 ] else : reason = None self . _sync_user ( nick , metadata ) if self . is_same_nick ( self . nickname , nick ) : for channel in channels : if self . in_channel ( channel ) : self . _destroy_channel ( channel ) await self . on_part ( channel , nick , reason ) else : for channel in channels : self . _destroy_user ( nick , channel ) await self . on_part ( channel , nick , reason ) | PART command . |
23,827 | async def on_raw_privmsg ( self , message ) : nick , metadata = self . _parse_user ( message . source ) target , message = message . params self . _sync_user ( nick , metadata ) await self . on_message ( target , nick , message ) if self . is_channel ( target ) : await self . on_channel_message ( target , nick , message ) else : await self . on_private_message ( target , nick , message ) | PRIVMSG command . |
23,828 | async def on_raw_quit ( self , message ) : nick , metadata = self . _parse_user ( message . source ) self . _sync_user ( nick , metadata ) if message . params : reason = message . params [ 0 ] else : reason = None await self . on_quit ( nick , reason ) if not self . is_same_nick ( self . nickname , nick ) : self . _destroy_user ( nick ) elif self . connected : await self . disconnect ( expected = True ) | QUIT command . |
23,829 | async def on_raw_topic ( self , message ) : setter , settermeta = self . _parse_user ( message . source ) target , topic = message . params self . _sync_user ( setter , settermeta ) if self . in_channel ( target ) : self . channels [ target ] [ 'topic' ] = topic self . channels [ target ] [ 'topic_by' ] = setter self . channels [ target ] [ 'topic_set' ] = datetime . datetime . now ( ) await self . on_topic_change ( target , topic , setter ) | TOPIC command . |
23,830 | async def on_raw_004 ( self , message ) : target , hostname , ircd , user_modes , channel_modes = message . params [ : 5 ] self . _channel_modes = set ( channel_modes ) self . _user_modes = set ( user_modes ) | Basic server information . |
23,831 | async def on_raw_301 ( self , message ) : target , nickname , message = message . params info = { 'away' : True , 'away_message' : message } if nickname in self . users : self . _sync_user ( nickname , info ) if nickname in self . _pending [ 'whois' ] : self . _whois_info [ nickname ] . update ( info ) | User is away . |
23,832 | async def on_raw_311 ( self , message ) : target , nickname , username , hostname , _ , realname = message . params info = { 'username' : username , 'hostname' : hostname , 'realname' : realname } self . _sync_user ( nickname , info ) if nickname in self . _pending [ 'whois' ] : self . _whois_info [ nickname ] . update ( info ) | WHOIS user info . |
23,833 | async def on_raw_312 ( self , message ) : target , nickname , server , serverinfo = message . params info = { 'server' : server , 'server_info' : serverinfo } if nickname in self . _pending [ 'whois' ] : self . _whois_info [ nickname ] . update ( info ) if nickname in self . _pending [ 'whowas' ] : self . _whowas_info [ nickname ] . update ( info ) | WHOIS server info . |
23,834 | async def on_raw_313 ( self , message ) : target , nickname = message . params [ : 2 ] info = { 'oper' : True } if nickname in self . _pending [ 'whois' ] : self . _whois_info [ nickname ] . update ( info ) | WHOIS operator info . |
23,835 | async def on_raw_314 ( self , message ) : target , nickname , username , hostname , _ , realname = message . params info = { 'username' : username , 'hostname' : hostname , 'realname' : realname } if nickname in self . _pending [ 'whowas' ] : self . _whowas_info [ nickname ] . update ( info ) | WHOWAS user info . |
23,836 | async def on_raw_317 ( self , message ) : target , nickname , idle_time = message . params [ : 3 ] info = { 'idle' : int ( idle_time ) , } if nickname in self . _pending [ 'whois' ] : self . _whois_info [ nickname ] . update ( info ) | WHOIS idle time . |
23,837 | async def on_raw_319 ( self , message ) : target , nickname , channels = message . params [ : 3 ] channels = { channel . lstrip ( ) for channel in channels . strip ( ) . split ( ' ' ) } info = { 'channels' : channels } if nickname in self . _pending [ 'whois' ] : self . _whois_info [ nickname ] . update ( info ) | WHOIS active channels . |
23,838 | async def on_raw_324 ( self , message ) : target , channel = message . params [ : 2 ] modes = message . params [ 2 : ] if not self . in_channel ( channel ) : return self . channels [ channel ] [ 'modes' ] = self . _parse_channel_modes ( channel , modes ) | Channel mode . |
23,839 | async def on_raw_329 ( self , message ) : target , channel , timestamp = message . params if not self . in_channel ( channel ) : return self . channels [ channel ] [ 'created' ] = datetime . datetime . fromtimestamp ( int ( timestamp ) ) | Channel creation time . |
23,840 | async def on_raw_332 ( self , message ) : target , channel , topic = message . params if not self . in_channel ( channel ) : return self . channels [ channel ] [ 'topic' ] = topic | Current topic on channel join . |
23,841 | async def on_raw_333 ( self , message ) : target , channel , setter , timestamp = message . params if not self . in_channel ( channel ) : return self . channels [ channel ] [ 'topic_by' ] = self . _parse_user ( setter ) [ 0 ] self . channels [ channel ] [ 'topic_set' ] = datetime . datetime . fromtimestamp ( int ( timestamp ) ) | Topic setter and time on channel join . |
23,842 | async def on_raw_375 ( self , message ) : await self . _registration_completed ( message ) self . motd = message . params [ 1 ] + '\n' | Start message of the day . |
23,843 | async def on_raw_422 ( self , message ) : await self . _registration_completed ( message ) self . motd = None await self . on_connect ( ) | MOTD is missing . |
23,844 | async def on_raw_433 ( self , message ) : if not self . registered : self . _registration_attempts += 1 if self . _attempt_nicknames : await self . set_nickname ( self . _attempt_nicknames . pop ( 0 ) ) else : await self . set_nickname ( self . _nicknames [ 0 ] + '_' * ( self . _registration_attempts - len ( self . _nicknames ) ) ) | Nickname in use . |
23,845 | async def connect ( self , hostname = None , port = None , tls = False , ** kwargs ) : if not port : if tls : port = DEFAULT_TLS_PORT else : port = rfc1459 . protocol . DEFAULT_PORT return await super ( ) . connect ( hostname , port , tls = tls , ** kwargs ) | Connect to a server optionally over TLS . See pydle . features . RFC1459Support . connect for misc parameters . |
23,846 | async def _connect ( self , hostname , port , reconnect = False , password = None , encoding = pydle . protocol . DEFAULT_ENCODING , channels = [ ] , tls = False , tls_verify = False , source_address = None ) : self . password = password if not reconnect : self . _autojoin_channels = channels self . connection = connection . Connection ( hostname , port , source_address = source_address , tls = tls , tls_verify = tls_verify , tls_certificate_file = self . tls_client_cert , tls_certificate_keyfile = self . tls_client_cert_key , tls_certificate_password = self . tls_client_cert_password , eventloop = self . eventloop ) self . encoding = encoding await self . connection . connect ( ) | Connect to IRC server optionally over TLS . |
23,847 | def _reset_attributes ( self ) : self . channels = { } self . users = { } self . _receive_buffer = b'' self . _pending = { } self . _handler_top_level = False self . _ping_checker_handle = None self . logger = logging . getLogger ( __name__ ) self . nickname = DEFAULT_NICKNAME self . network = None | Reset attributes . |
23,848 | def _reset_connection_attributes ( self ) : self . connection = None self . encoding = None self . _autojoin_channels = [ ] self . _reconnect_attempts = 0 | Reset connection attributes . |
23,849 | def run ( self , * args , ** kwargs ) : self . eventloop . run_until_complete ( self . connect ( * args , ** kwargs ) ) try : self . eventloop . run_forever ( ) finally : self . eventloop . stop ( ) | Connect and run bot in event loop . |
23,850 | async def connect ( self , hostname = None , port = None , reconnect = False , ** kwargs ) : if ( not hostname or not port ) and not reconnect : raise ValueError ( 'Have to specify hostname and port if not reconnecting.' ) if self . connected : await self . disconnect ( expected = True ) if not reconnect : self . _reset_connection_attributes ( ) await self . _connect ( hostname = hostname , port = port , reconnect = reconnect , ** kwargs ) if self . server_tag : self . logger = logging . getLogger ( self . __class__ . __name__ + ':' + self . server_tag ) self . eventloop . create_task ( self . handle_forever ( ) ) | Connect to IRC server . |
23,851 | async def _connect ( self , hostname , port , reconnect = False , channels = [ ] , encoding = protocol . DEFAULT_ENCODING , source_address = None ) : if not reconnect or not self . connection : self . _autojoin_channels = channels self . connection = connection . Connection ( hostname , port , source_address = source_address , eventloop = self . eventloop ) self . encoding = encoding await self . connection . connect ( ) | Connect to IRC host . |
23,852 | def _reconnect_delay ( self ) : if self . RECONNECT_ON_ERROR and self . RECONNECT_DELAYED : if self . _reconnect_attempts >= len ( self . RECONNECT_DELAYS ) : return self . RECONNECT_DELAYS [ - 1 ] else : return self . RECONNECT_DELAYS [ self . _reconnect_attempts ] else : return 0 | Calculate reconnection delay . |
23,853 | async def _perform_ping_timeout ( self , delay : int ) : await sleep ( delay ) error = TimeoutError ( 'Ping timeout: no data received from server in {timeout} seconds.' . format ( timeout = self . PING_TIMEOUT ) ) await self . on_data_error ( error ) | Handle timeout gracefully . |
23,854 | async def rawmsg ( self , command , * args , ** kwargs ) : message = str ( self . _create_message ( command , * args , ** kwargs ) ) await self . _send ( message ) | Send raw message . |
23,855 | async def handle_forever ( self ) : while self . connected : data = await self . connection . recv ( ) if not data : if self . connected : await self . disconnect ( expected = False ) break await self . on_data ( data ) | Handle data forever . |
23,856 | async def on_data_error ( self , exception ) : self . logger . error ( 'Encountered error on socket.' , exc_info = ( type ( exception ) , exception , None ) ) await self . disconnect ( expected = False ) | Handle error . |
23,857 | async def on_raw ( self , message ) : self . logger . debug ( '<< %s' , message . _raw ) if not message . _valid : self . logger . warning ( 'Encountered strictly invalid IRC message from server: %s' , message . _raw ) if isinstance ( message . command , int ) : cmd = str ( message . command ) . zfill ( 3 ) else : cmd = message . command method = 'on_raw_' + cmd . lower ( ) try : self . _handler_top_level = True handler = getattr ( self , method ) self . _handler_top_level = False await handler ( message ) except : self . logger . exception ( 'Failed to execute %s handler.' , method ) | Handle a single message . |
23,858 | async def on_unknown ( self , message ) : self . logger . warning ( 'Unknown command: [%s] %s %s' , message . source , message . command , message . params ) | Unknown command . |
23,859 | def connect ( self , client : BasicClient , * args , ** kwargs ) : self . clients . add ( client ) self . connect_args [ client ] = ( args , kwargs ) client . eventloop = self . eventloop | Add client to pool . |
23,860 | def disconnect ( self , client ) : self . clients . remove ( client ) del self . connect_args [ client ] client . disconnect ( ) | Remove client from pool . |
23,861 | def normalize ( input , case_mapping = protocol . DEFAULT_CASE_MAPPING ) : if case_mapping not in protocol . CASE_MAPPINGS : raise pydle . protocol . ProtocolViolation ( 'Unknown case mapping ({})' . format ( case_mapping ) ) input = input . lower ( ) if case_mapping in ( 'rfc1459' , 'rfc1459-strict' ) : input = input . replace ( '{' , '[' ) . replace ( '}' , ']' ) . replace ( '|' , '\\' ) if case_mapping == 'rfc1459' : input = input . replace ( '~' , '^' ) return input | Normalize input according to case mapping . |
23,862 | def parse_user ( raw ) : nick = raw user = None host = None if protocol . HOST_SEPARATOR in raw : raw , host = raw . split ( protocol . HOST_SEPARATOR ) if protocol . USER_SEPARATOR in raw : nick , user = raw . split ( protocol . USER_SEPARATOR ) return nick , user , host | Parse nick ( !user ( |
23,863 | def parse ( cls , line , encoding = pydle . protocol . DEFAULT_ENCODING ) : valid = True try : message = line . decode ( encoding ) except UnicodeDecodeError : message = line . decode ( pydle . protocol . FALLBACK_ENCODING ) if len ( message ) > protocol . MESSAGE_LENGTH_LIMIT : valid = False if message . endswith ( protocol . LINE_SEPARATOR ) : message = message [ : - len ( protocol . LINE_SEPARATOR ) ] elif message . endswith ( protocol . MINIMAL_LINE_SEPARATOR ) : message = message [ : - len ( protocol . MINIMAL_LINE_SEPARATOR ) ] if any ( ch in message for ch in protocol . FORBIDDEN_CHARACTERS ) : valid = False if message . startswith ( ':' ) : parts = protocol . ARGUMENT_SEPARATOR . split ( message [ 1 : ] , 2 ) else : parts = [ None ] + protocol . ARGUMENT_SEPARATOR . split ( message , 1 ) if len ( parts ) == 3 : source , command , raw_params = parts elif len ( parts ) == 2 : source , command = parts raw_params = '' else : raise pydle . protocol . ProtocolViolation ( 'Improper IRC message format: not enough elements.' , message = message ) if not protocol . COMMAND_PATTERN . match ( command ) : valid = False if raw_params . startswith ( protocol . TRAILING_PREFIX ) : params = [ raw_params [ len ( protocol . TRAILING_PREFIX ) : ] ] elif ' ' + protocol . TRAILING_PREFIX in raw_params : index = raw_params . find ( ' ' + protocol . TRAILING_PREFIX ) params = protocol . ARGUMENT_SEPARATOR . split ( raw_params [ : index ] . rstrip ( ' ' ) ) params . append ( raw_params [ index + len ( protocol . TRAILING_PREFIX ) + 1 : ] ) elif raw_params : params = protocol . ARGUMENT_SEPARATOR . split ( raw_params ) else : params = [ ] try : command = int ( command ) except ValueError : command = command . upper ( ) return RFC1459Message ( command , params , source = source , _valid = valid , _raw = message ) | Parse given line into IRC message structure . Returns a Message . |
23,864 | def construct ( self , force = False ) : command = str ( self . command ) if not protocol . COMMAND_PATTERN . match ( command ) and not force : raise pydle . protocol . ProtocolViolation ( 'The constructed command does not follow the command pattern ({pat})' . format ( pat = protocol . COMMAND_PATTERN . pattern ) , message = command ) message = command . upper ( ) if not self . params : message += ' ' for idx , param in enumerate ( self . params ) : if not param or ' ' in param or param [ 0 ] == ':' : if idx + 1 < len ( self . params ) and not force : raise pydle . protocol . ProtocolViolation ( 'Only the final parameter of an IRC message can be trailing and thus contain spaces, or start with a colon.' , message = param ) message += ' ' + protocol . TRAILING_PREFIX + param else : message += ' ' + param if self . source : message = ':' + self . source + ' ' + message if any ( ch in message for ch in protocol . FORBIDDEN_CHARACTERS ) and not force : raise pydle . protocol . ProtocolViolation ( 'The constructed message contains forbidden characters ({chs}).' . format ( chs = ', ' . join ( protocol . FORBIDDEN_CHARACTERS ) ) , message = message ) message += protocol . LINE_SEPARATOR if len ( message ) > protocol . MESSAGE_LENGTH_LIMIT and not force : raise pydle . protocol . ProtocolViolation ( 'The constructed message is too long. ({len} > {maxlen})' . format ( len = len ( message ) , maxlen = protocol . MESSAGE_LENGTH_LIMIT ) , message = message ) return message | Construct a raw IRC message . |
23,865 | def featurize ( * features ) : from functools import cmp_to_key def compare_subclass ( left , right ) : if issubclass ( left , right ) : return - 1 elif issubclass ( right , left ) : return 1 return 0 sorted_features = sorted ( features , key = cmp_to_key ( compare_subclass ) ) name = 'FeaturizedClient[{features}]' . format ( features = ', ' . join ( feature . __name__ for feature in sorted_features ) ) return type ( name , tuple ( sorted_features ) , { } ) | Put features into proper MRO order . |
23,866 | async def on_raw_join ( self , message ) : await super ( ) . on_raw_join ( message ) nick , metadata = self . _parse_user ( message . source ) channels = message . params [ 0 ] . split ( ',' ) if self . is_same_nick ( self . nickname , nick ) : if 'WHOX' in self . _isupport and self . _isupport [ 'WHOX' ] : await self . rawmsg ( 'WHO' , ',' . join ( channels ) , '%tnurha,{id}' . format ( id = WHOX_IDENTIFIER ) ) else : pass | Override JOIN to send WHOX . |
23,867 | async def on_raw_354 ( self , message ) : target , identifier = message . params [ : 2 ] if identifier != WHOX_IDENTIFIER : return metadata = { 'nickname' : message . params [ 4 ] , 'username' : message . params [ 2 ] , 'realname' : message . params [ 6 ] , 'hostname' : message . params [ 3 ] , } if message . params [ 5 ] != NO_ACCOUNT : metadata [ 'identified' ] = True metadata [ 'account' ] = message . params [ 5 ] self . _sync_user ( metadata [ 'nickname' ] , metadata ) | WHOX results have arrived . |
23,868 | def _create_channel ( self , channel ) : super ( ) . _create_channel ( channel ) if 'EXCEPTS' in self . _isupport : self . channels [ channel ] [ 'exceptlist' ] = None if 'INVEX' in self . _isupport : self . channels [ channel ] [ 'inviteexceptlist' ] = None | Create channel with optional ban and invite exception lists . |
23,869 | async def on_raw_005 ( self , message ) : isupport = { } for feature in message . params [ 1 : - 1 ] : if feature . startswith ( FEATURE_DISABLED_PREFIX ) : value = False elif '=' in feature : feature , value = feature . split ( '=' , 1 ) else : value = True isupport [ feature . upper ( ) ] = value self . _isupport . update ( isupport ) for entry , value in isupport . items ( ) : if value != False : if value == True : value = None method = 'on_isupport_' + pydle . protocol . identifierify ( entry ) if hasattr ( self , method ) : await getattr ( self , method ) ( value ) | ISUPPORT indication . |
23,870 | async def on_isupport_casemapping ( self , value ) : if value in rfc1459 . protocol . CASE_MAPPINGS : self . _case_mapping = value self . channels = rfc1459 . parsing . NormalizingDict ( self . channels , case_mapping = value ) self . users = rfc1459 . parsing . NormalizingDict ( self . users , case_mapping = value ) | IRC case mapping for nickname and channel name comparisons . |
23,871 | async def on_isupport_chanlimit ( self , value ) : self . _channel_limits = { } for entry in value . split ( ',' ) : types , limit = entry . split ( ':' ) self . _channel_limits [ frozenset ( types ) ] = int ( limit ) for prefix in types : self . _channel_limit_groups [ prefix ] = frozenset ( types ) | Simultaneous channel limits for user . |
23,872 | async def on_isupport_chanmodes ( self , value ) : list , param , param_set , noparams = [ set ( modes ) for modes in value . split ( ',' ) [ : 4 ] ] self . _channel_modes . update ( set ( value . replace ( ',' , '' ) ) ) if not rfc1459 . protocol . BEHAVIOUR_LIST in self . _channel_modes_behaviour : self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_LIST ] = set ( ) self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_LIST ] . update ( list ) if not rfc1459 . protocol . BEHAVIOUR_PARAMETER in self . _channel_modes_behaviour : self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_PARAMETER ] = set ( ) self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_PARAMETER ] . update ( param ) if not rfc1459 . protocol . BEHAVIOUR_PARAMETER_ON_SET in self . _channel_modes_behaviour : self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_PARAMETER_ON_SET ] = set ( ) self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_PARAMETER_ON_SET ] . update ( param_set ) if not rfc1459 . protocol . BEHAVIOUR_NO_PARAMETER in self . _channel_modes_behaviour : self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_NO_PARAMETER ] = set ( ) self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_NO_PARAMETER ] . update ( noparams ) | Valid channel modes and their behaviour . |
23,873 | async def on_isupport_excepts ( self , value ) : if not value : value = BAN_EXCEPT_MODE self . _channel_modes . add ( value ) self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_LIST ] . add ( value ) | Server allows ban exceptions . |
23,874 | async def on_isupport_extban ( self , value ) : self . _extban_prefix , types = value . split ( ',' ) self . _extban_types = set ( types ) | Extended ban prefixes . |
23,875 | async def on_isupport_invex ( self , value ) : if not value : value = INVITE_EXCEPT_MODE self . _channel_modes . add ( value ) self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_LIST ] . add ( value ) | Server allows invite exceptions . |
23,876 | async def on_isupport_maxbans ( self , value ) : if 'MAXLIST' not in self . _isupport : if not self . _list_limits : self . _list_limits = { } self . _list_limits [ 'b' ] = int ( value ) | Maximum entries in ban list . Replaced by MAXLIST . |
23,877 | async def on_isupport_maxchannels ( self , value ) : if 'CHANTYPES' in self . _isupport and 'CHANLIMIT' not in self . _isupport : self . _channel_limits = { } prefixes = self . _isupport [ 'CHANTYPES' ] self . _channel_limits [ frozenset ( prefixes ) ] = int ( value ) for prefix in prefixes : self . _channel_limit_groups [ prefix ] = frozenset ( prefixes ) | Old version of CHANLIMIT . |
23,878 | async def on_isupport_maxlist ( self , value ) : self . _list_limits = { } for entry in value . split ( ',' ) : modes , limit = entry . split ( ':' ) self . _list_limits [ frozenset ( modes ) ] = int ( limit ) for mode in modes : self . _list_limit_groups [ mode ] = frozenset ( modes ) | Limits on channel modes involving lists . |
23,879 | async def on_isupport_prefix ( self , value ) : if not value : self . _nickname_prefixes = collections . OrderedDict ( ) return modes , prefixes = value . lstrip ( '(' ) . split ( ')' , 1 ) self . _channel_modes . update ( set ( modes ) ) if not rfc1459 . protocol . BEHAVIOUR_PARAMETER in self . _channel_modes_behaviour : self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_PARAMETER ] = set ( ) self . _channel_modes_behaviour [ rfc1459 . protocol . BEHAVIOUR_PARAMETER ] . update ( set ( modes ) ) self . _nickname_prefixes = collections . OrderedDict ( ) for mode , prefix in zip ( modes , prefixes ) : self . _nickname_prefixes [ prefix ] = mode | Nickname prefixes on channels and their associated modes . |
23,880 | async def on_isupport_targmax ( self , value ) : if not value : return for entry in value . split ( ',' ) : command , limit = entry . split ( ':' , 1 ) if not limit : continue self . _target_limits [ command ] = int ( limit ) | The maximum number of targets certain types of commands can affect . |
23,881 | async def on_isupport_wallchops ( self , value ) : for prefix , mode in self . _nickname_prefixes . items ( ) : if mode == 'o' : break else : prefix = '@' self . _status_message_prefixes . add ( prefix ) | Support for messaging every opped member or higher on a channel . Replaced by STATUSMSG . |
23,882 | def parse ( cls , line , encoding = pydle . protocol . DEFAULT_ENCODING ) : valid = True try : message = line . decode ( encoding ) except UnicodeDecodeError : message = line . decode ( pydle . protocol . FALLBACK_ENCODING ) if len ( message ) > TAGGED_MESSAGE_LENGTH_LIMIT : valid = False if message . endswith ( rfc1459 . protocol . LINE_SEPARATOR ) : message = message [ : - len ( rfc1459 . protocol . LINE_SEPARATOR ) ] elif message . endswith ( rfc1459 . protocol . MINIMAL_LINE_SEPARATOR ) : message = message [ : - len ( rfc1459 . protocol . MINIMAL_LINE_SEPARATOR ) ] raw = message tags = { } if message . startswith ( TAG_INDICATOR ) : message = message [ len ( TAG_INDICATOR ) : ] raw_tags , message = message . split ( ' ' , 1 ) for raw_tag in raw_tags . split ( TAG_SEPARATOR ) : if TAG_VALUE_SEPARATOR in raw_tag : tag , value = raw_tag . split ( TAG_VALUE_SEPARATOR , 1 ) else : tag = raw_tag value = True tags [ tag ] = value message = super ( ) . parse ( message . lstrip ( ) . encode ( encoding ) , encoding = encoding ) return TaggedMessage ( _raw = raw , _valid = message . _valid and valid , tags = tags , ** message . _kw ) | Parse given line into IRC message structure . Returns a TaggedMessage . |
23,883 | def construct ( self , force = False ) : message = super ( ) . construct ( force = force ) if self . tags : raw_tags = [ ] for tag , value in self . tags . items ( ) : if value == True : raw_tags . append ( tag ) else : raw_tags . append ( tag + TAG_VALUE_SEPARATOR + value ) message = TAG_INDICATOR + TAG_SEPARATOR . join ( raw_tags ) + ' ' + message if len ( message ) > TAGGED_MESSAGE_LENGTH_LIMIT and not force : raise protocol . ProtocolViolation ( 'The constructed message is too long. ({len} > {maxlen})' . format ( len = len ( message ) , maxlen = TAGGED_MESSAGE_LENGTH_LIMIT ) , message = message ) return message | Construct raw IRC message and return it . |
23,884 | def _get_public_suffix_list ( ) : local_psl = os . environ . get ( 'PUBLIC_SUFFIX_LIST' ) if local_psl : with codecs . open ( local_psl , 'r' , 'utf-8' ) as f : psl_raw = f . readlines ( ) else : psl_raw = unicode ( urlopen ( PSL_URL ) . read ( ) , 'utf-8' ) . split ( '\n' ) psl = set ( ) for line in psl_raw : item = line . strip ( ) if item != '' and not item . startswith ( '//' ) : psl . add ( item ) return psl | Return a set containing all Public Suffixes . |
23,885 | def normalize ( url ) : url = url . strip ( ) if url == '' : return '' parts = split ( url ) if parts . scheme : netloc = parts . netloc if parts . scheme in SCHEMES : path = normalize_path ( parts . path ) else : path = parts . path else : netloc = parts . path path = '' if '/' in netloc : netloc , path_raw = netloc . split ( '/' , 1 ) path = normalize_path ( '/' + path_raw ) username , password , host , port = split_netloc ( netloc ) host = normalize_host ( host ) port = _normalize_port ( parts . scheme , port ) query = normalize_query ( parts . query ) fragment = normalize_fragment ( parts . fragment ) return construct ( URL ( parts . scheme , username , password , None , host , None , port , path , query , fragment , None ) ) | Normalize a URL . |
23,886 | def _encode_query ( query ) : if query == '' : return query query_args = [ ] for query_kv in query . split ( '&' ) : k , v = query_kv . split ( '=' ) query_args . append ( k + "=" + quote ( v . encode ( 'utf-8' ) ) ) return '&' . join ( query_args ) | Quote all values of a query string . |
23,887 | def encode ( url ) : parts = extract ( url ) return construct ( URL ( parts . scheme , parts . username , parts . password , _idna_encode ( parts . subdomain ) , _idna_encode ( parts . domain ) , _idna_encode ( parts . tld ) , parts . port , quote ( parts . path . encode ( 'utf-8' ) ) , _encode_query ( parts . query ) , quote ( parts . fragment . encode ( 'utf-8' ) ) , None ) ) | Encode URL . |
23,888 | def construct ( parts ) : url = '' if parts . scheme : if parts . scheme in SCHEMES : url += parts . scheme + '://' else : url += parts . scheme + ':' if parts . username and parts . password : url += parts . username + ':' + parts . password + '@' elif parts . username : url += parts . username + '@' if parts . subdomain : url += parts . subdomain + '.' url += parts . domain if parts . tld : url += '.' + parts . tld if parts . port : url += ':' + parts . port if parts . path : url += parts . path if parts . query : url += '?' + parts . query if parts . fragment : url += '#' + parts . fragment return url | Construct a new URL from parts . |
23,889 | def _normalize_port ( scheme , port ) : if not scheme : return port if port and port != DEFAULT_PORT [ scheme ] : return port | Return port if it is not default port else None . |
23,890 | def unquote ( text , exceptions = [ ] ) : if not text : if text is None : raise TypeError ( 'None object cannot be unquoted' ) else : return text if '%' not in text : return text s = text . split ( '%' ) res = [ s [ 0 ] ] for h in s [ 1 : ] : c = _hextochr . get ( h [ : 2 ] ) if c and c not in exceptions : if len ( h ) > 2 : res . append ( c + h [ 2 : ] ) else : res . append ( c ) else : res . append ( '%' + h ) return '' . join ( res ) | Unquote a text but ignore the exceptions . |
23,891 | def split ( url ) : scheme = netloc = path = query = fragment = '' ip6_start = url . find ( '[' ) scheme_end = url . find ( ':' ) if ip6_start > 0 and ip6_start < scheme_end : scheme_end = - 1 if scheme_end > 0 : for c in url [ : scheme_end ] : if c not in SCHEME_CHARS : break else : scheme = url [ : scheme_end ] . lower ( ) rest = url [ scheme_end : ] . lstrip ( ':/' ) if not scheme : rest = url l_path = rest . find ( '/' ) l_query = rest . find ( '?' ) l_frag = rest . find ( '#' ) if l_path > 0 : if l_query > 0 and l_frag > 0 : netloc = rest [ : l_path ] path = rest [ l_path : min ( l_query , l_frag ) ] elif l_query > 0 : if l_query > l_path : netloc = rest [ : l_path ] path = rest [ l_path : l_query ] else : netloc = rest [ : l_query ] path = '' elif l_frag > 0 : netloc = rest [ : l_path ] path = rest [ l_path : l_frag ] else : netloc = rest [ : l_path ] path = rest [ l_path : ] else : if l_query > 0 : netloc = rest [ : l_query ] elif l_frag > 0 : netloc = rest [ : l_frag ] else : netloc = rest if l_query > 0 : if l_frag > 0 : query = rest [ l_query + 1 : l_frag ] else : query = rest [ l_query + 1 : ] if l_frag > 0 : fragment = rest [ l_frag + 1 : ] if not scheme : path = netloc + path netloc = '' return SplitResult ( scheme , netloc , path , query , fragment ) | Split URL into scheme netloc path query and fragment . |
23,892 | def split_netloc ( netloc ) : username = password = host = port = '' if '@' in netloc : user_pw , netloc = netloc . split ( '@' , 1 ) if ':' in user_pw : username , password = user_pw . split ( ':' , 1 ) else : username = user_pw netloc = _clean_netloc ( netloc ) if ':' in netloc and netloc [ - 1 ] != ']' : host , port = netloc . rsplit ( ':' , 1 ) else : host = netloc return username , password , host , port | Split netloc into username password host and port . |
23,893 | def split_host ( host ) : if '[' in host : return '' , host , '' for c in host : if c not in IP_CHARS : break else : return '' , host , '' domain = subdomain = tld = '' parts = host . split ( '.' ) for i in range ( len ( parts ) ) : tld = '.' . join ( parts [ i : ] ) wildcard_tld = '*.' + tld exception_tld = '!' + tld if exception_tld in PSL : domain = '.' . join ( parts [ : i + 1 ] ) tld = '.' . join ( parts [ i + 1 : ] ) break if tld in PSL : domain = '.' . join ( parts [ : i ] ) break if wildcard_tld in PSL : domain = '.' . join ( parts [ : i - 1 ] ) tld = '.' . join ( parts [ i - 1 : ] ) break if '.' in domain : subdomain , domain = domain . rsplit ( '.' , 1 ) return subdomain , domain , tld | Use the Public Suffix List to split host into subdomain domain and tld . |
23,894 | def connection_made ( self , transport ) : self . transport = transport self . loop = transport . loop self . _cmd_lock = asyncio . Lock ( loop = self . loop ) self . _wd_lock = asyncio . Lock ( loop = self . loop ) self . _cmdq = asyncio . Queue ( loop = self . loop ) self . _msgq = asyncio . Queue ( loop = self . loop ) self . _updateq = asyncio . Queue ( loop = self . loop ) self . _readbuf = b'' self . _update_cb = None self . _received_lines = 0 self . _msg_task = self . loop . create_task ( self . _process_msgs ( ) ) self . _report_task = None self . _watchdog_task = None self . status = { } self . connected = True | Gets called when a connection to the gateway is established . Initialise the protocol object . |
23,895 | def connection_lost ( self , exc ) : _LOGGER . error ( "Disconnected: %s" , exc ) self . connected = False self . transport . close ( ) if self . _report_task is not None : self . _report_task . cancel ( ) self . _msg_task . cancel ( ) for q in [ self . _cmdq , self . _updateq , self . _msgq ] : while not q . empty ( ) : q . get_nowait ( ) self . status = { } | Gets called when the connection to the gateway is lost . Tear down and clean up the protocol object . |
23,896 | async def setup_watchdog ( self , cb , timeout ) : self . _watchdog_timeout = timeout self . _watchdog_cb = cb self . _watchdog_task = self . loop . create_task ( self . _watchdog ( timeout ) ) | Trigger a reconnect after |
23,897 | async def cancel_watchdog ( self ) : if self . _watchdog_task is not None : _LOGGER . debug ( "Canceling Watchdog task." ) self . _watchdog_task . cancel ( ) try : await self . _watchdog_task except asyncio . CancelledError : self . _watchdog_task = None | Cancel the watchdog task and related variables . |
23,898 | async def _inform_watchdog ( self ) : async with self . _wd_lock : if self . _watchdog_task is None : return self . _watchdog_task . cancel ( ) try : await self . _watchdog_task except asyncio . CancelledError : self . _watchdog_task = self . loop . create_task ( self . _watchdog ( self . _watchdog_timeout ) ) | Inform the watchdog of activity . |
23,899 | async def _watchdog ( self , timeout ) : await asyncio . sleep ( timeout , loop = self . loop ) _LOGGER . debug ( "Watchdog triggered!" ) await self . cancel_watchdog ( ) await self . _watchdog_cb ( ) | Trigger and cancel the watchdog after timeout . Call callback . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.