idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
59,600 | def get_alias ( self ) : alias = None if self . alias : alias = self . alias elif self . auto_alias : alias = self . auto_alias return alias | Gets the alias for the table or the auto_alias if one is set . If there isn t any kind of alias None is returned . |
59,601 | def add_field ( self , field ) : field = FieldFactory ( field , ) field . set_table ( self ) field_name = field . get_name ( ) for existing_field in self . fields : if existing_field . get_name ( ) == field_name : return None self . before_add_field ( field ) field . before_add ( ) if field . ignore is False : self . fields . append ( field ) return field | Adds a field to this table |
59,602 | def remove_field ( self , field ) : new_field = FieldFactory ( field , ) new_field . set_table ( self ) new_field_identifier = new_field . get_identifier ( ) for field in self . fields : if field . get_identifier ( ) == new_field_identifier : self . fields . remove ( field ) return field return None | Removes a field from this table |
59,603 | def add_fields ( self , fields ) : if isinstance ( fields , string_types ) : fields = [ fields ] elif type ( fields ) is tuple : fields = list ( fields ) field_objects = [ self . add_field ( field ) for field in fields ] return field_objects | Adds all of the passed fields to the table s current field list |
59,604 | def find_field ( self , field = None , alias = None ) : if alias : field = alias field = FieldFactory ( field , table = self , alias = alias ) identifier = field . get_identifier ( ) for field in self . fields : if field . get_identifier ( ) == identifier : return field return None | Finds a field by name or alias . |
59,605 | def init_defaults ( self ) : super ( SimpleTable , self ) . init_defaults ( ) self . name = self . table | Sets the name of the table to the passed in table value |
59,606 | def init_defaults ( self ) : super ( ModelTable , self ) . init_defaults ( ) self . model = self . table self . name = self . model . _meta . db_table | Sets a model instance variable to the table value and sets the name to the table name as determined from the model class |
59,607 | def init_defaults ( self ) : super ( QueryTable , self ) . init_defaults ( ) self . query = self . table self . query . is_inner = True | Sets a query instance variable to the table value |
59,608 | def run_command ( cmd_to_run ) : with tempfile . TemporaryFile ( ) as stdout_file , tempfile . TemporaryFile ( ) as stderr_file : popen = subprocess . Popen ( cmd_to_run , stdout = stdout_file , stderr = stderr_file ) popen . wait ( ) stderr_file . seek ( 0 ) stdout_file . seek ( 0 ) stderr = stderr_file . read ( ) stdout = stdout_file . read ( ) if six . PY3 : stderr = stderr . decode ( ) stdout = stdout . decode ( ) return stderr , stdout | Wrapper around subprocess that pipes the stderr and stdout from cmd_to_run to temporary files . Using the temporary files gets around subprocess . PIPE s issues with handling large buffers . |
59,609 | def log ( self , level , prefix = '' ) : logging . log ( level , "%sname: %s" , prefix , self . __name ) logging . log ( level , "%soptions: %s" , prefix , self . __options ) | Writes the contents of the Extension to the logging system . |
59,610 | def specbits ( self ) : bits = [ ] for opt in sorted ( self . __options ) : m = re . match ( r'^! (.*)' , opt ) if m : bits . extend ( [ '!' , "--%s" % m . group ( 1 ) ] ) else : bits . append ( "--%s" % opt ) optval = self . __options [ opt ] if isinstance ( optval , list ) : bits . extend ( optval ) else : bits . append ( optval ) return bits | Returns the array of arguments that would be given to iptables for the current Extension . |
59,611 | def log ( self , level , prefix = '' ) : logging . log ( level , "%sin interface: %s" , prefix , self . in_interface ) logging . log ( level , "%sout interface: %s" , prefix , self . out_interface ) logging . log ( level , "%ssource: %s" , prefix , self . source ) logging . log ( level , "%sdestination: %s" , prefix , self . destination ) logging . log ( level , "%smatches:" , prefix ) for match in self . matches : match . log ( level , prefix + ' ' ) if self . jump : logging . log ( level , "%sjump:" , prefix ) self . jump . log ( level , prefix + ' ' ) | Writes the contents of the Rule to the logging system . |
59,612 | def specbits ( self ) : def host_bits ( opt , optval ) : m = re . match ( r'^!\s*(.*)' , optval ) if m : return [ '!' , opt , m . group ( 1 ) ] else : return [ opt , optval ] bits = [ ] if self . protocol : bits . extend ( host_bits ( '-p' , self . protocol ) ) if self . in_interface : bits . extend ( host_bits ( '-i' , self . in_interface ) ) if self . out_interface : bits . extend ( host_bits ( '-o' , self . out_interface ) ) if self . source : bits . extend ( host_bits ( '-s' , self . source ) ) if self . destination : bits . extend ( host_bits ( '-d' , self . destination ) ) for mod in self . matches : bits . extend ( [ '-m' , mod . name ( ) ] ) bits . extend ( mod . specbits ( ) ) if self . goto : bits . extend ( [ '-g' , self . goto . name ( ) ] ) bits . extend ( self . goto . specbits ( ) ) elif self . jump : bits . extend ( [ '-j' , self . jump . name ( ) ] ) bits . extend ( self . jump . specbits ( ) ) return bits | Returns the array of arguments that would be given to iptables for the current Rule . |
59,613 | def parse_chains ( data ) : chains = odict ( ) for line in data . splitlines ( True ) : m = re_chain . match ( line ) if m : policy = None if m . group ( 2 ) != '-' : policy = m . group ( 2 ) chains [ m . group ( 1 ) ] = { 'policy' : policy , 'packets' : int ( m . group ( 3 ) ) , 'bytes' : int ( m . group ( 4 ) ) , } return chains | Parse the chain definitions . |
59,614 | def parse_rules ( data , chain ) : rules = [ ] for line in data . splitlines ( True ) : m = re_rule . match ( line ) if m and m . group ( 3 ) == chain : rule = parse_rule ( m . group ( 4 ) ) rule . packets = int ( m . group ( 1 ) ) rule . bytes = int ( m . group ( 2 ) ) rules . append ( rule ) return rules | Parse the rules for the specified chain . |
59,615 | def _get_new_connection ( self , conn_params ) : self . __connection_string = conn_params . get ( 'connection_string' , '' ) conn = self . Database . connect ( ** conn_params ) return conn | Opens a connection to the database . |
59,616 | def get_connection_params ( self ) : from django . conf import settings settings_dict = self . settings_dict options = settings_dict . get ( 'OPTIONS' , { } ) autocommit = options . get ( 'autocommit' , False ) conn_params = { 'server' : settings_dict [ 'HOST' ] , 'database' : settings_dict [ 'NAME' ] , 'user' : settings_dict [ 'USER' ] , 'port' : settings_dict . get ( 'PORT' , '1433' ) , 'password' : settings_dict [ 'PASSWORD' ] , 'timeout' : self . command_timeout , 'autocommit' : autocommit , 'use_mars' : options . get ( 'use_mars' , False ) , 'load_balancer' : options . get ( 'load_balancer' , None ) , 'failover_partner' : options . get ( 'failover_partner' , None ) , 'use_tz' : utc if getattr ( settings , 'USE_TZ' , False ) else None , } for opt in _SUPPORTED_OPTIONS : if opt in options : conn_params [ opt ] = options [ opt ] self . tzinfo_factory = utc_tzinfo_factory if settings . USE_TZ else None return conn_params | Returns a dict of parameters suitable for get_new_connection . |
59,617 | def create_cursor ( self , name = None ) : cursor = self . connection . cursor ( ) cursor . tzinfo_factory = self . tzinfo_factory return cursor | Creates a cursor . Assumes that a connection is established . |
59,618 | def __get_dbms_version ( self , make_connection = True ) : major , minor , _ , _ = self . get_server_version ( make_connection = make_connection ) return '{}.{}' . format ( major , minor ) | Returns the DBMS Version string |
59,619 | def get_buffer ( self ) : buffer = [ ] for table in self . __tables : buffer . extend ( table . get_buffer ( ) ) return buffer | Get the change buffers . |
59,620 | def start ( self ) : self . clear ( ) self . setDefaultPolicy ( ) self . acceptIcmp ( ) self . acceptInput ( 'lo' ) | Start the firewall . |
59,621 | def list_rules ( self , chainname ) : data = self . __run ( [ self . __iptables_save , '-t' , self . __name , '-c' ] ) return netfilter . parser . parse_rules ( data , chainname ) | Returns a list of Rules in the specified chain . |
59,622 | def commit ( self ) : while len ( self . __buffer ) > 0 : self . __run ( self . __buffer . pop ( 0 ) ) | Commits any buffered commands . This is only useful if auto_commit is False . |
59,623 | async def numbered_page ( self ) : to_delete = [ ] to_delete . append ( await self . bot . send_message ( self . message . channel , 'What page do you want to go to?' ) ) msg = await self . bot . wait_for_message ( author = self . author , channel = self . message . channel , check = lambda m : m . content . isdigit ( ) , timeout = 30.0 ) if msg is not None : page = int ( msg . content ) to_delete . append ( msg ) if page != 0 and page <= self . maximum_pages : await self . show_page ( page ) else : to_delete . append ( await self . bot . say ( 'Invalid page given. (%s/%s)' % ( page , self . maximum_pages ) ) ) await asyncio . sleep ( 5 ) else : to_delete . append ( await self . bot . send_message ( self . message . channel , 'Took too long.' ) ) await asyncio . sleep ( 5 ) try : await self . bot . delete_messages ( to_delete ) except Exception : pass | lets you type a page number to go to |
59,624 | async def show_help ( self ) : e = discord . Embed ( ) messages = [ 'Welcome to the interactive paginator!\n' ] messages . append ( 'This interactively allows you to see pages of text by navigating with ' 'reactions. They are as follows:\n' ) for ( emoji , func ) in self . reaction_emojis : messages . append ( '%s %s' % ( emoji , func . __doc__ ) ) e . description = '\n' . join ( messages ) e . colour = 0x738bd7 e . set_footer ( text = 'We were on page %s before this message.' % self . current_page ) await self . bot . edit_message ( self . message , embed = e ) async def go_back_to_current_page ( ) : await asyncio . sleep ( 60.0 ) await self . show_current_page ( ) self . bot . loop . create_task ( go_back_to_current_page ( ) ) | shows this message |
59,625 | async def stop_pages ( self ) : await self . bot . delete_message ( self . message ) self . paginating = False | stops the interactive pagination session |
59,626 | async def paginate ( self ) : await self . show_page ( 1 , first = True ) while self . paginating : react = await self . bot . wait_for_reaction ( message = self . message , check = self . react_check , timeout = 120.0 ) if react is None : self . paginating = False try : await self . bot . clear_reactions ( self . message ) except : pass finally : break try : await self . bot . remove_reaction ( self . message , react . reaction . emoji , react . user ) except : pass await self . match ( ) | Actually paginate the entries and run the interactive loop if necessary . |
59,627 | async def _senddms ( self ) : data = self . bot . config . get ( "meta" , { } ) tosend = data . get ( 'send_dms' , True ) data [ 'send_dms' ] = not tosend await self . bot . config . put ( 'meta' , data ) await self . bot . responses . toggle ( message = "Forwarding of DMs to owner has been {status}." , success = data [ 'send_dms' ] ) | Toggles sending DMs to owner . |
59,628 | async def _quit ( self ) : await self . bot . responses . failure ( message = "Bot shutting down" ) await self . bot . logout ( ) | Quits the bot . |
59,629 | async def _setcolor ( self , * , color : discord . Colour ) : data = self . bot . config . get ( "meta" , { } ) data [ 'default_color' ] = str ( color ) await self . bot . config . put ( 'meta' , data ) await self . bot . responses . basic ( message = "The default color has been updated." ) | Sets the default color of embeds . |
59,630 | async def _do ( self , ctx , times : int , * , command ) : msg = copy . copy ( ctx . message ) msg . content = command for i in range ( times ) : await self . bot . process_commands ( msg ) | Repeats a command a specified number of times . |
59,631 | async def disable ( self , ctx , * , command : str ) : command = command . lower ( ) if command in ( 'enable' , 'disable' ) : return await self . bot . responses . failure ( message = 'Cannot disable that command.' ) if command not in self . bot . commands : return await self . bot . responses . failure ( message = 'Command "{}" was not found.' . format ( command ) ) guild_id = ctx . message . server . id cmds = self . config . get ( 'commands' , { } ) entries = cmds . get ( guild_id , [ ] ) entries . append ( command ) cmds [ guild_id ] = entries await self . config . put ( 'commands' , cmds ) await self . bot . responses . success ( message = '"%s" command disabled in this server.' % command ) | Disables a command for this server . |
59,632 | async def enable ( self , ctx , * , command : str ) : command = command . lower ( ) guild_id = ctx . message . server . id cmds = self . config . get ( 'commands' , { } ) entries = cmds . get ( guild_id , [ ] ) try : entries . remove ( command ) except KeyError : await self . bot . responses . failure ( message = 'The command does not exist or is not disabled.' ) else : cmds [ guild_id ] = entries await self . config . put ( 'commands' , cmds ) await self . bot . responses . success ( message = '"%s" command enabled in this server.' % command ) | Enables a command for this server . |
59,633 | async def ignore ( self , ctx ) : if ctx . invoked_subcommand is None : await self . bot . say ( 'Invalid subcommand passed: {0.subcommand_passed}' . format ( ctx ) ) | Handles the bot s ignore lists . |
59,634 | async def ignore_list ( self , ctx ) : ignored = self . config . get ( 'ignored' , [ ] ) channel_ids = set ( c . id for c in ctx . message . server . channels ) result = [ ] for channel in ignored : if channel in channel_ids : result . append ( '<#{}>' . format ( channel ) ) if result : await self . bot . responses . basic ( title = "Ignored Channels:" , message = '\n\n{}' . format ( ', ' . join ( result ) ) ) else : await self . bot . responses . failure ( message = 'I am not ignoring any channels here.' ) | Tells you what channels are currently ignored in this server . |
59,635 | async def channel_cmd ( self , ctx , * , channel : discord . Channel = None ) : if channel is None : channel = ctx . message . channel ignored = self . config . get ( 'ignored' , [ ] ) if channel . id in ignored : await self . bot . responses . failure ( message = 'That channel is already ignored.' ) return ignored . append ( channel . id ) await self . config . put ( 'ignored' , ignored ) await self . bot . responses . success ( message = 'Channel <#{}> will be ignored.' . format ( channel . id ) ) | Ignores a specific channel from being processed . |
59,636 | async def _all ( self , ctx ) : ignored = self . config . get ( 'ignored' , [ ] ) channels = ctx . message . server . channels ignored . extend ( c . id for c in channels if c . type == discord . ChannelType . text ) await self . config . put ( 'ignored' , list ( set ( ignored ) ) ) await self . bot . responses . success ( message = 'All channels ignored.' ) | Ignores every channel in the server from being processed . |
59,637 | async def unignore ( self , ctx , * channels : discord . Channel ) : if len ( channels ) == 0 : channels = ( ctx . message . channel , ) ignored = self . config . get ( 'ignored' , [ ] ) result = [ ] for channel in channels : try : ignored . remove ( channel . id ) except ValueError : pass else : result . append ( '<#{}>' . format ( channel . id ) ) await self . config . put ( 'ignored' , ignored ) await self . bot . responses . success ( message = 'Channel(s) {} will no longer be ignored.' . format ( ', ' . join ( result ) ) ) | Unignores channels from being processed . |
59,638 | async def unignore_all ( self , ctx ) : channels = [ c for c in ctx . message . server . channels if c . type is discord . ChannelType . text ] await ctx . invoke ( self . unignore , * channels ) | Unignores all channels in this server from being processed . |
59,639 | async def cleanup ( self , ctx , search : int = 100 ) : spammers = Counter ( ) channel = ctx . message . channel prefixes = self . bot . command_prefix if callable ( prefixes ) : prefixes = prefixes ( self . bot , ctx . message ) def is_possible_command_invoke ( entry ) : valid_call = any ( entry . content . startswith ( prefix ) for prefix in prefixes ) return valid_call and not entry . content [ 1 : 2 ] . isspace ( ) can_delete = channel . permissions_for ( channel . server . me ) . manage_messages if not can_delete : api_calls = 0 async for entry in self . bot . logs_from ( channel , limit = search , before = ctx . message ) : if api_calls and api_calls % 5 == 0 : await asyncio . sleep ( 1.1 ) if entry . author == self . bot . user : await self . bot . delete_message ( entry ) spammers [ 'Bot' ] += 1 api_calls += 1 if is_possible_command_invoke ( entry ) : try : await self . bot . delete_message ( entry ) except discord . Forbidden : continue else : spammers [ entry . author . display_name ] += 1 api_calls += 1 else : predicate = lambda m : m . author == self . bot . user or is_possible_command_invoke ( m ) deleted = await self . bot . purge_from ( channel , limit = search , before = ctx . message , check = predicate ) spammers = Counter ( m . author . display_name for m in deleted ) deleted = sum ( spammers . values ( ) ) messages = [ '%s %s removed.' % ( deleted , 'message was' if deleted == 1 else 'messages were' ) ] if deleted : messages . append ( '' ) spammers = sorted ( spammers . items ( ) , key = lambda t : t [ 1 ] , reverse = True ) messages . extend ( map ( lambda t : '**{0[0]}**: {0[1]}' . format ( t ) , spammers ) ) msg = await self . bot . responses . basic ( title = "Removed Messages:" , message = '\n' . join ( messages ) ) await asyncio . sleep ( 10 ) await self . bot . delete_message ( msg ) | Cleans up the bot s messages from the channel . |
59,640 | async def plonk ( self , ctx , * , member : discord . Member ) : plonks = self . config . get ( 'plonks' , { } ) guild_id = ctx . message . server . id db = plonks . get ( guild_id , [ ] ) if member . id in db : await self . bot . responses . failure ( message = 'That user is already bot banned in this server.' ) return db . append ( member . id ) plonks [ guild_id ] = db await self . config . put ( 'plonks' , plonks ) await self . bot . responses . success ( message = '%s has been banned from using the bot in this server.' % member ) | Bans a user from using the bot . |
59,641 | async def plonks ( self , ctx ) : plonks = self . config . get ( 'plonks' , { } ) guild = ctx . message . server db = plonks . get ( guild . id , [ ] ) members = '\n' . join ( map ( str , filter ( None , map ( guild . get_member , db ) ) ) ) if members : await self . bot . responses . basic ( title = "Plonked Users:" , message = members ) else : await self . bot . responses . failure ( message = 'No members are banned in this server.' ) | Shows members banned from the bot . |
59,642 | async def unplonk ( self , ctx , * , member : discord . Member ) : plonks = self . config . get ( 'plonks' , { } ) guild_id = ctx . message . server . id db = plonks . get ( guild_id , [ ] ) try : db . remove ( member . id ) except ValueError : await self . bot . responses . failure ( message = '%s is not banned from using the bot in this server.' % member ) else : plonks [ guild_id ] = db await self . config . put ( 'plonks' , plonks ) await self . bot . responses . success ( message = '%s has been unbanned from using the bot in this server.' % member ) | Unbans a user from using the bot . |
59,643 | async def join ( self , ctx ) : perms = discord . Permissions . none ( ) perms . read_messages = True perms . send_messages = True perms . manage_messages = True perms . embed_links = True perms . read_message_history = True perms . attach_files = True perms . add_reactions = True await self . bot . send_message ( ctx . message . author , discord . utils . oauth_url ( self . bot . client_id , perms ) ) | Sends you the bot invite link . |
59,644 | async def info ( self , ctx , * , member : discord . Member = None ) : channel = ctx . message . channel if member is None : member = ctx . message . author e = discord . Embed ( ) roles = [ role . name . replace ( '@' , '@\u200b' ) for role in member . roles ] shared = sum ( 1 for m in self . bot . get_all_members ( ) if m . id == member . id ) voice = member . voice_channel if voice is not None : other_people = len ( voice . voice_members ) - 1 voice_fmt = '{} with {} others' if other_people else '{} by themselves' voice = voice_fmt . format ( voice . name , other_people ) else : voice = 'Not connected.' e . set_author ( name = str ( member ) , icon_url = member . avatar_url or member . default_avatar_url ) e . set_footer ( text = 'Member since' ) . timestamp = member . joined_at e . add_field ( name = 'ID' , value = member . id ) e . add_field ( name = 'Servers' , value = '%s shared' % shared ) e . add_field ( name = 'Voice' , value = voice ) e . add_field ( name = 'Created' , value = member . created_at ) e . add_field ( name = 'Roles' , value = ', ' . join ( roles ) ) e . colour = member . colour if member . avatar : e . set_image ( url = member . avatar_url ) await self . bot . say ( embed = e ) | Shows info about a member . |
59,645 | async def put ( self , key , value , * args ) : self . _db [ key ] = value await self . save ( ) | Edits a data entry . |
59,646 | async def addreaction ( self , ctx , * , reactor = "" ) : if not reactor : await self . bot . say ( "What should I react to?" ) response = await self . bot . wait_for_message ( author = ctx . message . author ) reactor = response . content data = self . config . get ( ctx . message . server . id , { } ) keyword = data . get ( reactor , { } ) if keyword : await self . bot . responses . failure ( message = "Reaction '{}' already exists." . format ( reactor ) ) return await self . bot . say ( "Okay, I'll react to '{}'. What do you want me to say? (Type $none for no response)" . format ( reactor ) ) response = await self . bot . wait_for_message ( author = ctx . message . author ) reactions = [ ] def check ( reaction , user ) : if str ( reaction . emoji ) != "\U000023f9" : reactions . append ( reaction . emoji ) return False else : return user == ctx . message . author msg = await self . bot . say ( "Awesome! Now react to this message any reactions I should have to '{}'. (React \U000023f9 to stop)" . format ( reactor ) ) await self . bot . wait_for_reaction ( message = msg , check = check ) for i , reaction in enumerate ( reactions ) : reaction = reaction if isinstance ( reaction , str ) else reaction . name + ":" + str ( reaction . id ) await self . bot . add_reaction ( ctx . message , reaction ) reactions [ i ] = reaction if response : keyword [ "response" ] = response . content if response . content . lower ( ) != "$none" else "" keyword [ "reaction" ] = reactions data [ reactor ] = keyword await self . config . put ( ctx . message . server . id , data ) await self . bot . responses . success ( message = "Reaction '{}' has been added." . format ( reactor ) ) | Interactively adds a custom reaction |
59,647 | async def listreactions ( self , ctx ) : data = self . config . get ( ctx . message . server . id , { } ) if not data : await self . bot . responses . failure ( message = "There are no reactions on this server." ) return try : pager = Pages ( self . bot , message = ctx . message , entries = list ( data . keys ( ) ) ) pager . embed . colour = 0x738bd7 pager . embed . set_author ( name = ctx . message . server . name + " Reactions" , icon_url = ctx . message . server . icon_url ) await pager . paginate ( ) except Exception as e : await self . bot . say ( e ) | Lists all the reactions for the server |
59,648 | async def viewreaction ( self , ctx , * , reactor : str ) : data = self . config . get ( ctx . message . server . id , { } ) keyword = data . get ( reactor , { } ) if not keyword : await self . bot . responses . failure ( message = "Reaction '{}' was not found." . format ( reactor ) ) return response = data . get ( reactor , { } ) . get ( "response" , "" ) reacts = data . get ( reactor , { } ) . get ( "reaction" , [ ] ) for i , r in enumerate ( reacts ) : if ":" in r : reacts [ i ] = "<:" + r + ">" reacts = " " . join ( reacts ) if reacts else "-" response = response if response else "-" string = "Here's what I say to '{reactor}': {response}\n" "I'll react to this message how I react to '{reactor}'." . format ( reactor = reactor , response = response ) await self . bot . responses . full ( sections = [ { "name" : "Response" , "value" : response } , { "name" : "Reactions" , "value" : reacts , "inline" : False } ] ) | Views a specific reaction |
59,649 | async def _default_help_command ( ctx , * commands : str ) : bot = ctx . bot destination = ctx . message . author if bot . pm_help else ctx . message . channel def repl ( obj ) : return _mentions_transforms . get ( obj . group ( 0 ) , '' ) if len ( commands ) == 0 : pages = bot . formatter . format_help_for ( ctx , bot ) elif len ( commands ) == 1 : name = _mention_pattern . sub ( repl , commands [ 0 ] ) command = None if name in [ x . lower ( ) for x in bot . cogs ] : command = bot . cogs [ [ x for x in bot . cogs if x . lower ( ) == name ] [ 0 ] ] else : command = bot . commands . get ( name ) if command is None : await bot . responses . failure ( destination = destination , message = bot . command_not_found . format ( name ) ) return pages = bot . formatter . format_help_for ( ctx , command ) else : name = _mention_pattern . sub ( repl , commands [ 0 ] ) command = bot . commands . get ( name ) if command is None : await bot . responses . failure ( destination = destination , message = bot . command_not_found . format ( name ) ) return for key in commands [ 1 : ] : try : key = _mention_pattern . sub ( repl , key ) command = command . commands . get ( key ) if command is None : await bot . responses . failure ( destination = destination , message = bot . command_not_found . format ( name ) ) return except AttributeError : await bot . responses . failure ( destination = destination , message = bot . command_has_no_subcommands . format ( command , key ) ) return pages = bot . formatter . format_help_for ( ctx , command ) if bot . pm_help is None : characters = sum ( map ( lambda l : len ( l ) , pages . values ( ) ) ) if characters > 1000 : destination = ctx . message . author await bot . responses . full ( destination = destination , ** pages ) | Shows this message . |
59,650 | def nla_ok ( nla , remaining ) : return remaining . value >= nla . SIZEOF and nla . SIZEOF <= nla . nla_len <= remaining . value | Check if the attribute header and payload can be accessed safely . |
59,651 | def nla_next ( nla , remaining ) : totlen = int ( NLA_ALIGN ( nla . nla_len ) ) remaining . value -= totlen return nlattr ( bytearray_ptr ( nla . bytearray , totlen ) ) | Return next attribute in a stream of attributes . |
59,652 | def nla_parse ( tb , maxtype , head , len_ , policy ) : rem = c_int ( ) for nla in nla_for_each_attr ( head , len_ , rem ) : type_ = nla_type ( nla ) if type_ > maxtype : continue if policy : err = validate_nla ( nla , maxtype , policy ) if err < 0 : return err if type_ in tb and tb [ type_ ] : _LOGGER . debug ( 'Attribute of type %d found multiple times in message, previous attribute is being ignored.' , type_ ) tb [ type_ ] = nla if rem . value > 0 : _LOGGER . debug ( 'netlink: %d bytes leftover after parsing attributes.' , rem . value ) return 0 | Create attribute index based on a stream of attributes . |
59,653 | def nla_for_each_attr ( head , len_ , rem ) : pos = head rem . value = len_ while nla_ok ( pos , rem ) : yield pos pos = nla_next ( pos , rem ) | Iterate over a stream of attributes . |
59,654 | def nla_for_each_nested ( nla , rem ) : pos = nlattr ( nla_data ( nla ) ) rem . value = nla_len ( nla ) while nla_ok ( pos , rem ) : yield pos pos = nla_next ( pos , rem ) | Iterate over a stream of nested attributes . |
59,655 | def nla_find ( head , len_ , attrtype ) : rem = c_int ( ) for nla in nla_for_each_attr ( head , len_ , rem ) : if nla_type ( nla ) == attrtype : return nla return None | Find a single attribute in a stream of attributes . |
59,656 | def nla_reserve ( msg , attrtype , attrlen ) : tlen = NLMSG_ALIGN ( msg . nm_nlh . nlmsg_len ) + nla_total_size ( attrlen ) if tlen > msg . nm_size : return None nla = nlattr ( nlmsg_tail ( msg . nm_nlh ) ) nla . nla_type = attrtype nla . nla_len = nla_attr_size ( attrlen ) if attrlen : padlen = nla_padlen ( attrlen ) nla . bytearray [ nla . nla_len : nla . nla_len + padlen ] = bytearray ( b'\0' ) * padlen msg . nm_nlh . nlmsg_len = tlen _LOGGER . debug ( 'msg 0x%x: attr <0x%x> %d: Reserved %d (%d) bytes at offset +%d nlmsg_len=%d' , id ( msg ) , id ( nla ) , nla . nla_type , nla_total_size ( attrlen ) , attrlen , nla . bytearray . slice . start - nlmsg_data ( msg . nm_nlh ) . slice . start , msg . nm_nlh . nlmsg_len ) return nla | Reserve space for an attribute . |
59,657 | def nla_put ( msg , attrtype , datalen , data ) : nla = nla_reserve ( msg , attrtype , datalen ) if not nla : return - NLE_NOMEM if datalen <= 0 : return 0 nla_data ( nla ) [ : datalen ] = data [ : datalen ] _LOGGER . debug ( 'msg 0x%x: attr <0x%x> %d: Wrote %d bytes at offset +%d' , id ( msg ) , id ( nla ) , nla . nla_type , datalen , nla . bytearray . slice . start - nlmsg_data ( msg . nm_nlh ) . slice . start ) return 0 | Add a unspecific attribute to Netlink message . |
59,658 | def nla_put_data ( msg , attrtype , data ) : return nla_put ( msg , attrtype , len ( data ) , data ) | Add abstract data as unspecific attribute to Netlink message . |
59,659 | def nla_put_u8 ( msg , attrtype , value ) : data = bytearray ( value if isinstance ( value , c_uint8 ) else c_uint8 ( value ) ) return nla_put ( msg , attrtype , SIZEOF_U8 , data ) | Add 8 bit integer attribute to Netlink message . |
59,660 | def nla_put_u16 ( msg , attrtype , value ) : data = bytearray ( value if isinstance ( value , c_uint16 ) else c_uint16 ( value ) ) return nla_put ( msg , attrtype , SIZEOF_U16 , data ) | Add 16 bit integer attribute to Netlink message . |
59,661 | def nla_put_u32 ( msg , attrtype , value ) : data = bytearray ( value if isinstance ( value , c_uint32 ) else c_uint32 ( value ) ) return nla_put ( msg , attrtype , SIZEOF_U32 , data ) | Add 32 bit integer attribute to Netlink message . |
59,662 | def nla_put_u64 ( msg , attrtype , value ) : data = bytearray ( value if isinstance ( value , c_uint64 ) else c_uint64 ( value ) ) return nla_put ( msg , attrtype , SIZEOF_U64 , data ) | Add 64 bit integer attribute to Netlink message . |
59,663 | def nla_put_string ( msg , attrtype , value ) : data = bytearray ( value ) + bytearray ( b'\0' ) return nla_put ( msg , attrtype , len ( data ) , data ) | Add string attribute to Netlink message . |
59,664 | def nla_put_msecs ( msg , attrtype , msecs ) : if isinstance ( msecs , c_uint64 ) : pass elif isinstance ( msecs , c_ulong ) : msecs = c_uint64 ( msecs . value ) else : msecs = c_uint64 ( msecs ) return nla_put_u64 ( msg , attrtype , msecs ) | Add msecs Netlink attribute to Netlink message . |
59,665 | def nla_put_nested ( msg , attrtype , nested ) : _LOGGER . debug ( 'msg 0x%x: attr <> %d: adding msg 0x%x as nested attribute' , id ( msg ) , attrtype , id ( nested ) ) return nla_put ( msg , attrtype , nlmsg_datalen ( nested . nm_nlh ) , nlmsg_data ( nested . nm_nlh ) ) | Add nested attributes to Netlink message . |
59,666 | def nla_parse_nested ( tb , maxtype , nla , policy ) : return nla_parse ( tb , maxtype , nlattr ( nla_data ( nla ) ) , nla_len ( nla ) , policy ) | Create attribute index based on nested attribute . |
59,667 | def genl_send_simple ( sk , family , cmd , version , flags ) : hdr = genlmsghdr ( cmd = cmd , version = version ) return int ( nl_send_simple ( sk , family , flags , hdr , hdr . SIZEOF ) ) | Send a Generic Netlink message consisting only of a header . |
59,668 | def genlmsg_valid_hdr ( nlh , hdrlen ) : if not nlmsg_valid_hdr ( nlh , GENL_HDRLEN ) : return False ghdr = genlmsghdr ( nlmsg_data ( nlh ) ) if genlmsg_len ( ghdr ) < NLMSG_ALIGN ( hdrlen ) : return False return True | Validate Generic Netlink message headers . |
59,669 | def genlmsg_parse ( nlh , hdrlen , tb , maxtype , policy ) : if not genlmsg_valid_hdr ( nlh , hdrlen ) : return - NLE_MSG_TOOSHORT ghdr = genlmsghdr ( nlmsg_data ( nlh ) ) return int ( nla_parse ( tb , maxtype , genlmsg_attrdata ( ghdr , hdrlen ) , genlmsg_attrlen ( ghdr , hdrlen ) , policy ) ) | Parse Generic Netlink message including attributes . |
59,670 | def genlmsg_len ( gnlh ) : nlh = nlmsghdr ( bytearray_ptr ( gnlh . bytearray , - NLMSG_HDRLEN , oob = True ) ) return nlh . nlmsg_len - GENL_HDRLEN - NLMSG_HDRLEN | Return length of message payload including user header . |
59,671 | def genlmsg_put ( msg , port , seq , family , hdrlen , flags , cmd , version ) : hdr = genlmsghdr ( cmd = cmd , version = version ) nlh = nlmsg_put ( msg , port , seq , family , GENL_HDRLEN + hdrlen , flags ) if nlh is None : return None nlmsg_data ( nlh ) [ : hdr . SIZEOF ] = hdr . bytearray [ : hdr . SIZEOF ] _LOGGER . debug ( 'msg 0x%x: Added generic netlink header cmd=%d version=%d' , id ( msg ) , cmd , version ) return bytearray_ptr ( nlmsg_data ( nlh ) , GENL_HDRLEN ) | Add Generic Netlink headers to Netlink message . |
59,672 | def nl_cb_call ( cb , type_ , msg ) : cb . cb_active = type_ ret = cb . cb_set [ type_ ] ( msg , cb . cb_args [ type_ ] ) cb . cb_active = 10 + 1 return int ( ret ) | Call a callback function . |
59,673 | def nl_pad ( self , value ) : self . bytearray [ self . _get_slicers ( 1 ) ] = bytearray ( c_ushort ( value or 0 ) ) | Pad setter . |
59,674 | def nl_groups ( self , value ) : self . bytearray [ self . _get_slicers ( 3 ) ] = bytearray ( c_uint32 ( value or 0 ) ) | Group setter . |
59,675 | def nlmsg_type ( self , value ) : self . bytearray [ self . _get_slicers ( 1 ) ] = bytearray ( c_uint16 ( value or 0 ) ) | Message content setter . |
59,676 | def nlmsg_seq ( self , value ) : self . bytearray [ self . _get_slicers ( 3 ) ] = bytearray ( c_uint32 ( value or 0 ) ) | Sequence setter . |
59,677 | def nl_socket_alloc ( cb = None ) : cb = cb or nl_cb_alloc ( default_cb ) if not cb : return None sk = nl_sock ( ) sk . s_cb = cb sk . s_local . nl_family = getattr ( socket , 'AF_NETLINK' , - 1 ) sk . s_peer . nl_family = getattr ( socket , 'AF_NETLINK' , - 1 ) sk . s_seq_expect = sk . s_seq_next = int ( time . time ( ) ) sk . s_flags = NL_OWN_PORT nl_socket_get_local_port ( sk ) return sk | Allocate new Netlink socket . Does not yet actually open a socket . |
59,678 | def nl_socket_add_memberships ( sk , * group ) : if sk . s_fd == - 1 : return - NLE_BAD_SOCK for grp in group : if not grp : break if grp < 0 : return - NLE_INVAL try : sk . socket_instance . setsockopt ( SOL_NETLINK , NETLINK_ADD_MEMBERSHIP , grp ) except OSError as exc : return - nl_syserr2nlerr ( exc . errno ) return 0 | Join groups . |
59,679 | def nl_socket_drop_memberships ( sk , * group ) : if sk . s_fd == - 1 : return - NLE_BAD_SOCK for grp in group : if not grp : break if grp < 0 : return - NLE_INVAL try : sk . socket_instance . setsockopt ( SOL_NETLINK , NETLINK_DROP_MEMBERSHIP , grp ) except OSError as exc : return - nl_syserr2nlerr ( exc . errno ) return 0 | Leave groups . |
59,680 | def nl_socket_modify_cb ( sk , type_ , kind , func , arg ) : return int ( nl_cb_set ( sk . s_cb , type_ , kind , func , arg ) ) | Modify the callback handler associated with the socket . |
59,681 | def nl_socket_modify_err_cb ( sk , kind , func , arg ) : return int ( nl_cb_err ( sk . s_cb , kind , func , arg ) ) | Modify the error callback handler associated with the socket . |
59,682 | def nl_socket_set_buffer_size ( sk , rxbuf , txbuf ) : rxbuf = 32768 if rxbuf <= 0 else rxbuf txbuf = 32768 if txbuf <= 0 else txbuf if sk . s_fd == - 1 : return - NLE_BAD_SOCK try : sk . socket_instance . setsockopt ( socket . SOL_SOCKET , socket . SO_SNDBUF , txbuf ) except OSError as exc : return - nl_syserr2nlerr ( exc . errno ) try : sk . socket_instance . setsockopt ( socket . SOL_SOCKET , socket . SO_RCVBUF , rxbuf ) except OSError as exc : return - nl_syserr2nlerr ( exc . errno ) sk . s_flags |= NL_SOCK_BUFSIZE_SET return 0 | Set socket buffer size of Netlink socket . |
59,683 | def cmd ( self , value ) : self . bytearray [ self . _get_slicers ( 0 ) ] = bytearray ( c_uint8 ( value or 0 ) ) | Command setter . |
59,684 | def version ( self , value ) : self . bytearray [ self . _get_slicers ( 1 ) ] = bytearray ( c_uint8 ( value or 0 ) ) | Version setter . |
59,685 | def reserved ( self , value ) : self . bytearray [ self . _get_slicers ( 2 ) ] = bytearray ( c_uint16 ( value or 0 ) ) | Reserved setter . |
59,686 | def _get ( out_parsed , in_bss , key , parser_func ) : short_key = key [ 12 : ] . lower ( ) key_integer = getattr ( nl80211 , key ) if in_bss . get ( key_integer ) is None : return dict ( ) data = parser_func ( in_bss [ key_integer ] ) if parser_func == libnl . attr . nla_data : data = data [ : libnl . attr . nla_len ( in_bss [ key_integer ] ) ] out_parsed [ short_key ] = data | Handle calling the parser function to convert bytearray data into Python data types . |
59,687 | def _fetch ( in_parsed , * keys ) : for ie in ( 'information_elements' , 'beacon_ies' ) : target = in_parsed . get ( ie , { } ) for key in keys : target = target . get ( key , { } ) if target : return target return None | Retrieve nested dict data from either information elements or beacon IES dicts . |
59,688 | def nl_cb_alloc ( kind ) : if kind < 0 or kind > NL_CB_KIND_MAX : return None cb = nl_cb ( ) cb . cb_active = NL_CB_TYPE_MAX + 1 for i in range ( NL_CB_TYPE_MAX ) : nl_cb_set ( cb , i , kind , None , None ) nl_cb_err ( cb , kind , None , None ) return cb | Allocate a new callback handle . |
59,689 | def nl_cb_set ( cb , type_ , kind , func , arg ) : if type_ < 0 or type_ > NL_CB_TYPE_MAX or kind < 0 or kind > NL_CB_KIND_MAX : return - NLE_RANGE if kind == NL_CB_CUSTOM : cb . cb_set [ type_ ] = func cb . cb_args [ type_ ] = arg else : cb . cb_set [ type_ ] = cb_def [ type_ ] [ kind ] cb . cb_args [ type_ ] = arg return 0 | Set up a callback . Updates cb in place . |
59,690 | def nl_cb_err ( cb , kind , func , arg ) : if kind < 0 or kind > NL_CB_KIND_MAX : return - NLE_RANGE if kind == NL_CB_CUSTOM : cb . cb_err = func cb . cb_err_arg = arg else : cb . cb_err = cb_err_def [ kind ] cb . cb_err_arg = arg return 0 | Set up an error callback . Updates cb in place . |
59,691 | def ifi_index ( self , value ) : self . bytearray [ self . _get_slicers ( 3 ) ] = bytearray ( c_int ( value or 0 ) ) | Index setter . |
59,692 | def ifi_change ( self , value ) : self . bytearray [ self . _get_slicers ( 5 ) ] = bytearray ( c_uint ( value or 0 ) ) | Change setter . |
59,693 | def _class_factory ( base ) : class ClsPyPy ( base ) : def __repr__ ( self ) : return repr ( base ( super ( ClsPyPy , self ) . value ) ) @ classmethod def from_buffer ( cls , ba ) : try : integer = struct . unpack_from ( getattr ( cls , '_type_' ) , ba ) [ 0 ] except struct . error : len_ = len ( ba ) size = struct . calcsize ( getattr ( cls , '_type_' ) ) if len_ < size : raise ValueError ( 'Buffer size too small ({0} instead of at least {1} bytes)' . format ( len_ , size ) ) raise return cls ( integer ) class ClsPy26 ( base ) : def __repr__ ( self ) : return repr ( base ( super ( ClsPy26 , self ) . value ) ) def __iter__ ( self ) : return iter ( struct . pack ( getattr ( super ( ClsPy26 , self ) , '_type_' ) , super ( ClsPy26 , self ) . value ) ) try : base . from_buffer ( bytearray ( base ( ) ) ) except TypeError : return ClsPy26 except AttributeError : return ClsPyPy except ValueError : return ClsPyPy return base | Create subclasses of ctypes . |
59,694 | def pid ( self , value ) : self . bytearray [ self . _get_slicers ( 0 ) ] = bytearray ( c_int32 ( value or 0 ) ) | Process ID setter . |
59,695 | def uid ( self , value ) : self . bytearray [ self . _get_slicers ( 1 ) ] = bytearray ( c_int32 ( value or 0 ) ) | User ID setter . |
59,696 | def gid ( self , value ) : self . bytearray [ self . _get_slicers ( 2 ) ] = bytearray ( c_int32 ( value or 0 ) ) | Group ID setter . |
59,697 | def put_skeleton_files_on_disk ( metadata_type , where , github_template = None , params = { } ) : api_name = params [ "api_name" ] file_name = github_template [ "file_name" ] template_source = config . connection . get_plugin_client_setting ( 'mm_template_source' , 'joeferraro/MavensMate-Templates/master' ) template_location = config . connection . get_plugin_client_setting ( 'mm_template_location' , 'remote' ) try : if template_location == 'remote' : if 'linux' in sys . platform : template_body = os . popen ( "wget https://raw.githubusercontent.com/{0}/{1}/{2} -q -O -" . format ( template_source , metadata_type , file_name ) ) . read ( ) else : template_body = urllib2 . urlopen ( "https://raw.githubusercontent.com/{0}/{1}/{2}" . format ( template_source , metadata_type , file_name ) ) . read ( ) else : template_body = get_file_as_string ( os . path . join ( template_source , metadata_type , file_name ) ) except : template_body = get_file_as_string ( os . path . join ( config . base_path , config . support_dir , "templates" , "github-local" , metadata_type , file_name ) ) template = env . from_string ( template_body ) file_body = template . render ( params ) metadata_type = get_meta_type_by_name ( metadata_type ) os . makedirs ( "{0}/{1}" . format ( where , metadata_type [ 'directoryName' ] ) ) f = open ( "{0}/{1}/{2}" . format ( where , metadata_type [ 'directoryName' ] , api_name + "." + metadata_type [ 'suffix' ] ) , 'w' ) f . write ( file_body ) f . close ( ) template = env . get_template ( 'meta.html' ) file_body = template . render ( api_name = api_name , sfdc_api_version = SFDC_API_VERSION , meta_type = metadata_type [ 'xmlName' ] ) f = open ( "{0}/{1}/{2}" . format ( where , metadata_type [ 'directoryName' ] , api_name + "." + metadata_type [ 'suffix' ] ) + "-meta.xml" , 'w' ) f . write ( file_body ) f . close ( ) | Generates file based on jinja2 templates |
59,698 | def genl_ctrl_probe_by_name ( sk , name ) : ret = genl_family_alloc ( ) if not ret : return None genl_family_set_name ( ret , name ) msg = nlmsg_alloc ( ) orig = nl_socket_get_cb ( sk ) cb = nl_cb_clone ( orig ) genlmsg_put ( msg , NL_AUTO_PORT , NL_AUTO_SEQ , GENL_ID_CTRL , 0 , 0 , CTRL_CMD_GETFAMILY , 1 ) nla_put_string ( msg , CTRL_ATTR_FAMILY_NAME , name ) nl_cb_set ( cb , NL_CB_VALID , NL_CB_CUSTOM , probe_response , ret ) if nl_send_auto ( sk , msg ) < 0 : return None if nl_recvmsgs ( sk , cb ) < 0 : return None if wait_for_ack ( sk ) < 0 : return None if genl_family_get_id ( ret ) != 0 : return ret | Look up generic Netlink family by family name querying the kernel directly . |
59,699 | def genl_ctrl_resolve ( sk , name ) : family = genl_ctrl_probe_by_name ( sk , name ) if family is None : return - NLE_OBJ_NOTFOUND return int ( genl_family_get_id ( family ) ) | Resolve Generic Netlink family name to numeric identifier . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.