idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
55,800 | def stamp_excerpt ( kb_app : kb , sphinx_app : Sphinx , doctree : doctree ) : resources = sphinx_app . env . resources confdir = sphinx_app . confdir source = PurePath ( doctree . attributes [ 'source' ] ) docname = str ( source . relative_to ( confdir ) ) . split ( '.rst' ) [ 0 ] resource = resources . get ( docname )... | Walk the tree and extract excert into resource . excerpt |
55,801 | def bitfieldify ( buff , count ) : databits = bitarray ( ) databits . frombytes ( buff ) return databits [ len ( databits ) - count : ] | Extract a bitarray out of a bytes array . |
55,802 | def build_byte_align_buff ( bits ) : bitmod = len ( bits ) % 8 if bitmod == 0 : rdiff = bitarray ( ) else : rdiff = bitarray ( 8 - bitmod ) rdiff . setall ( False ) return rdiff + bits | Pad the left side of a bitarray with 0s to align its length with byte boundaries . |
55,803 | def create ( self , name , cidr , ** kwargs ) : return self . driver . create ( name , cidr , ** kwargs ) | This function will create a user network . Within OpenStack it will create a network and a subnet Within AWS it will create a VPC and a subnet |
55,804 | def find_whole_word ( w ) : return re . compile ( r'\b({0})\b' . format ( w ) , flags = re . IGNORECASE ) . search | Scan through string looking for a location where this word produces a match and return a corresponding MatchObject instance . Return None if no position in the string matches the pattern ; note that this is different from finding a zero - length match at some point in the string . |
55,805 | def GetCompressedFilesInDir ( fileDir , fileList , ignoreDirList , supportedFormatList = [ '.rar' , ] ) : goodlogging . Log . Info ( "EXTRACT" , "Parsing file directory: {0}" . format ( fileDir ) ) if os . path . isdir ( fileDir ) is True : for globPath in glob . glob ( os . path . join ( fileDir , '*' ) ) : if os . pa... | Get all supported files from given directory folder . Appends to given file list . |
55,806 | def MultipartArchiving ( firstPartExtractList , otherPartSkippedList , archiveDir , otherPartFilePath = None ) : if otherPartFilePath is None : for filePath in list ( otherPartSkippedList ) : MultipartArchiving ( firstPartExtractList , otherPartSkippedList , archiveDir , filePath ) else : baseFileName = re . findall ( ... | Archive all parts of multi - part compressed file . |
55,807 | def DoRarExtraction ( rarArchive , targetFile , dstDir ) : try : rarArchive . extract ( targetFile , dstDir ) except BaseException as ex : goodlogging . Log . Info ( "EXTRACT" , "Extract failed - Exception: {0}" . format ( ex ) ) return False else : return True | RAR extraction with exception catching |
55,808 | def GetRarPassword ( skipUserInput ) : goodlogging . Log . Info ( "EXTRACT" , "RAR file needs password to extract" ) if skipUserInput is False : prompt = "Enter password, 'x' to skip this file or 'exit' to quit this program: " response = goodlogging . Log . Input ( "EXTRACT" , prompt ) response = util . CheckEmptyRespo... | Get password for rar archive from user input . |
55,809 | def CheckPasswordReuse ( skipUserInput ) : goodlogging . Log . Info ( "EXTRACT" , "RAR files needs password to extract" ) if skipUserInput is False : prompt = "Enter 't' to reuse the last password for just this file, " "'a' to reuse for all subsequent files, " "'n' to enter a new password for this file " "or 's' to ent... | Check with user for password reuse . |
55,810 | def register ( self , func , singleton = False , threadlocal = False , name = None ) : func . _giveme_singleton = singleton func . _giveme_threadlocal = threadlocal if name is None : name = func . __name__ self . _registered [ name ] = func return func | Register a dependency function |
55,811 | def get_value ( self , name ) : factory = self . _registered . get ( name ) if not factory : raise KeyError ( 'Name not registered' ) if factory . _giveme_singleton : if name in self . _singletons : return self . _singletons [ name ] self . _singletons [ name ] = factory ( ) return self . _singletons [ name ] elif fact... | Get return value of a dependency factory or a live singleton instance . |
55,812 | def trace ( fun , * a , ** k ) : @ wraps ( fun ) def tracer ( * a , ** k ) : ret = fun ( * a , ** k ) print ( 'trace:fun: %s\n ret=%s\n a=%s\nk%s\n' % ( str ( fun ) , str ( ret ) , str ( a ) , str ( k ) ) ) return ret return tracer | define a tracer for a rule function for log and statistic purposes |
55,813 | def timer ( fun , * a , ** k ) : @ wraps ( fun ) def timer ( * a , ** k ) : start = arrow . now ( ) ret = fun ( * a , ** k ) end = arrow . now ( ) print ( 'timer:fun: %s\n start:%s,end:%s, took [%s]' % ( str ( fun ) , str ( start ) , str ( end ) , str ( end - start ) ) ) return ret return timer | define a timer for a rule function for log and statistic purposes |
55,814 | def get_function ( self , fun = None ) : sfun = str ( fun ) self . say ( 'get_function:' + sfun , verbosity = 100 ) if not fun : return NoRuleFunction ( ) if sfun in self . _rule_functions : return self . _rule_functions [ sfun ] else : self . add_function ( name = sfun , fun = self . rule_function_not_found ( fun ) ) ... | get function as RuleFunction or return a NoRuleFunction function |
55,815 | def add_function ( self , fun = None , name = None , fun_type = FUN_TYPE ) : if not name : if six . PY2 : name = fun . func_name else : name = fun . __name__ self . say ( 'adding fun(%s)' % name , verbosity = 50 ) self . say ( 'adding fun_type:%s' % fun_type , verbosity = 50 ) if self . function_exists ( name ) : self ... | actually replace function |
55,816 | def function_exists ( self , fun ) : res = fun in self . _rule_functions self . say ( 'function exists:' + str ( fun ) + ':' + str ( res ) , verbosity = 10 ) return res | get function s existense |
55,817 | def rule_function_not_found ( self , fun = None ) : sfun = str ( fun ) self . cry ( 'rule_function_not_found:' + sfun ) def not_found ( * a , ** k ) : return ( sfun + ':rule_function_not_found' , k . keys ( ) ) return not_found | any function that does not exist will be added as a dummy function that will gather inputs for easing into the possible future implementation |
55,818 | def parse_value ( val ) : val = val . replace ( "%" , " " ) . replace ( " " , "" ) . replace ( "," , "." ) . replace ( "st" , "" ) . strip ( ) missing = [ "Ejdeltagit" , "N/A" ] if val in missing : return val elif val == "" : return None return float ( val ) | Parse values from html |
55,819 | def _get_html ( self , url ) : self . log . info ( u"/GET {}" . format ( url ) ) r = requests . get ( url ) if hasattr ( r , 'from_cache' ) : if r . from_cache : self . log . info ( "(from cache)" ) if r . status_code != 200 : throw_request_err ( r ) return r . content | Get html from url |
55,820 | def _get_json ( self , url ) : self . log . info ( u"/GET " + url ) r = requests . get ( url ) if hasattr ( r , 'from_cache' ) : if r . from_cache : self . log . info ( "(from cache)" ) if r . status_code != 200 : throw_request_err ( r ) return r . json ( ) | Get json from url |
55,821 | def regions ( self ) : regions = [ ] elem = self . dimensions [ "region" ] . elem for option_elem in elem . find_all ( "option" ) : region = option_elem . text . strip ( ) regions . append ( region ) return regions | Get a list of all regions |
55,822 | def _get_region_slug ( self , id_or_label ) : region = id_or_label slug = region . replace ( u" " , "-" ) . replace ( u"ö", " o") \ . replace ( u"Ö", " O") \ . replace ( u"ä", " a") \ . replace ( u"å", " a") s" EXCEPTIONS = { "Jamtland-Harjedalens" : "Jamtlands" , "Rikets" : "Sveriges" , } if slug in EXCEPTIONS : s... | Get the regional slug to be used in url Norrbotten = > Norrbottens |
55,823 | def default_value ( self ) : if not hasattr ( self , "_default_value" ) : if self . elem_type == "select" : try : def_value = get_option_value ( self . elem . select_one ( "[selected]" ) ) except AttributeError : def_value = get_option_value ( self . elem . select_one ( "option" ) ) elif self . elem_type == "checkbox" ... | The default category when making a query |
55,824 | def _parse_horizontal_scroll_table ( self , table_html ) : row_labels = [ parse_text ( x . text ) for x in table_html . select ( ".DTFC_LeftBodyWrapper tbody tr" ) ] row_label_ids = [ None ] * len ( row_labels ) cols = [ parse_text ( x . text ) for x in table_html . select ( ".dataTables_scrollHead th" ) ] value_rows =... | Get list of dicts from horizontally scrollable table |
55,825 | def is_json_file ( filename , show_warnings = False ) : try : config_dict = load_config ( filename , file_type = "json" ) is_json = True except : is_json = False return ( is_json ) | Check configuration file type is JSON Return a boolean indicating wheather the file is JSON format or not |
55,826 | def is_yaml_file ( filename , show_warnings = False ) : if is_json_file ( filename ) : return ( False ) try : config_dict = load_config ( filename , file_type = "yaml" ) if ( type ( config_dict ) == str ) : is_yaml = False else : is_yaml = True except : is_yaml = False return ( is_yaml ) | Check configuration file type is yaml Return a boolean indicating wheather the file is yaml format or not |
55,827 | def is_ini_file ( filename , show_warnings = False ) : try : config_dict = load_config ( filename , file_type = "ini" ) if config_dict == { } : is_ini = False else : is_ini = True except : is_ini = False return ( is_ini ) | Check configuration file type is INI Return a boolean indicating wheather the file is INI format or not |
55,828 | def is_toml_file ( filename , show_warnings = False ) : if is_yaml_file ( filename ) : return ( False ) try : config_dict = load_config ( filename , file_type = "toml" ) is_toml = True except : is_toml = False return ( is_toml ) | Check configuration file type is TOML Return a boolean indicating wheather the file is TOML format or not |
55,829 | def _collect_settings ( self , apps ) : contents = { } if apps : for app in apps : if app not in settings . INSTALLED_APPS : raise CommandError ( "Application '{0}' not in settings.INSTALLED_APPS" . format ( app ) ) else : apps = settings . INSTALLED_APPS for app in apps : module = import_module ( app ) for module_dir ... | Iterate over given apps or INSTALLED_APPS and collect the content of each s settings file which is expected to be in JSON format . |
55,830 | def required_unique ( objects , key ) : keys = { } duplicate = set ( ) for k in map ( key , objects ) : keys [ k ] = keys . get ( k , 0 ) + 1 if keys [ k ] > 1 : duplicate . add ( k ) if duplicate : return ( False , u"Duplicate object keys: {}" . format ( duplicate ) ) return ( True , u"" ) | A pyrsistent invariant which requires all objects in the given iterable to have a unique key . |
55,831 | def item_by_name ( self , name ) : for obj in self . items : if obj . metadata . name == name : return obj raise KeyError ( name ) | Find an item in this collection by its name metadata . |
55,832 | def _init_name_core ( self , name : str ) : self . __regex = re . compile ( rf'^{self._pattern}$' ) self . name = name | Runs whenever a new instance is initialized or sep is set . |
55,833 | def get_name ( self , ** values ) -> str : if not values and self . name : return self . name if values : for ck , cvs in _sorted_items ( self . compounds ) : if ck in cvs and ck in values : continue comp_values = [ values . pop ( cv , getattr ( self , cv ) ) for cv in cvs ] if None not in comp_values : values [ ck ] =... | Get a new name string from this object s name values . |
55,834 | def cast_config ( cls , config : typing . Mapping [ str , str ] ) -> typing . Dict [ str , str ] : return { k : cls . cast ( v , k ) for k , v in config . items ( ) } | Cast config to grouped regular expressions . |
55,835 | def _execute_primitives ( self , commands ) : for p in commands : if self . _scanchain and self . _scanchain . _debug : print ( " Executing" , p ) p . execute ( self ) | Run a list of executable primitives on this controller and distribute the returned data to the associated TDOPromises . |
55,836 | def pretty_version_text ( ) : version_lines = [ "dtool, version {}" . format ( dtool_version ) ] version_lines . append ( "\nBase:" ) version_lines . append ( "dtoolcore, version {}" . format ( dtoolcore . __version__ ) ) version_lines . append ( "dtool-cli, version {}" . format ( __version__ ) ) version_lines . append... | Return pretty version text listing all plugins . |
55,837 | def dtool ( debug ) : level = logging . WARNING if debug : level = logging . DEBUG logging . basicConfig ( format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' , level = level ) | Tool to work with datasets . |
55,838 | def add_nic ( self , instance_id , net_id ) : self . client . servers . interface_attach ( instance_id , None , net_id , None ) return True | Add a Network Interface Controller |
55,839 | def delete_nic ( self , instance_id , port_id ) : self . client . servers . interface_detach ( instance_id , port_id ) return True | Delete a Network Interface Controller |
55,840 | def disassociate_public_ip ( self , public_ip_id ) : floating_ip = self . client . floating_ips . get ( public_ip_id ) floating_ip = floating_ip . to_dict ( ) instance_id = floating_ip . get ( 'instance_id' ) address = floating_ip . get ( 'ip' ) self . client . servers . remove_floating_ip ( instance_id , address ) ret... | Disassociate a external IP |
55,841 | def split ( self , bitindex ) : if bitindex < 0 : raise ValueError ( "bitindex must be larger or equal to 0." ) if bitindex > len ( self ) : raise ValueError ( "bitindex larger than the array's size. " "Len: %s; bitindex: %s" % ( len ( self ) , bitindex ) ) if bitindex == 0 : return None , self if bitindex == len ( sel... | Split a promise into two promises at the provided index . |
55,842 | def _fulfill ( self , bits , ignore_nonpromised_bits = False ) : if self . _allsubsfulfilled ( ) : if not self . _components : if ignore_nonpromised_bits : self . _value = bits [ self . _bitstartselective : self . _bitstartselective + self . _bitlength ] else : self . _value = bits [ self . _bitstart : self . _bitend ]... | Supply the promise with the bits from its associated primitive s execution . |
55,843 | def makesubatoffset ( self , bitoffset , * , _offsetideal = None ) : if _offsetideal is None : _offsetideal = bitoffset if bitoffset is 0 : return self newpromise = TDOPromise ( self . _chain , self . _bitstart + bitoffset , self . _bitlength , _parent = self , bitstartselective = self . _bitstartselective + _offsetide... | Create a copy of this promise with an offset and use it as this promise s child . |
55,844 | def add ( self , promise , bitoffset , * , _offsetideal = None ) : if _offsetideal is None : _offsetideal = bitoffset if isinstance ( promise , TDOPromise ) : newpromise = promise . makesubatoffset ( bitoffset , _offsetideal = _offsetideal ) self . _promises . append ( newpromise ) elif isinstance ( promise , TDOPromis... | Add a promise to the promise collection at an optional offset . |
55,845 | def split ( self , bitindex ) : if bitindex < 0 : raise ValueError ( "bitindex must be larger or equal to 0." ) if bitindex == 0 : return None , self lastend = 0 split_promise = False for splitindex , p in enumerate ( self . _promises ) : if bitindex in range ( lastend , p . _bitstart ) : split_promise = False break if... | Split a promise into two promises . A tail bit and the rest . |
55,846 | def makesubatoffset ( self , bitoffset , * , _offsetideal = None ) : if _offsetideal is None : _offsetideal = bitoffset if bitoffset is 0 : return self newpromise = TDOPromiseCollection ( self . _chain ) for promise in self . _promises : newpromise . add ( promise , bitoffset , _offsetideal = _offsetideal ) return newp... | Create a copy of this PromiseCollection with an offset applied to each contained promise and register each with their parent . |
55,847 | def cli ( ctx , stage ) : if not ctx . bubble : ctx . say_yellow ( 'There is no bubble present, ' + 'will not show any transformer rules' ) raise click . Abort ( ) path = ctx . home + '/' RULES = None ctx . say ( 'Stage:' + stage , verbosity = 10 ) if stage in STAGES : if stage in ctx . cfg . CFG : STAGE = ctx . cfg . ... | Show transformer rules |
55,848 | def connectExec ( connection , protocol , commandLine ) : deferred = connectSession ( connection , protocol ) @ deferred . addCallback def requestSubsystem ( session ) : return session . requestExec ( commandLine ) return deferred | Connect a Protocol to a ssh exec session |
55,849 | def connectShell ( connection , protocol ) : deferred = connectSession ( connection , protocol ) @ deferred . addCallback def requestSubsystem ( session ) : return session . requestShell ( ) return deferred | Connect a Protocol to a ssh shell session |
55,850 | def connectSubsystem ( connection , protocol , subsystem ) : deferred = connectSession ( connection , protocol ) @ deferred . addCallback def requestSubsystem ( session ) : return session . requestSubsystem ( subsystem ) return deferred | Connect a Protocol to a ssh subsystem channel |
55,851 | def connectSession ( connection , protocol , sessionFactory = None , * args , ** kwargs ) : factory = sessionFactory or defaultSessionFactory session = factory ( * args , ** kwargs ) session . dataReceived = protocol . dataReceived session . closed = lambda : protocol . connectionLost ( connectionDone ) deferred = defe... | Open a SSHSession channel and connect a Protocol to it |
55,852 | def requestSubsystem ( self , subsystem ) : data = common . NS ( subsystem ) return self . sendRequest ( 'subsystem' , data , wantReply = True ) | Request a subsystem and return a deferred reply . |
55,853 | def requestPty ( self , term = None , rows = 0 , cols = 0 , xpixel = 0 , ypixel = 0 , modes = '' ) : term = term or os . environ . get ( 'TERM' , '' ) data = packRequest_pty_req ( term , ( rows , cols , xpixel , ypixel ) , modes ) return self . sendRequest ( 'pty-req' , data ) | Request allocation of a pseudo - terminal for a channel |
55,854 | def requestEnv ( self , env = { } ) : for variable , value in env . items ( ) : data = common . NS ( variable ) + common . NS ( value ) self . sendRequest ( 'env' , data ) | Send requests to set the environment variables for the channel |
55,855 | def commandstr ( command ) : if command == CMD_MESSAGE_ERROR : msg = "CMD_MESSAGE_ERROR" elif command == CMD_MESSAGE_LIST : msg = "CMD_MESSAGE_LIST" elif command == CMD_MESSAGE_PASSWORD : msg = "CMD_MESSAGE_PASSWORD" elif command == CMD_MESSAGE_MP3 : msg = "CMD_MESSAGE_MP3" elif command == CMD_MESSAGE_DELETE : msg = "C... | Convert command into string . |
55,856 | def run ( ) : parser = OptionParser ( version = __version__ , description = __doc__ , ) parser . add_option ( '-u' , '--url' , dest = 'url' , help = 'Database URL (connection string)' , ) parser . add_option ( '-r' , '--render' , dest = 'render' , default = 'dot' , choices = [ 'plantuml' , 'dot' ] , help = 'Output form... | Command for reflection database objects |
55,857 | def refresh ( self ) : strawpoll_response = requests . get ( '{api_url}/{poll_id}' . format ( api_url = api_url , poll_id = self . id ) ) raise_status ( strawpoll_response ) self . status_code = strawpoll_response . status_code self . response_json = strawpoll_response . json ( ) self . id = self . response_json [ 'id'... | Refresh all class attributes . |
55,858 | def write_json_file ( self , path ) : with open ( path , "w" ) as f : f . write ( self . to_json ( ) ) | Serialize this VariantCollection to a JSON representation and write it out to a text file . |
55,859 | def read_json_file ( cls , path ) : with open ( path , 'r' ) as f : json_string = f . read ( ) return cls . from_json ( json_string ) | Construct a VariantCollection from a JSON file . |
55,860 | def dumps ( data , escape = False , ** kwargs ) : if 'sort_keys' not in kwargs : kwargs [ 'sort_keys' ] = True converted = json . dumps ( data , default = _converter , ** kwargs ) if escape : return cgi . escape ( converted ) return converted | A wrapper around json . dumps that can handle objects that json module is not aware . |
55,861 | def deserialize ( klass , data ) : handler = DESERIALIZE_REGISTRY . get ( klass ) if handler : return handler ( data ) raise TypeError ( "There is no deserializer registered to handle " "instances of '{}'" . format ( klass . __name__ ) ) | Helper function to access a method that creates objects of a given klass with the received data . |
55,862 | def _convert_from ( data ) : try : module , klass_name = data [ '__class__' ] . rsplit ( '.' , 1 ) klass = getattr ( import_module ( module ) , klass_name ) except ( ImportError , AttributeError , KeyError ) : return data return deserialize ( klass , data [ '__value__' ] ) | Internal function that will be hooked to the native json . loads |
55,863 | def _converter ( data ) : handler = REGISTRY . get ( data . __class__ ) if handler : full_name = '{}.{}' . format ( data . __class__ . __module__ , data . __class__ . __name__ ) return { '__class__' : full_name , '__value__' : handler ( data ) , } raise TypeError ( repr ( data ) + " is not JSON serializable" ) | Internal function that will be passed to the native json . dumps . |
55,864 | def handle_error ( self , error ) : logging . exception ( "try to sleep if there are repeating errors." ) error_desc = str ( error ) now = datetime . datetime . now ( ) if error_desc not in self . error_time_log : self . error_time_log [ error_desc ] = now return time_of_last_encounter = self . error_time_log [ str ( e... | Try to detect repetitive errors and sleep for a while to avoid being marked as spam |
55,865 | def parse_isodate ( datestr ) : m = isodate_rx . search ( datestr ) assert m , 'unrecognized date format: ' + datestr year , month , day = m . group ( 'year' , 'month' , 'day' ) hour , minute , second , fraction = m . group ( 'hour' , 'minute' , 'second' , 'fraction' ) tz , tzhh , tzmm = m . group ( 'tz' , 'tzhh' , 'tz... | Parse a string that loosely fits ISO 8601 formatted date - time string |
55,866 | def ls ( self , rev , path , recursive = False , recursive_dirs = False , directory = False , report = ( ) ) : raise NotImplementedError | List directory or file |
55,867 | def log ( self , revrange = None , limit = None , firstparent = False , merges = None , path = None , follow = False ) : raise NotImplementedError | Get commit logs |
55,868 | def user_create ( self , cloudflare_email , cloudflare_pass , unique_id = None ) : params = { 'act' : 'user_create' , 'cloudflare_email' : cloudflare_email , 'cloudflare_pass' : cloudflare_pass } if unique_id : params [ 'unique_id' ] = unique_id return self . _request ( params ) | Create new cloudflare user with selected email and id . Optionally also select unique_id which can be then used to get user information . |
55,869 | def zone_set ( self , user_key , zone_name , resolve_to , subdomains ) : params = { 'act' : 'zone_set' , 'user_key' : user_key , 'zone_name' : zone_name , 'resolve_to' : resolve_to , 'subdomains' : subdomains , } return self . _request ( params ) | Create new zone for user associated with this user_key . |
55,870 | def full_zone_set ( self , user_key , zone_name ) : params = { 'act' : 'full_zone_set' , 'user_key' : user_key , 'zone_name' : zone_name , } return self . _request ( params ) | Create new zone and all subdomains for user associated with this user_key . |
55,871 | def user_lookup ( self , cloudflare_email = None , unique_id = None ) : if not cloudflare_email and not unique_id : raise KeyError ( 'Either cloudflare_email or unique_id must be present' ) params = { 'act' : 'user_lookup' } if cloudflare_email : params [ 'cloudflare_email' ] = cloudflare_email else : params [ 'unique_... | Lookup user data based on either his cloudflare_email or his unique_id . |
55,872 | def user_auth ( self , cloudflare_email = None , cloudflare_pass = None , unique_id = None ) : if not ( cloudflare_email and cloudflare_pass ) and not unique_id : raise KeyError ( 'Either cloudflare_email and cloudflare_pass or unique_id must be present' ) params = { 'act' : 'user_auth' } if cloudflare_email and cloudf... | Get user_key based on either his email and password or unique_id . |
55,873 | def zone_list ( self , user_key , limit = 100 , offset = 0 , zone_name = None , sub_id = None , zone_status = 'ALL' , sub_status = 'ALL' , ) : if zone_status not in [ 'V' , 'D' , 'ALL' ] : raise ValueError ( 'zone_status has to be V, D or ALL' ) if sub_status not in [ 'V' , 'CNL' , 'ALL' ] : raise ValueError ( 'sub_sta... | List zones for a user . |
55,874 | def attr_exists ( self , attr ) : gen = self . attr_gen ( attr ) n_instances = len ( list ( gen ) ) if n_instances > 0 : return True else : return False | Returns True if at least on instance of the attribute is found |
55,875 | def datasets ( self ) : HiisiHDF . _clear_cache ( ) self . visititems ( HiisiHDF . _is_dataset ) return HiisiHDF . CACHE [ 'dataset_paths' ] | Method returns a list of dataset paths . |
55,876 | def create_from_filedict ( self , filedict ) : if self . mode in [ 'r+' , 'w' , 'w-' , 'x' , 'a' ] : for h5path , path_content in filedict . iteritems ( ) : if path_content . has_key ( 'DATASET' ) : if h5path in self : for key , value in path_content . iteritems ( ) : if key != 'DATASET' : self [ h5path ] . attrs [ key... | Creates h5 file from dictionary containing the file structure . Filedict is a regular dictinary whose keys are hdf5 paths and whose values are dictinaries containing the metadata and datasets . Metadata is given as normal key - value - pairs and dataset arrays are given using DATASET key . Datasets must be numpy arrays... |
55,877 | def search ( self , attr , value , tolerance = 0 ) : found_paths = [ ] gen = self . attr_gen ( attr ) for path_attr_pair in gen : if isinstance ( path_attr_pair . value , str ) : type_name = 'str' else : type_name = path_attr_pair . value . dtype . name if 'int' in type_name or 'float' in type_name : if abs ( path_attr... | Find paths with a key value match |
55,878 | def _extractReporterIons ( ionArrays , reporterMz , mzTolerance ) : reporterIons = { 'mz' : [ ] , 'i' : [ ] } for reporterMzValue in reporterMz : limHi = reporterMzValue * ( 1 + mzTolerance ) limLo = reporterMzValue * ( 1 - mzTolerance ) loPos = bisect . bisect_left ( ionArrays [ 'mz' ] , limLo ) upPos = bisect . bisec... | Find and a list of reporter ions and return mz and intensity values . |
55,879 | def _correctIsotopeImpurities ( matrix , intensities ) : correctedIntensities , _ = scipy . optimize . nnls ( matrix , intensities ) return correctedIntensities | Corrects observed reporter ion intensities for isotope impurities . |
55,880 | def _normalizeImpurityMatrix ( matrix ) : newMatrix = list ( ) for line in matrix : total = sum ( line ) if total != 0 : newMatrix . append ( [ i / total for i in line ] ) else : newMatrix . append ( line ) return newMatrix | Normalize each row of the matrix that the sum of the row equals 1 . |
55,881 | def _padImpurityMatrix ( matrix , preChannels , postChannels ) : extendedMatrix = list ( ) lastMatrixI = len ( matrix ) - 1 for i , line in enumerate ( matrix ) : prePadding = itertools . repeat ( 0. , i ) postPadding = itertools . repeat ( 0. , lastMatrixI - i ) newLine = list ( itertools . chain ( prePadding , line ,... | Align the values of an isotope impurity matrix and fill up with 0 . |
55,882 | def _processImpurityMatrix ( self ) : processedMatrix = _normalizeImpurityMatrix ( self . impurityMatrix ) processedMatrix = _padImpurityMatrix ( processedMatrix , self . matrixPreChannels , self . matrixPostChannels ) processedMatrix = _transposeMatrix ( processedMatrix ) return processedMatrix | Process the impurity matrix so that it can be used to correct observed reporter intensities . |
55,883 | def exception ( message ) : def decorator ( method ) : @ wraps ( method ) def wrapper ( self , * args , ** kwargs ) : if self . messages : kwargs [ 'message' ] = args [ 0 ] if args else kwargs . get ( 'message' , message ) else : kwargs [ 'message' ] = None kwargs [ 'prefix' ] = self . prefix kwargs [ 'statsd' ] = self... | Exception method convenience wrapper . |
55,884 | def to_dict ( self ) : val = dict ( self . payload or ( ) ) if self . message : val [ 'message' ] = self . message return val | Convert Exception class to a Python dictionary . |
55,885 | def init_app ( self , app , config = None , statsd = None ) : if config is not None : self . config = config elif self . config is None : self . config = app . config self . messages = self . config . get ( 'EXCEPTION_MESSAGE' , True ) self . prefix = self . config . get ( 'EXCEPTION_PREFIX' , DEFAULT_PREFIX ) self . s... | Init Flask Extension . |
55,886 | def wrap_node ( self , node , options ) : if 'celery_task' in options : return options [ 'celery_task' ] ( node ) return self . celery_task ( node ) | \ celery registers tasks by decorating them and so do we so the user can pass a celery task and we ll wrap our code with theirs in a nice package celery can execute . |
55,887 | def checkpoint ( key = 0 , unpickler = pickle . load , pickler = pickle . dump , work_dir = gettempdir ( ) , refresh = False ) : def decorator ( func ) : def wrapped ( * args , ** kwargs ) : if isinstance ( key , str ) : save_file = os . path . join ( work_dir , key ) elif isinstance ( key , Template ) : save_file = os... | A utility decorator to save intermediate results of a function . It is the caller s responsibility to specify a key naming scheme such that the output of each function call with different arguments is stored in a separate file . |
55,888 | def run ( ) : parser = argparse . ArgumentParser ( prog = 'python -m braillegraph' , description = 'Print a braille bar graph of the given integers.' ) parser . add_argument ( '-n' , '--no-newline' , action = 'store_const' , dest = 'end' , const = '' , default = None , help = 'do not print the trailing newline characte... | Display the arguments as a braille graph on standard output . |
55,889 | def _rnd_date ( start , end ) : return date . fromordinal ( random . randint ( start . toordinal ( ) , end . toordinal ( ) ) ) | Internal random date generator . |
55,890 | def rnd_date_list_high_performance ( size , start = date ( 1970 , 1 , 1 ) , end = None , ** kwargs ) : if end is None : end = date . today ( ) start_days = to_ordinal ( parser . parse_datetime ( start ) ) end_days = to_ordinal ( parser . parse_datetime ( end ) ) _assert_correct_start_end ( start_days , end_days ) if ha... | Generate mass random date . |
55,891 | def day_interval ( year , month , day , milliseconds = False , return_string = False ) : if milliseconds : delta = timedelta ( milliseconds = 1 ) else : delta = timedelta ( seconds = 1 ) start = datetime ( year , month , day ) end = datetime ( year , month , day ) + timedelta ( days = 1 ) - delta if not return_string :... | Return a start datetime and end datetime of a day . |
55,892 | def month_interval ( year , month , milliseconds = False , return_string = False ) : if milliseconds : delta = timedelta ( milliseconds = 1 ) else : delta = timedelta ( seconds = 1 ) if month == 12 : start = datetime ( year , month , 1 ) end = datetime ( year + 1 , 1 , 1 ) - delta else : start = datetime ( year , month... | Return a start datetime and end datetime of a month . |
55,893 | def year_interval ( year , milliseconds = False , return_string = False ) : if milliseconds : delta = timedelta ( milliseconds = 1 ) else : delta = timedelta ( seconds = 1 ) start = datetime ( year , 1 , 1 ) end = datetime ( year + 1 , 1 , 1 ) - delta if not return_string : return start , end else : return str ( start ... | Return a start datetime and end datetime of a year . |
55,894 | def get_milestone ( self , title ) : if not title : return GithubObject . NotSet if not hasattr ( self , '_milestones' ) : self . _milestones = { m . title : m for m in self . repo . get_milestones ( ) } milestone = self . _milestones . get ( title ) if not milestone : milestone = self . repo . create_milestone ( title... | given the title as str looks for an existing milestone or create a new one and return the object |
55,895 | def get_assignee ( self , login ) : if not login : return GithubObject . NotSet if not hasattr ( self , '_assignees' ) : self . _assignees = { c . login : c for c in self . repo . get_assignees ( ) } if login not in self . _assignees : print ( "{} doesn't belong to this repo. This issue won't be assigned." . format ( l... | given the user login looks for a user in assignee list of the repo and return it if was found . |
55,896 | def sender ( self , issues ) : for issue in issues : state = self . get_state ( issue . state ) if issue . number : try : gh_issue = self . repo . get_issue ( issue . number ) original_state = gh_issue . state if original_state == state : action = 'Updated' elif original_state == 'closed' : action = 'Reopened' else : a... | push a list of issues to github |
55,897 | def wrap_node ( self , node , options ) : job_kwargs = { 'queue' : options . get ( 'queue' , 'default' ) , 'connection' : options . get ( 'connection' , self . redis_connection ) , 'timeout' : options . get ( 'timeout' , None ) , 'result_ttl' : options . get ( 'result_ttl' , 500 ) , } return job ( ** job_kwargs ) ( nod... | we have the option to construct nodes here so we can use different queues for nodes without having to have different queue objects . |
55,898 | def create_albaran_automatic ( pk , list_lines ) : line_bd = SalesLineAlbaran . objects . filter ( line_order__pk__in = list_lines ) . values_list ( 'line_order__pk' ) if line_bd . count ( ) == 0 or len ( list_lines ) != len ( line_bd [ 0 ] ) : if line_bd . count ( ) != 0 : for x in line_bd [ 0 ] : list_lines . pop ( l... | creamos de forma automatica el albaran |
55,899 | def create_invoice_from_albaran ( pk , list_lines ) : context = { } if list_lines : new_list_lines = [ x [ 0 ] for x in SalesLineAlbaran . objects . values_list ( 'line_order__pk' ) . filter ( pk__in = [ int ( x ) for x in list_lines ] ) . exclude ( invoiced = True ) ] if new_list_lines : lo = SalesLineOrder . objects ... | la pk y list_lines son de albaranes necesitamos la info de las lineas de pedidos |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.