idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
59,700 | def genl_ctrl_resolve_grp ( sk , family_name , grp_name ) : family = genl_ctrl_probe_by_name ( sk , family_name ) if family is None : return - NLE_OBJ_NOTFOUND return genl_ctrl_grp_by_name ( family , grp_name ) | Resolve Generic Netlink family group name . |
59,701 | def _safe_read ( path , length ) : if not os . path . exists ( os . path . join ( HERE , path ) ) : return '' file_handle = codecs . open ( os . path . join ( HERE , path ) , encoding = 'utf-8' ) contents = file_handle . read ( length ) file_handle . close ( ) return contents | Read file contents . |
59,702 | def error_handler ( _ , err , arg ) : arg . value = err . error return libnl . handlers . NL_STOP | Update the mutable integer arg with the error code . |
59,703 | def callback_trigger ( msg , arg ) : gnlh = genlmsghdr ( nlmsg_data ( nlmsg_hdr ( msg ) ) ) if gnlh . cmd == nl80211 . NL80211_CMD_SCAN_ABORTED : arg . value = 1 elif gnlh . cmd == nl80211 . NL80211_CMD_NEW_SCAN_RESULTS : arg . value = 0 return libnl . handlers . NL_SKIP | Called when the kernel is done scanning . Only signals if it was successful or if it failed . No other data . |
59,704 | def callback_dump ( msg , results ) : bss = dict ( ) gnlh = genlmsghdr ( nlmsg_data ( nlmsg_hdr ( msg ) ) ) tb = dict ( ( i , None ) for i in range ( nl80211 . NL80211_ATTR_MAX + 1 ) ) nla_parse ( tb , nl80211 . NL80211_ATTR_MAX , genlmsg_attrdata ( gnlh , 0 ) , genlmsg_attrlen ( gnlh , 0 ) , None ) if not tb [ nl80211... | Here is where SSIDs and their data is decoded from the binary data sent by the kernel . |
59,705 | def do_scan_trigger ( sk , if_index , driver_id , mcid ) : _LOGGER . debug ( 'Joining group %d.' , mcid ) ret = nl_socket_add_membership ( sk , mcid ) if ret < 0 : return ret msg = nlmsg_alloc ( ) genlmsg_put ( msg , 0 , 0 , driver_id , 0 , 0 , nl80211 . NL80211_CMD_TRIGGER_SCAN , 0 ) nla_put_u32 ( msg , nl80211 . NL80... | Issue a scan request to the kernel and wait for it to reply with a signal . |
59,706 | def eta_letters ( seconds ) : final_days , final_hours , final_minutes , final_seconds = 0 , 0 , 0 , seconds if final_seconds >= 86400 : final_days = int ( final_seconds / 86400.0 ) final_seconds -= final_days * 86400 if final_seconds >= 3600 : final_hours = int ( final_seconds / 3600.0 ) final_seconds -= final_hours *... | Convert seconds remaining into human readable strings . |
59,707 | def print_table ( data ) : table = AsciiTable ( [ COLUMNS ] ) table . justify_columns [ 2 ] = 'right' table . justify_columns [ 3 ] = 'right' table . justify_columns [ 4 ] = 'right' table_data = list ( ) for row_in in data : row_out = [ str ( row_in . get ( 'ssid' , '' ) ) . replace ( '\0' , '' ) , str ( row_in . get (... | Print the table of detected SSIDs and their data to screen . |
59,708 | def generateObject ( self , sObjectType ) : obj = self . _sforce . factory . create ( 'ens:sObject' ) obj . type = sObjectType return obj | Generate a Salesforce object such as a Lead or Contact |
59,709 | def _marshallSObjects ( self , sObjects , tag = 'sObjects' ) : if not isinstance ( sObjects , ( tuple , list ) ) : sObjects = ( sObjects , ) if sObjects [ 0 ] . type in [ 'LeadConvert' , 'SingleEmailMessage' , 'MassEmailMessage' ] : nsPrefix = 'tns:' else : nsPrefix = 'ens:' li = [ ] for obj in sObjects : el = Element ... | Marshall generic sObjects into a list of SAX elements |
59,710 | def _setHeaders ( self , call = None , ** kwargs ) : headers = { 'SessionHeader' : self . _sessionHeader } if 'debug_categories' in kwargs : debug_categories = kwargs [ 'debug_categories' ] headers [ 'DebuggingHeader' ] = { 'categories' : debug_categories } if call in ( 'convertLead' , 'create' , 'merge' , 'process' , ... | Attach particular SOAP headers to the request depending on the method call made |
59,711 | def invalidateSessions ( self , sessionIds ) : self . _setHeaders ( 'invalidateSessions' ) return self . _handleResultTyping ( self . _sforce . service . invalidateSessions ( sessionIds ) ) | Invalidate a Salesforce session |
59,712 | def query ( self , queryString ) : self . _setHeaders ( 'query' ) return self . _sforce . service . query ( queryString ) | Executes a query against the specified object and returns data that matches the specified criteria . |
59,713 | def queryAll ( self , queryString ) : self . _setHeaders ( 'queryAll' ) return self . _sforce . service . queryAll ( queryString ) | Retrieves data from specified objects whether or not they have been deleted . |
59,714 | def queryMore ( self , queryLocator ) : self . _setHeaders ( 'queryMore' ) return self . _sforce . service . queryMore ( queryLocator ) | Retrieves the next batch of objects from a query . |
59,715 | def resetPassword ( self , userId ) : self . _setHeaders ( 'resetPassword' ) return self . _sforce . service . resetPassword ( userId ) | Changes a user s password to a system - generated value . |
59,716 | def setPassword ( self , userId , password ) : self . _setHeaders ( 'setPassword' ) return self . _sforce . service . setPassword ( userId , password ) | Sets the specified user s password to the specified value . |
59,717 | def nl_msgtype_lookup ( ops , msgtype ) : for i in ops . co_msgtypes : if i . mt_id == msgtype : return i return None | Lookup message type cache association . |
59,718 | def nl_cache_mngt_register ( ops ) : global cache_ops if not ops . co_name or not ops . co_obj_ops : return - NLE_INVAL with cache_ops_lock : if _nl_cache_ops_lookup ( ops . co_name ) : return - NLE_EXIST ops . co_refcnt = 0 ops . co_next = cache_ops cache_ops = ops _LOGGER . debug ( 'Registered cache operations {0}' .... | Register a set of cache operations . |
59,719 | def nl_connect ( sk , protocol ) : flags = getattr ( socket , 'SOCK_CLOEXEC' , 0 ) if sk . s_fd != - 1 : return - NLE_BAD_SOCK try : sk . socket_instance = socket . socket ( getattr ( socket , 'AF_NETLINK' , - 1 ) , socket . SOCK_RAW | flags , protocol ) except OSError as exc : return - nl_syserr2nlerr ( exc . errno ) ... | Create file descriptor and bind socket . |
59,720 | def nl_complete_msg ( sk , msg ) : nlh = msg . nm_nlh if nlh . nlmsg_pid == NL_AUTO_PORT : nlh . nlmsg_pid = nl_socket_get_local_port ( sk ) if nlh . nlmsg_seq == NL_AUTO_SEQ : nlh . nlmsg_seq = sk . s_seq_next sk . s_seq_next += 1 if msg . nm_protocol == - 1 : msg . nm_protocol = sk . s_proto nlh . nlmsg_flags |= NLM_... | Finalize Netlink message . |
59,721 | def nl_send_simple ( sk , type_ , flags , buf = None , size = 0 ) : msg = nlmsg_alloc_simple ( type_ , flags ) if buf is not None and size : err = nlmsg_append ( msg , buf , size , NLMSG_ALIGNTO ) if err < 0 : return err return nl_send_auto ( sk , msg ) | Construct and transmit a Netlink message . |
59,722 | def nl_recv ( sk , nla , buf , creds = None ) : flags = 0 page_size = resource . getpagesize ( ) * 4 if sk . s_flags & NL_MSG_PEEK : flags |= socket . MSG_PEEK | socket . MSG_TRUNC iov_len = sk . s_bufsize or page_size if creds and sk . s_flags & NL_SOCK_PASSCRED : raise NotImplementedError while True : try : if hasatt... | Receive data from Netlink socket . |
59,723 | def nl_recvmsgs_report ( sk , cb ) : if cb . cb_recvmsgs_ow : return int ( cb . cb_recvmsgs_ow ( sk , cb ) ) return int ( recvmsgs ( sk , cb ) ) | Receive a set of messages from a Netlink socket and report parsed messages . |
59,724 | def nl_recvmsgs ( sk , cb ) : err = nl_recvmsgs_report ( sk , cb ) if err > 0 : return 0 return int ( err ) | Receive a set of messages from a Netlink socket . |
59,725 | def nl_wait_for_ack ( sk ) : cb = nl_cb_clone ( sk . s_cb ) nl_cb_set ( cb , NL_CB_ACK , NL_CB_CUSTOM , lambda * _ : NL_STOP , None ) return int ( nl_recvmsgs ( sk , cb ) ) | Wait for ACK . |
59,726 | def get_plugin_client_settings ( self ) : settings = { } user_path = self . get_plugin_settings_path ( "User" ) def_path = self . get_plugin_settings_path ( "MavensMate" ) if def_path == None : if 'ATOM' in self . plugin_client : file_name = 'atom' elif 'SUBLIME_TEXT' in self . plugin_client : file_name = 'st3' elif 'B... | if the default path for settings is none we re either dealing with a bad client setup or a new client like Atom . io . Let s load the settings from the default cache and optionally allow them to pipe settings in via STDIN |
59,727 | def nlmsg_for_each_attr ( nlh , hdrlen , rem ) : return nla_for_each_attr ( nlmsg_attrdata ( nlh , hdrlen ) , nlmsg_attrlen ( nlh , hdrlen ) , rem ) | Iterate over a stream of attributes in a message . |
59,728 | def nlmsg_attrdata ( nlh , hdrlen ) : data = nlmsg_data ( nlh ) return libnl . linux_private . netlink . nlattr ( bytearray_ptr ( data , libnl . linux_private . netlink . NLMSG_ALIGN ( hdrlen ) ) ) | Head of attributes data . |
59,729 | def nlmsg_attrlen ( nlh , hdrlen ) : return max ( nlmsg_len ( nlh ) - libnl . linux_private . netlink . NLMSG_ALIGN ( hdrlen ) , 0 ) | Length of attributes data . |
59,730 | def nlmsg_ok ( nlh , remaining ) : sizeof = libnl . linux_private . netlink . nlmsghdr . SIZEOF return remaining . value >= sizeof and sizeof <= nlh . nlmsg_len <= remaining . value | Check if the Netlink message fits into the remaining bytes . |
59,731 | def nlmsg_next ( nlh , remaining ) : totlen = libnl . linux_private . netlink . NLMSG_ALIGN ( nlh . nlmsg_len ) remaining . value -= totlen return libnl . linux_private . netlink . nlmsghdr ( bytearray_ptr ( nlh . bytearray , totlen ) ) | Next Netlink message in message stream . |
59,732 | def nlmsg_parse ( nlh , hdrlen , tb , maxtype , policy ) : if not nlmsg_valid_hdr ( nlh , hdrlen ) : return - NLE_MSG_TOOSHORT return nla_parse ( tb , maxtype , nlmsg_attrdata ( nlh , hdrlen ) , nlmsg_attrlen ( nlh , hdrlen ) , policy ) | Parse attributes of a Netlink message . |
59,733 | def nlmsg_find_attr ( nlh , hdrlen , attrtype ) : return nla_find ( nlmsg_attrdata ( nlh , hdrlen ) , nlmsg_attrlen ( nlh , hdrlen ) , attrtype ) | Find a specific attribute in a Netlink message . |
59,734 | def nlmsg_alloc ( len_ = default_msg_size ) : len_ = max ( libnl . linux_private . netlink . nlmsghdr . SIZEOF , len_ ) nm = nl_msg ( ) nm . nm_refcnt = 1 nm . nm_nlh = libnl . linux_private . netlink . nlmsghdr ( bytearray ( b'\0' ) * len_ ) nm . nm_protocol = - 1 nm . nm_size = len_ nm . nm_nlh . nlmsg_len = nlmsg_to... | Allocate a new Netlink message with maximum payload size specified . |
59,735 | def nlmsg_inherit ( hdr = None ) : nm = nlmsg_alloc ( ) if hdr : new = nm . nm_nlh new . nlmsg_type = hdr . nlmsg_type new . nlmsg_flags = hdr . nlmsg_flags new . nlmsg_seq = hdr . nlmsg_seq new . nlmsg_pid = hdr . nlmsg_pid return nm | Allocate a new Netlink message and inherit Netlink message header . |
59,736 | def nlmsg_alloc_simple ( nlmsgtype , flags ) : nlh = libnl . linux_private . netlink . nlmsghdr ( nlmsg_type = nlmsgtype , nlmsg_flags = flags ) msg = nlmsg_inherit ( nlh ) _LOGGER . debug ( 'msg 0x%x: Allocated new simple message' , id ( msg ) ) return msg | Allocate a new Netlink message . |
59,737 | def nlmsg_convert ( hdr ) : nm = nlmsg_alloc ( hdr . nlmsg_len ) if not nm : return None nm . nm_nlh . bytearray = hdr . bytearray . copy ( ) [ : hdr . nlmsg_len ] return nm | Convert a Netlink message received from a Netlink socket to an nl_msg . |
59,738 | def nlmsg_reserve ( n , len_ , pad ) : nlmsg_len_ = n . nm_nlh . nlmsg_len tlen = len_ if not pad else ( ( len_ + ( pad - 1 ) ) & ~ ( pad - 1 ) ) if tlen + nlmsg_len_ > n . nm_size : return None buf = bytearray_ptr ( n . nm_nlh . bytearray , nlmsg_len_ ) n . nm_nlh . nlmsg_len += tlen if tlen > len_ : bytearray_ptr ( b... | Reserve room for additional data in a Netlink message . |
59,739 | def nlmsg_append ( n , data , len_ , pad ) : tmp = nlmsg_reserve ( n , len_ , pad ) if tmp is None : return - NLE_NOMEM tmp [ : len_ ] = data . bytearray [ : len_ ] _LOGGER . debug ( 'msg 0x%x: Appended %d bytes with padding %d' , id ( n ) , len_ , pad ) return 0 | Append data to tail of a Netlink message . |
59,740 | def nlmsg_put ( n , pid , seq , type_ , payload , flags ) : if n . nm_nlh . nlmsg_len < libnl . linux_private . netlink . NLMSG_HDRLEN : raise BUG nlh = n . nm_nlh nlh . nlmsg_type = type_ nlh . nlmsg_flags = flags nlh . nlmsg_pid = pid nlh . nlmsg_seq = seq _LOGGER . debug ( 'msg 0x%x: Added netlink header type=%d, fl... | Add a Netlink message header to a Netlink message . |
59,741 | def nl_nlmsg_flags2str ( flags , buf , _ = None ) : del buf [ : ] all_flags = ( ( 'REQUEST' , libnl . linux_private . netlink . NLM_F_REQUEST ) , ( 'MULTI' , libnl . linux_private . netlink . NLM_F_MULTI ) , ( 'ACK' , libnl . linux_private . netlink . NLM_F_ACK ) , ( 'ECHO' , libnl . linux_private . netlink . NLM_F_ECH... | Netlink Message Flags Translations . |
59,742 | def dump_hex ( ofd , start , len_ , prefix = 0 ) : prefix_whitespaces = ' ' * prefix limit = 16 - ( prefix * 2 ) start_ = start [ : len_ ] for line in ( start_ [ i : i + limit ] for i in range ( 0 , len ( start_ ) , limit ) ) : hex_lines , ascii_lines = list ( ) , list ( ) for c in line : hex_lines . append ( '{0:02x}... | Convert start to hex and logs it 16 bytes per log statement . |
59,743 | def nl_msg_dump ( msg , ofd = _LOGGER . debug ) : hdr = nlmsg_hdr ( msg ) ofd ( '-------------------------- BEGIN NETLINK MESSAGE ---------------------------' ) ofd ( ' [NETLINK HEADER] %d octets' , hdr . SIZEOF ) print_hdr ( ofd , msg ) if hdr . nlmsg_type == libnl . linux_private . netlink . NLMSG_ERROR : dump_err... | Dump message in human readable format to callable . |
59,744 | def nl_object_alloc ( ops ) : new = nl_object ( ) nl_init_list_head ( new . ce_list ) new . ce_ops = ops if ops . oo_constructor : ops . oo_constructor ( new ) _LOGGER . debug ( 'Allocated new object 0x%x' , id ( new ) ) return new | Allocate a new object of kind specified by the operations handle . |
59,745 | def genl_register_family ( ops ) : if not ops . o_name or ( ops . o_cmds and ops . o_ncmds <= 0 ) : return - NLE_INVAL if ops . o_id and lookup_family ( ops . o_id ) : return - NLE_EXIST if lookup_family_by_name ( ops . o_name ) : return - NLE_EXIST nl_list_add_tail ( ops . o_list , genl_ops_list ) return 0 | Register Generic Netlink family and associated commands . |
59,746 | def genl_register ( ops ) : if ops . co_protocol != NETLINK_GENERIC : return - NLE_PROTO_MISMATCH if ops . co_hdrsize < GENL_HDRSIZE ( 0 ) : return - NLE_INVAL if ops . co_genl is None : return - NLE_INVAL ops . co_genl . o_cache_ops = ops ops . co_genl . o_hdrsize = ops . co_hdrsize - GENL_HDRLEN ops . co_genl . o_nam... | Register Generic Netlink family backed cache . |
59,747 | def __setup_connection ( self ) : if self . payload != None and type ( self . payload ) is dict and 'settings' in self . payload : config . plugin_client_settings = self . payload [ 'settings' ] config . offline = self . args . offline config . connection = PluginConnection ( client = self . args . client or 'SUBLIME_T... | each operation requested represents a session the session holds information about the plugin running it and establishes a project object |
59,748 | def execute ( self ) : try : self . __setup_connection ( ) if self . args . ui_switch == True : config . logger . debug ( 'UI operation requested, attempting to launch MavensMate UI' ) tmp_html_file = util . generate_ui ( self . operation , self . payload , self . args ) if config . connection . plugin_client == 'ATOM'... | Executes requested command |
59,749 | def get_alert ( self , alert ) : if alert > self . alerts_count ( ) or self . alerts_count ( ) is None : return None else : return self . get ( ) [ alert - 1 ] | Recieves a day as an argument and returns the prediction for that alert if is available . If not function will return None . |
59,750 | def get_forecast ( self , latitude , longitude ) : reply = self . http_get ( self . url_builder ( latitude , longitude ) ) self . forecast = json . loads ( reply ) for item in self . forecast . keys ( ) : setattr ( self , item , self . forecast [ item ] ) | Gets the weather data from darksky api and stores it in the respective dictionaries if available . This function should be used to fetch weather information . |
59,751 | def get_forecast_fromstr ( self , reply ) : self . forecast = json . loads ( reply ) for item in self . forecast . keys ( ) : setattr ( self , item , self . forecast [ item ] ) | Gets the weather data from a darksky api response string and stores it in the respective dictionaries if available . This function should be used to fetch weather information . |
59,752 | def url_builder ( self , latitude , longitude ) : try : float ( latitude ) float ( longitude ) except TypeError : raise TypeError ( 'Latitude (%s) and Longitude (%s) must be a float number' % ( latitude , longitude ) ) url = self . _darksky_url + self . forecast_io_api_key + '/' url += str ( latitude ) . strip ( ) + ',... | This function is used to build the correct url to make the request to the forecast . io api . Recieves the latitude and the longitude . Return a string with the url . |
59,753 | def http_get ( self , request_url ) : try : headers = { 'Accept-Encoding' : 'gzip, deflate' } response = requests . get ( request_url , headers = headers ) except requests . exceptions . Timeout as ext : log . error ( 'Error: Timeout' , ext ) except requests . exceptions . TooManyRedirects as extmr : log . error ( 'Err... | This function recieves the request url and it is used internally to get the information via http . Returns the response content . Raises Timeout TooManyRedirects RequestException . Raises KeyError if headers are not present . Raises HTTPError if responde code is not 200 . |
59,754 | def _map_or_starmap ( function , iterable , args , kwargs , map_or_starmap ) : arg_newarg = ( ( "parallel" , "pm_parallel" ) , ( "chunksize" , "pm_chunksize" ) , ( "pool" , "pm_pool" ) , ( "processes" , "pm_processes" ) , ( "parmap_progress" , "pm_pbar" ) ) kwargs = _deprecated_kwargs ( kwargs , arg_newarg ) chunksize ... | Shared function between parmap . map and parmap . starmap . Refer to those functions for details . |
59,755 | def _map_or_starmap_async ( function , iterable , args , kwargs , map_or_starmap ) : arg_newarg = ( ( "parallel" , "pm_parallel" ) , ( "chunksize" , "pm_chunksize" ) , ( "pool" , "pm_pool" ) , ( "processes" , "pm_processes" ) , ( "callback" , "pm_callback" ) , ( "error_callback" , "pm_error_callback" ) ) kwargs = _depr... | Shared function between parmap . map_async and parmap . starmap_async . Refer to those functions for details . |
59,756 | def map_async ( function , iterable , * args , ** kwargs ) : return _map_or_starmap_async ( function , iterable , args , kwargs , "map" ) | This function is the multiprocessing . Pool . map_async version that supports multiple arguments . |
59,757 | def starmap_async ( function , iterables , * args , ** kwargs ) : return _map_or_starmap_async ( function , iterables , args , kwargs , "starmap" ) | This function is the multiprocessing . Pool . starmap_async version that supports multiple arguments . |
59,758 | def lookup_domain ( domain , nameservers = [ ] , rtype = "A" , exclude_nameservers = [ ] , timeout = 2 ) : dns_exp = DNSQuery ( domains = [ domain ] , nameservers = nameservers , rtype = rtype , exclude_nameservers = exclude_nameservers , timeout = timeout ) return dns_exp . lookup_domain ( domain ) | Wrapper for DNSQuery method |
59,759 | def parse_out_ips ( message ) : ips = [ ] for entry in message . answer : for rdata in entry . items : ips . append ( rdata . to_text ( ) ) return ips | Given a message parse out the ips in the answer |
59,760 | def send_chaos_queries ( self ) : names = [ "HOSTNAME.BIND" , "VERSION.BIND" , "ID.SERVER" ] self . results = { 'exp-name' : "chaos-queries" } for name in names : self . results [ name ] = { } for nameserver in self . nameservers : sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) sock . setsockopt ( so... | Send chaos queries to identify the DNS server and its manufacturer |
59,761 | def lookup_domains ( self ) : thread_error = False thread_wait_timeout = 200 ind = 1 total_item_count = len ( self . domains ) for domain in self . domains : for nameserver in self . nameservers : wait_time = 0 while threading . active_count ( ) > self . max_threads : time . sleep ( 1 ) wait_time += 1 if wait_time > th... | More complex DNS primitive that looks up domains concurrently |
59,762 | def start ( self , timeout = None ) : self . thread . start ( ) start_time = time . time ( ) if not timeout : timeout = self . timeout while start_time + timeout > time . time ( ) : self . thread . join ( 1 ) if self . started : return True if self . error : return False return False | Start running the command |
59,763 | def stop ( self , timeout = None ) : if not timeout : timeout = self . timeout self . kill_switch ( ) self . process . kill ( ) self . thread . join ( timeout ) try : os . killpg ( os . getpgid ( self . process . pid ) , signal . SIGTERM ) except : pass if self . stopped : return True else : return False | Stop the given command |
59,764 | def traceroute_batch ( input_list , results = { } , method = "udp" , cmd_arguments = None , delay_time = 0.1 , max_threads = 100 ) : threads = [ ] thread_error = False thread_wait_timeout = 200 ind = 1 total_item_count = len ( input_list ) for domain in input_list : wait_time = 0 while threading . active_count ( ) > ma... | This is a parallel version of the traceroute primitive . |
59,765 | def _traceroute_callback ( self , line , kill_switch ) : line = line . lower ( ) if "traceroute to" in line : self . started = True if "enough privileges" in line : self . error = True self . kill_switch ( ) self . stopped = True if "service not known" in line : self . error = True self . kill_switch ( ) self . stopped... | Callback function to handle traceroute . |
59,766 | def output_callback ( self , line , kill_switch ) : self . notifications += line + "\n" if "Initialization Sequence Completed" in line : self . started = True if "ERROR:" in line or "Cannot resolve host address:" in line : self . error = True if "process exiting" in line : self . stopped = True | Set status of openvpn according to what we process |
59,767 | def load_experiments ( self ) : logging . debug ( "Loading experiments." ) exp_dir = self . config [ 'dirs' ] [ 'experiments_dir' ] for path in glob . glob ( os . path . join ( exp_dir , '[!_]*.py' ) ) : name , ext = os . path . splitext ( os . path . basename ( path ) ) try : if name in loaded_modules : continue imp .... | This function will return the list of experiments . |
59,768 | def _tcpdump_callback ( self , line , kill_switch ) : line = line . lower ( ) if ( "listening" in line ) or ( "reading" in line ) : self . started = True if ( "no suitable device" in line ) : self . error = True self . kill_switch ( ) if "by kernel" in line : self . stopped = True | Callback function to handle tcpdump |
59,769 | def _run ( ) : args = parse_args ( ) custom_meta = None if args . custom_meta : print "Adding custom parameters:" custom_meta = { } try : for item in args . custom_meta . split ( ',' ) : key , value = item . split ( ':' ) custom_meta [ key ] = value print 'key: %s, value: %s' % ( key , value ) except Exception as e : s... | Entry point for package and cli uses |
59,770 | def get_fingerprint_batch ( input_list , results = { } , default_port = 443 , delay_time = 0.5 , max_threads = 100 ) : threads = [ ] thread_error = False thread_wait_timeout = 200 ind = 1 total_item_count = len ( input_list ) for row in input_list : if len ( row . split ( ":" ) ) == 2 : host , port = row . split ( ":" ... | This is a parallel version of the TLS fingerprint primitive . |
59,771 | def meta_redirect ( content ) : decoded = content . decode ( "utf-8" , errors = "replace" ) try : soup = BeautifulSoup . BeautifulSoup ( decoded ) except Exception as e : return None result = soup . find ( "meta" , attrs = { "http-equiv" : re . compile ( "^refresh$" , re . I ) } ) if result : try : wait , text = result... | Returns redirecting URL if there is a HTML refresh meta tag returns None otherwise |
59,772 | def _get_http_request ( netloc , path = "/" , headers = None , ssl = False ) : if ssl : port = 443 else : port = 80 host = netloc if len ( netloc . split ( ":" ) ) == 2 : host , port = netloc . split ( ":" ) request = { "host" : host , "port" : port , "path" : path , "ssl" : ssl , "method" : "GET" } if headers : reques... | Actually gets the http . Moved this to it s own private method since it is called several times for following redirects |
59,773 | def get_requests_batch ( input_list , results = { } , delay_time = 0.5 , max_threads = 100 ) : threads = [ ] thread_error = False thread_wait_timeout = 200 ind = 1 total_item_count = len ( input_list ) user_agent = random . choice ( user_agent_pool ) for row in input_list : headers = { } path = "/" ssl = False theme = ... | This is a parallel version of the HTTP GET primitive . |
59,774 | def create_script_for_location ( content , destination ) : temp = tempfile . NamedTemporaryFile ( mode = 'w' , delete = False ) temp . write ( content ) temp . close ( ) shutil . move ( temp . name , destination ) cur_perms = os . stat ( destination ) . st_mode set_perms = cur_perms | stat . S_IXOTH | stat . S_IXGRP | ... | Create a script with the given content mv it to the destination and make it executable |
59,775 | def daemonize ( package , bin_loc , user ) : path = "/etc/cron.hourly/centinel-" + user if user != "root" : hourly = "" . join ( [ "#!/bin/bash\n" , "# cron job for centinel\n" , "su " , user , " -c '" , bin_loc , " --sync'\n" , "su " , user , " -c '" , bin_loc , "'\n" , "su " , user , " -c '" , bin_loc , " --sync'\n" ... | Create crontab entries to run centinel every hour and autoupdate every day |
59,776 | def create_config_files ( directory ) : template_url = ( "https://securenetconnection.com/vpnconfig/" "openvpn-template.ovpn" ) resp = requests . get ( template_url ) resp . raise_for_status ( ) template = resp . content server_url = ( "https://securenetconnection.com/vpnconfig/" "servers-cli.php" ) resp = requests . g... | Create all available VPN configuration files in the given directory |
59,777 | def sync_scheduler ( self ) : url = "%s/%s/%s" % ( self . config [ 'server' ] [ 'server_url' ] , "experiments" , "scheduler.info" ) try : req = requests . get ( url , proxies = self . config [ 'proxy' ] [ 'proxy' ] , auth = self . auth , verify = self . verify ) req . raise_for_status ( ) except Exception as exp : logg... | Download the scheduler . info file and perform a smart comparison with what we currently have so that we don t overwrite the last_run timestamp |
59,778 | def informed_consent ( self ) : if self . typeable_handle is None : consent_url = [ self . config [ 'server' ] [ 'server_url' ] , "/get_initial_consent?username=" ] consent_url . append ( urlsafe_b64encode ( self . username ) ) consent_url . append ( "&password=" ) consent_url . append ( urlsafe_b64encode ( self . pass... | Create a URL for the user to give their consent through |
59,779 | def return_abs_path ( directory , path ) : if directory is None or path is None : return directory = os . path . expanduser ( directory ) return os . path . abspath ( os . path . join ( directory , path ) ) | Unfortunately Python is not smart enough to return an absolute path with tilde expansion so I writing functionality to do this |
59,780 | def _run ( ) : args = parse_args ( ) signal . signal ( signal . SIGTERM , signal_handler ) signal . signal ( signal . SIGINT , signal_handler ) log_formatter = logging . Formatter ( "%(asctime)s %(filename)s(line %(lineno)d) " "%(levelname)s: %(message)s" ) root_logger = logging . getLogger ( ) root_logger . setLevel (... | Entry point for all uses of centinel |
59,781 | def parse_config ( self , config_file ) : with open ( config_file , 'r' ) as f : config = json . load ( f ) self . params = config if self . params [ 'proxy' ] [ 'proxy_type' ] : self . params [ 'proxy' ] = { self . params [ 'proxy' ] [ 'proxy_type' ] : self . params [ 'proxy' ] [ 'proxy_url' ] } | Given a configuration file read in and interpret the results |
59,782 | def update ( self , old , backup_path = None ) : for category in old . params . keys ( ) : for parameter in old . params [ category ] . keys ( ) : if ( category in self . params and parameter in self . params [ category ] and ( old . params [ category ] [ parameter ] != self . params [ category ] [ parameter ] ) and ( ... | Update the old configuration file with new values . |
59,783 | def write_out_config ( self , config_file ) : with open ( config_file , 'w' ) as f : json . dump ( self . params , f , indent = 2 , separators = ( ',' , ': ' ) ) | Write out the configuration file |
59,784 | def divide_url ( self , url ) : if 'https://' in url : host = url [ 8 : ] . split ( '/' ) [ 0 ] path = url [ 8 + len ( host ) : ] elif 'http://' in url : host = url [ 7 : ] . split ( '/' ) [ 0 ] path = url [ 7 + len ( host ) : ] else : host = url . split ( '/' ) [ 0 ] path = url [ len ( host ) : ] return host , path | divide url into host and path two parts |
59,785 | def hash_folder ( folder , regex = '[!_]*' ) : file_hashes = { } for path in glob . glob ( os . path . join ( folder , regex ) ) : if not os . path . isfile ( path ) : continue with open ( path , 'r' ) as fileP : md5_hash = hashlib . md5 ( fileP . read ( ) ) . digest ( ) file_name = os . path . basename ( path ) file_h... | Get the md5 sum of each file in the folder and return to the user |
59,786 | def compute_files_to_download ( client_hashes , server_hashes ) : to_dload , to_delete = [ ] , [ ] for filename in server_hashes : if filename not in client_hashes : to_dload . append ( filename ) continue if client_hashes [ filename ] != server_hashes [ filename ] : to_dload . append ( filename ) for filename in clien... | Given a dictionary of file hashes from the client and the server specify which files should be downloaded from the server |
59,787 | def spinner ( beep = False , disable = False , force = False ) : return Spinner ( beep , disable , force ) | This function creates a context manager that is used to display a spinner on stdout as long as the context has not exited . |
59,788 | def verifier ( self , url ) : webbrowser . open ( url ) print ( 'A browser should have opened up with a link to allow us to access' ) print ( 'your account, follow the instructions on the link and paste the verifier' ) print ( 'Code into here to give us access, if the browser didn\'t open, the link is:' ) print ( url )... | Will ask user to click link to accept app and write code |
59,789 | def write_config ( self ) : if not os . path . exists ( os . path . dirname ( self . config_file ) ) : os . makedirs ( os . path . dirname ( self . config_file ) ) with open ( self . config_file , 'w' ) as f : f . write ( json . dumps ( self . config ) ) f . close ( ) | Write config to file |
59,790 | def read_config ( self ) : try : with open ( self . config_file , 'r' ) as f : self . config = json . loads ( f . read ( ) ) f . close ( ) except IOError : return False return True | Read config from file |
59,791 | def post_note ( self ) : if self . args . note_title : note_title = self . args . note_title else : note_title = None note_content = self . args . note_content mynote = self . pump . Note ( display_name = note_title , content = note_content ) mynote . to = self . pump . me . followers mynote . cc = self . pump . Public... | Post note and return the URL of the posted note |
59,792 | def get_obj_id ( self , item ) : if item is not None : if isinstance ( item , six . string_types ) : return item elif hasattr ( item , 'id' ) : return item . id | Get the id of a PumpObject . |
59,793 | def get_page ( self , url ) : if url : data = self . feed . _request ( url , offset = self . _offset , since = self . _since , before = self . _before ) self . _before = False if self . _before is not None else None self . _since = False if self . _since is not None else None if getattr ( self . feed , 'issue65' , Fals... | Get a page of items from API |
59,794 | def done ( self ) : if self . _done : return self . _done if self . _limit is None : self . _done = False elif self . itemcount >= self . _limit : self . _done = True return self . _done | Check if we should stop returning objects |
59,795 | def _build_cache ( self ) : self . cache = [ ] if self . done : return for i in ( self . get_cached ( ) if self . _cached else self . get_page ( self . url ) ) : if not self . _cached : if not i . get ( "objectType" ) : i [ "objectType" ] = self . feed . object_types [ 0 ] obj = Mapper ( pypump = self . feed . _pump ) ... | Build a list of objects from feed s cached items or API page |
59,796 | def items ( self , offset = None , limit = 20 , since = None , before = None , * args , ** kwargs ) : return ItemList ( self , offset = offset , limit = limit , since = since , before = before , cached = self . is_cached ) | Get a feed s items . |
59,797 | def direct ( self ) : url = self . _subfeed ( "direct" ) if "direct" in self . url or "major" in self . url or "minor" in self . url : return self if self . _direct is None : self . _direct = self . __class__ ( url , pypump = self . _pump ) return self . _direct | Direct inbox feed contains activities addressed directly to the owner of the inbox . |
59,798 | def major ( self ) : url = self . _subfeed ( "major" ) if "major" in self . url or "minor" in self . url : return self if self . _major is None : self . _major = self . __class__ ( url , pypump = self . _pump ) return self . _major | Major inbox feed contains major activities such as notes and images . |
59,799 | def minor ( self ) : url = self . _subfeed ( "minor" ) if "minor" in self . url or "major" in self . url : return self if self . _minor is None : self . _minor = self . __class__ ( url , pypump = self . _pump ) return self . _minor | Minor inbox feed contains minor activities such as likes shares and follows . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.