idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
237,300 | def inet_ntop ( af , addr ) : if af == socket . AF_INET : return inet_ntoa ( addr ) elif af == socket . AF_INET6 : if len ( addr ) != 16 : raise Exception ( "Illegal syntax for IP address" ) parts = [ ] for left in [ 0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 ] : try : value = struct . unpack ( "!H" , addr [ left : left + 2 ] ) ... | Convert an IP address from binary form into text represenation |
237,301 | def strand ( s1 , s2 ) : return "" . join ( map ( lambda x , y : chr ( ord ( x ) & ord ( y ) ) , s1 , s2 ) ) | Returns the binary AND of the 2 provided strings s1 and s2 . s1 and s2 must be of same length . |
237,302 | def pkcs_mgf1 ( mgfSeed , maskLen , h ) : if not h in _hashFuncParams : warning ( "pkcs_mgf1: invalid hash (%s) provided" ) return None hLen = _hashFuncParams [ h ] [ 0 ] hFunc = _hashFuncParams [ h ] [ 1 ] if maskLen > 2 ** 32 * hLen : warning ( "pkcs_mgf1: maskLen > 2**32 * hLen" ) return None T = "" maxCounter = mat... | Implements generic MGF1 Mask Generation function as described in Appendix B . 2 . 1 of RFC 3447 . The hash function is passed by name . valid values are md2 md4 md5 sha1 tls sha256 sha384 and sha512 . Returns None on error . |
237,303 | def create_temporary_ca_path ( anchor_list , folder ) : try : if not os . path . isdir ( folder ) : os . makedirs ( folder ) except : return None l = len ( anchor_list ) if l == 0 : return None fmtstr = "%%0%sd.pem" % math . ceil ( math . log ( l , 10 ) ) i = 0 try : for a in anchor_list : fname = os . path . join ( fo... | Create a CA path folder as defined in OpenSSL terminology by storing all certificates in anchor_list list in PEM format under provided folder and then creating the associated links using the hash as usually done by c_rehash . |
237,304 | def _rsadp ( self , c ) : n = self . modulus if type ( c ) is int : c = long ( c ) if type ( c ) is not long or c > n - 1 : warning ( "Key._rsaep() expects a long between 0 and n-1" ) return None return self . key . decrypt ( c ) | Internal method providing raw RSA decryption i . e . simple modular exponentiation of the given ciphertext representative c a long between 0 and n - 1 . |
237,305 | def fragment ( pkt , fragsize = 1480 ) : fragsize = ( fragsize + 7 ) // 8 * 8 lst = [ ] for p in pkt : s = bytes ( p [ IP ] . payload ) nb = ( len ( s ) + fragsize - 1 ) // fragsize for i in range ( nb ) : q = p . copy ( ) del q [ IP ] . payload del q [ IP ] . chksum del q [ IP ] . len if i == nb - 1 : q [ IP ] . flags... | Fragment a big IP datagram |
237,306 | def parse_version ( str_ ) : v = re . findall ( r"\d+.\d+.\d+" , str_ ) if v : return v [ 0 ] else : print ( "cannot parse string {}" . format ( str_ ) ) raise KeyError | Parses the program s version from a python variable declaration . |
237,307 | def make_session ( username = None , password = None , bearer_token = None , extra_headers_dict = None ) : if password is None and bearer_token is None : logger . error ( "No authentication information provided; " "please check your object" ) raise KeyError session = requests . Session ( ) session . trust_env = False h... | Creates a Requests Session for use . Accepts a bearer token for premiums users and will override username and password information if present . |
237,308 | def retry ( func ) : def retried_func ( * args , ** kwargs ) : max_tries = 3 tries = 0 while True : try : resp = func ( * args , ** kwargs ) except requests . exceptions . ConnectionError as exc : exc . msg = "Connection error for session; exiting" raise exc except requests . exceptions . HTTPError as exc : exc . msg =... | Decorator to handle API retries and exceptions . Defaults to three retries . |
237,309 | def request ( session , url , rule_payload , ** kwargs ) : if isinstance ( rule_payload , dict ) : rule_payload = json . dumps ( rule_payload ) logger . debug ( "sending request" ) result = session . post ( url , data = rule_payload , ** kwargs ) return result | Executes a request with the given payload and arguments . |
237,310 | def collect_results ( rule , max_results = 500 , result_stream_args = None ) : if result_stream_args is None : logger . error ( "This function requires a configuration dict for the " "inner ResultStream object." ) raise KeyError rs = ResultStream ( rule_payload = rule , max_results = max_results , ** result_stream_args... | Utility function to quickly get a list of tweets from a ResultStream without keeping the object around . Requires your args to be configured prior to using . |
237,311 | def stream ( self ) : self . init_session ( ) self . check_counts ( ) self . execute_request ( ) self . stream_started = True while True : for tweet in self . current_tweets : if self . total_results >= self . max_results : break yield self . _tweet_func ( tweet ) self . total_results += 1 if self . next_token and self... | Main entry point for the data from the API . Will automatically paginate through the results via the next token and return up to max_results tweets or up to max_requests API calls whichever is lower . |
237,312 | def init_session ( self ) : if self . session : self . session . close ( ) self . session = make_session ( self . username , self . password , self . bearer_token , self . extra_headers_dict ) | Defines a session object for passing requests . |
237,313 | def check_counts ( self ) : if "counts" in re . split ( "[/.]" , self . endpoint ) : logger . info ( "disabling tweet parsing due to counts API usage" ) self . _tweet_func = lambda x : x | Disables tweet parsing if the count API is used . |
237,314 | def execute_request ( self ) : if self . n_requests % 20 == 0 and self . n_requests > 1 : logger . info ( "refreshing session" ) self . init_session ( ) resp = request ( session = self . session , url = self . endpoint , rule_payload = self . rule_payload ) self . n_requests += 1 ResultStream . session_request_counter ... | Sends the request to the API and parses the json response . Makes some assumptions about the session length and sets the presence of a next token . |
237,315 | def gen_rule_payload ( pt_rule , results_per_call = None , from_date = None , to_date = None , count_bucket = None , tag = None , stringify = True ) : pt_rule = ' ' . join ( pt_rule . split ( ) ) payload = { "query" : pt_rule } if results_per_call is not None and isinstance ( results_per_call , int ) is True : payload ... | Generates the dict or json payload for a PowerTrack rule . |
237,316 | def gen_params_from_config ( config_dict ) : if config_dict . get ( "count_bucket" ) : logger . warning ( "change your endpoint to the count endpoint; this is " "default behavior when the count bucket " "field is defined" ) endpoint = change_to_count_endpoint ( config_dict . get ( "endpoint" ) ) else : endpoint = confi... | Generates parameters for a ResultStream from a dictionary . |
237,317 | def infer_endpoint ( rule_payload ) : bucket = ( rule_payload if isinstance ( rule_payload , dict ) else json . loads ( rule_payload ) ) . get ( "bucket" ) return "counts" if bucket else "search" | Infer which endpoint should be used for a given rule payload . |
237,318 | def validate_count_api ( rule_payload , endpoint ) : rule = ( rule_payload if isinstance ( rule_payload , dict ) else json . loads ( rule_payload ) ) bucket = rule . get ( 'bucket' ) counts = set ( endpoint . split ( "/" ) ) & { "counts.json" } if len ( counts ) == 0 : if bucket is not None : msg = ( ) logger . error (... | Ensures that the counts api is set correctly in a payload . |
237,319 | def partition ( iterable , chunk_size , pad_none = False ) : args = [ iter ( iterable ) ] * chunk_size if not pad_none : return zip ( * args ) else : return it . zip_longest ( * args ) | adapted from Toolz . Breaks an iterable into n iterables up to the certain chunk size padding with Nones if availble . |
237,320 | def write_ndjson ( filename , data_iterable , append = False , ** kwargs ) : write_mode = "ab" if append else "wb" logger . info ( "writing to file {}" . format ( filename ) ) with codecs . open ( filename , write_mode , "utf-8" ) as outfile : for item in data_iterable : outfile . write ( json . dumps ( item ) + "\n" )... | Generator that writes newline - delimited json to a file and returns items from an iterable . |
237,321 | def write_result_stream ( result_stream , filename_prefix = None , results_per_file = None , ** kwargs ) : if isinstance ( result_stream , types . GeneratorType ) : stream = result_stream else : stream = result_stream . stream ( ) file_time_formatter = "%Y-%m-%dT%H_%M_%S" if filename_prefix is None : filename_prefix = ... | Wraps a ResultStream object to save it to a file . This function will still return all data from the result stream as a generator that wraps the write_ndjson method . |
237,322 | def _load_yaml_credentials ( filename = None , yaml_key = None ) : try : with open ( os . path . expanduser ( filename ) ) as f : search_creds = yaml . safe_load ( f ) [ yaml_key ] except FileNotFoundError : logger . error ( "cannot read file {}" . format ( filename ) ) search_creds = { } except KeyError : logger . err... | Loads and parses credentials in a YAML file . Catches common exceptions and returns an empty dict on error which will be handled downstream . |
237,323 | def _generate_bearer_token ( consumer_key , consumer_secret ) : data = [ ( 'grant_type' , 'client_credentials' ) ] resp = requests . post ( OAUTH_ENDPOINT , data = data , auth = ( consumer_key , consumer_secret ) ) logger . warning ( "Grabbing bearer token from OAUTH" ) if resp . status_code >= 400 : logger . error ( r... | Return the bearer token for a given pair of consumer key and secret values . |
237,324 | def fi_business_id ( business_id ) : if not business_id or not re . match ( business_id_pattern , business_id ) : return False factors = [ 7 , 9 , 10 , 5 , 8 , 4 , 2 ] numbers = map ( int , business_id [ : 7 ] ) checksum = int ( business_id [ 8 ] ) sum_ = sum ( f * n for f , n in zip ( factors , numbers ) ) modulo = su... | Validate a Finnish Business ID . |
237,325 | def fi_ssn ( ssn , allow_temporal_ssn = True ) : if not ssn : return False result = re . match ( ssn_pattern , ssn ) if not result : return False gd = result . groupdict ( ) checksum = int ( gd [ 'date' ] + gd [ 'serial' ] ) return ( int ( gd [ 'serial' ] ) >= 2 and ( allow_temporal_ssn or int ( gd [ 'serial' ] ) <= 89... | Validate a Finnish Social Security Number . |
237,326 | def modcheck ( value ) : rearranged = value [ 4 : ] + value [ : 4 ] converted = [ char_value ( char ) for char in rearranged ] integerized = int ( '' . join ( [ str ( i ) for i in converted ] ) ) return ( integerized % 97 == 1 ) | Check if the value string passes the mod97 - test . |
237,327 | def func_args_as_dict ( func , args , kwargs ) : if six . PY2 : _getargspec = inspect . getargspec else : _getargspec = inspect . getfullargspec arg_names = list ( OrderedDict . fromkeys ( itertools . chain ( _getargspec ( func ) [ 0 ] , kwargs . keys ( ) ) ) ) return OrderedDict ( list ( six . moves . zip ( arg_names ... | Return given function s positional and key value arguments as an ordered dictionary . |
237,328 | def validator ( func , * args , ** kwargs ) : def wrapper ( func , * args , ** kwargs ) : value = func ( * args , ** kwargs ) if not value : return ValidationFailure ( func , func_args_as_dict ( func , args , kwargs ) ) return True return decorator ( wrapper , func ) | A decorator that makes given function validator . |
237,329 | def length ( value , min = None , max = None ) : if ( min is not None and min < 0 ) or ( max is not None and max < 0 ) : raise AssertionError ( '`min` and `max` need to be greater than zero.' ) return between ( len ( value ) , min = min , max = max ) | Return whether or not the length of given string is within a specified range . |
237,330 | def url ( value , public = False ) : result = pattern . match ( value ) if not public : return result return result and not any ( ( result . groupdict ( ) . get ( key ) for key in ( 'private_ip' , 'private_host' ) ) ) | Return whether or not given value is a valid URL . |
237,331 | def ipv4 ( value ) : groups = value . split ( '.' ) if len ( groups ) != 4 or any ( not x . isdigit ( ) for x in groups ) : return False return all ( 0 <= int ( part ) < 256 for part in groups ) | Return whether or not given value is a valid IP version 4 address . |
237,332 | def post_report ( coverage , args ) : response = requests . post ( URL , files = { 'json_file' : json . dumps ( coverage ) } , verify = ( not args . skip_ssl_verify ) ) try : result = response . json ( ) except ValueError : result = { 'error' : 'Failure to submit data. ' 'Response [%(status)s]: %(text)s' % { 'status' :... | Post coverage report to coveralls . io . |
237,333 | def is_source_file ( args , filepath ) : if args . extension : return os . path . splitext ( filepath ) [ 1 ] in args . extension else : return os . path . splitext ( filepath ) [ 1 ] in _CPP_EXTENSIONS | Returns true if it is a C ++ source file . |
237,334 | def exclude_paths ( args ) : results = [ ] if args . exclude : for excl_path in args . exclude : results . append ( os . path . abspath ( os . path . join ( args . root , excl_path ) ) ) return results | Returns the absolute paths for excluded path . |
237,335 | def create_exclude_rules ( args ) : global _cached_exclude_rules if _cached_exclude_rules is not None : return _cached_exclude_rules rules = [ ] for excl_path in args . exclude : abspath = os . path . abspath ( os . path . join ( args . root , excl_path ) ) rules . append ( ( abspath , True ) ) for incl_path in args . ... | Creates the exlude rules |
237,336 | def is_excluded_path ( args , filepath ) : for regexp_exclude_path in args . regexp : if re . match ( regexp_exclude_path , filepath ) : return True abspath = os . path . abspath ( filepath ) if args . include : out_of_include_dirs = True for incl_path in args . include : absolute_include_path = os . path . abspath ( o... | Returns true if the filepath is under the one of the exclude path . |
237,337 | def filter_dirs ( root , dirs , excl_paths ) : filtered_dirs = [ ] for dirpath in dirs : abspath = os . path . abspath ( os . path . join ( root , dirpath ) ) if os . path . basename ( abspath ) in _SKIP_DIRS : continue if abspath not in excl_paths : filtered_dirs . append ( dirpath ) return filtered_dirs | Filter directory paths based on the exclusion rules defined in excl_paths . |
237,338 | def parse_gcov_file ( args , fobj , filename ) : coverage = [ ] ignoring = False for line in fobj : report_fields = line . decode ( 'utf-8' , 'replace' ) . split ( ':' , 2 ) if len ( report_fields ) == 1 : continue line_num = report_fields [ 1 ] . strip ( ) if line_num == '' : continue cov_num = report_fields [ 0 ] . s... | Parses the content of . gcov file |
237,339 | def parse_lcov_file_info ( args , filepath , line_iter , line_coverage_re , file_end_string ) : coverage = [ ] lines_covered = [ ] for line in line_iter : if line != "end_of_record" : line_coverage_match = line_coverage_re . match ( line ) if line_coverage_match : line_no = line_coverage_match . group ( 1 ) cov_count =... | Parse the file content in lcov info file |
237,340 | def combine_reports ( original , new ) : if original is None : return new report = { } report [ 'name' ] = original [ 'name' ] report [ 'source_digest' ] = original [ 'source_digest' ] coverage = [ ] for original_num , new_num in zip ( original [ 'coverage' ] , new [ 'coverage' ] ) : if original_num is None : coverage ... | Combines two gcov reports for a file into one by adding the number of hits on each line |
237,341 | def collect_non_report_files ( args , discovered_files ) : excl_paths = exclude_paths ( args ) abs_root = os . path . abspath ( args . root ) non_report_files = [ ] for root , dirs , files in os . walk ( args . root , followlinks = args . follow_symlinks ) : dirs [ : ] = filter_dirs ( root , dirs , excl_paths ) for fil... | Collects the source files that have no coverage reports . |
237,342 | def parse_yaml_config ( args ) : try : import yaml except ImportError : yaml = None yml = { } try : with open ( args . coveralls_yaml , 'r' ) as fp : if not yaml : raise SystemExit ( 'PyYAML is required for parsing configuration' ) yml = yaml . load ( fp ) except IOError : pass yml = yml or { } return yml | Parse yaml config |
237,343 | def run ( ) : import json import os import sys from . import coverage , report args = coverage . create_args ( sys . argv [ 1 : ] ) if args . verbose : print ( 'encodings: {}' . format ( args . encodings ) ) yml = parse_yaml_config ( args ) if not args . repo_token : args . repo_token = yml . get ( 'repo_token' , '' ) ... | Run cpp coverage . |
237,344 | def gitrepo ( cwd ) : repo = Repository ( cwd ) if not repo . valid ( ) : return { } return { 'head' : { 'id' : repo . gitlog ( '%H' ) , 'author_name' : repo . gitlog ( '%aN' ) , 'author_email' : repo . gitlog ( '%ae' ) , 'committer_name' : repo . gitlog ( '%cN' ) , 'committer_email' : repo . gitlog ( '%ce' ) , 'messag... | Return hash of Git data that can be used to display more information to users . |
237,345 | def _verify ( function ) : def wrapped ( pin , * args , ** kwargs ) : pin = int ( pin ) if pin not in _open : ppath = gpiopath ( pin ) if not os . path . exists ( ppath ) : log . debug ( "Creating Pin {0}" . format ( pin ) ) with _export_lock : with open ( pjoin ( gpio_root , 'export' ) , 'w' ) as f : _write ( f , pin ... | decorator to ensure pin is properly set up |
237,346 | def set ( pin , value ) : if value is LOW : value = 0 value = int ( bool ( value ) ) log . debug ( "Write {0}: {1}" . format ( pin , value ) ) f = _open [ pin ] . value _write ( f , value ) | set the pin value to 0 or 1 |
237,347 | def end ( self ) : _checkErr ( 'vend' , _C . Vfinish ( self . _hdf_inst . _id ) , "cannot terminate V interface" ) self . _hdf_inst = None | Close the V interface . |
237,348 | def attach ( self , num_name , write = 0 ) : if isinstance ( num_name , bytes ) : num = self . find ( num_name ) else : num = num_name vg_id = _C . Vattach ( self . _hdf_inst . _id , num , write and 'w' or 'r' ) _checkErr ( 'vattach' , vg_id , "cannot attach Vgroup" ) return VG ( self , vg_id ) | Open an existing vgroup given its name or its reference number or create a new vgroup returning a VG instance for that vgroup . |
237,349 | def create ( self , name ) : vg = self . attach ( - 1 , 1 ) vg . _name = name return vg | Create a new vgroup and assign it a name . |
237,350 | def find ( self , name ) : refnum = _C . Vfind ( self . _hdf_inst . _id , name ) if not refnum : raise HDF4Error ( "vgroup not found" ) return refnum | Find a vgroup given its name returning its reference number if found . |
237,351 | def findclass ( self , name ) : refnum = _C . Vfindclass ( self . _hdf_inst . _id , name ) if not refnum : raise HDF4Error ( "vgroup not found" ) return refnum | Find a vgroup given its class name returning its reference number if found . |
237,352 | def delete ( self , num_name ) : try : vg = self . attach ( num_name , 1 ) except HDF4Error as msg : raise HDF4Error ( "delete: no such vgroup" ) refnum = vg . _refnum vg . detach ( ) _checkErr ( 'delete' , _C . Vdelete ( self . _hdf_inst . _id , refnum ) , "error deleting vgroup" ) | Delete from the HDF file the vgroup identified by its reference number or its name . |
237,353 | def getid ( self , ref ) : num = _C . Vgetid ( self . _hdf_inst . _id , ref ) _checkErr ( 'getid' , num , "bad arguments or last vgroup reached" ) return num | Obtain the reference number of the vgroup following the vgroup with the given reference number . |
237,354 | def insert ( self , inst ) : if isinstance ( inst , VD ) : id = inst . _id elif isinstance ( inst , VG ) : id = inst . _id else : raise HDF4Error ( "insrt: bad argument" ) index = _C . Vinsert ( self . _id , id ) _checkErr ( 'insert' , index , "cannot insert in vgroup" ) return index | Insert a vdata or a vgroup in the vgroup . |
237,355 | def add ( self , tag , ref ) : n = _C . Vaddtagref ( self . _id , tag , ref ) _checkErr ( 'addtagref' , n , 'invalid arguments' ) return n | Add to the vgroup an object identified by its tag and reference number . |
237,356 | def delete ( self , tag , ref ) : _checkErr ( 'delete' , _C . Vdeletetagref ( self . _id , tag , ref ) , "error deleting member" ) | Delete from the vgroup the member identified by its tag and reference number . |
237,357 | def tagref ( self , index ) : status , tag , ref = _C . Vgettagref ( self . _id , index ) _checkErr ( 'tagref' , status , "illegal arguments" ) return tag , ref | Get the tag and reference number of a vgroup member given the index number of that member . |
237,358 | def tagrefs ( self ) : n = self . _nmembers ret = [ ] if n : tags = _C . array_int32 ( n ) refs = _C . array_int32 ( n ) k = _C . Vgettagrefs ( self . _id , tags , refs , n ) _checkErr ( 'tagrefs' , k , "error getting tags and refs" ) for m in xrange ( k ) : ret . append ( ( tags [ m ] , refs [ m ] ) ) return ret | Get the tags and reference numbers of all the vgroup members . |
237,359 | def inqtagref ( self , tag , ref ) : return _C . Vinqtagref ( self . _id , tag , ref ) | Determines if an object identified by its tag and reference number belongs to the vgroup . |
237,360 | def nrefs ( self , tag ) : n = _C . Vnrefs ( self . _id , tag ) _checkErr ( 'nrefs' , n , "bad arguments" ) return n | Determine the number of tags of a given type in a vgroup . |
237,361 | def attrinfo ( self ) : dic = { } for n in range ( self . _nattrs ) : att = self . attr ( n ) name , type , order , size = att . info ( ) dic [ name ] = ( type , order , att . get ( ) , size ) return dic | Return info about all the vgroup attributes . |
237,362 | def findattr ( self , name ) : try : att = self . attr ( name ) if att . _index is None : att = None except HDF4Error : att = None return att | Search the vgroup for a given attribute . |
237,363 | def index ( self ) : self . _index = _C . SDfindattr ( self . _obj . _id , self . _name ) _checkErr ( 'find' , self . _index , 'illegal attribute name' ) return self . _index | Retrieve the attribute index number . |
237,364 | def end ( self ) : status = _C . SDend ( self . _id ) _checkErr ( 'end' , status , "cannot execute" ) self . _id = None | End access to the SD interface and close the HDF file . |
237,365 | def info ( self ) : status , n_datasets , n_file_attrs = _C . SDfileinfo ( self . _id ) _checkErr ( 'info' , status , "cannot execute" ) return n_datasets , n_file_attrs | Retrieve information about the SD interface . |
237,366 | def nametoindex ( self , sds_name ) : sds_idx = _C . SDnametoindex ( self . _id , sds_name ) _checkErr ( 'nametoindex' , sds_idx , 'non existent SDS' ) return sds_idx | Return the index number of a dataset given the dataset name . |
237,367 | def reftoindex ( self , sds_ref ) : sds_idx = _C . SDreftoindex ( self . _id , sds_ref ) _checkErr ( 'reftoindex' , sds_idx , 'illegal SDS ref number' ) return sds_idx | Returns the index number of a dataset given the dataset reference number . |
237,368 | def setfillmode ( self , fill_mode ) : if not fill_mode in [ SDC . FILL , SDC . NOFILL ] : raise HDF4Error ( "bad fill mode" ) old_mode = _C . SDsetfillmode ( self . _id , fill_mode ) _checkErr ( 'setfillmode' , old_mode , 'cannot execute' ) return old_mode | Set the fill mode for all the datasets in the file . |
237,369 | def select ( self , name_or_index ) : if isinstance ( name_or_index , type ( 1 ) ) : idx = name_or_index else : try : idx = self . nametoindex ( name_or_index ) except HDF4Error : raise HDF4Error ( "select: non-existent dataset" ) id = _C . SDselect ( self . _id , idx ) _checkErr ( 'select' , id , "cannot execute" ) re... | Locate a dataset . |
237,370 | def attributes ( self , full = 0 ) : nsds , natts = self . info ( ) res = { } for n in range ( natts ) : a = self . attr ( n ) name , aType , nVal = a . info ( ) if full : res [ name ] = ( a . get ( ) , a . index ( ) , aType , nVal ) else : res [ name ] = a . get ( ) return res | Return a dictionnary describing every global attribute attached to the SD interface . |
237,371 | def datasets ( self ) : nDs = self . info ( ) [ 0 ] res = { } for n in range ( nDs ) : v = self . select ( n ) vName , vRank , vLen , vType , vAtt = v . info ( ) if vRank < 2 : vLen = [ vLen ] dimNames = [ ] dimLengths = [ ] for dimNum in range ( vRank ) : d = v . dim ( dimNum ) dimNames . append ( d . info ( ) [ 0 ] )... | Return a dictionnary describing all the file datasets . |
237,372 | def endaccess ( self ) : status = _C . SDendaccess ( self . _id ) _checkErr ( 'endaccess' , status , "cannot execute" ) self . _id = None | Terminates access to the SDS . |
237,373 | def dim ( self , dim_index ) : id = _C . SDgetdimid ( self . _id , dim_index ) _checkErr ( 'dim' , id , 'invalid SDS identifier or dimension index' ) return SDim ( self , id , dim_index ) | Get an SDim instance given a dimension index number . |
237,374 | def get ( self , start = None , count = None , stride = None ) : try : sds_name , rank , dim_sizes , data_type , n_attrs = self . info ( ) if isinstance ( dim_sizes , type ( 1 ) ) : dim_sizes = [ dim_sizes ] except HDF4Error : raise HDF4Error ( 'get : cannot execute' ) if start is None : start = [ 0 ] * rank elif isins... | Read data from the dataset . |
237,375 | def set ( self , data , start = None , count = None , stride = None ) : try : sds_name , rank , dim_sizes , data_type , n_attrs = self . info ( ) if isinstance ( dim_sizes , type ( 1 ) ) : dim_sizes = [ dim_sizes ] except HDF4Error : raise HDF4Error ( 'set : cannot execute' ) if start is None : start = [ 0 ] * rank eli... | Write data to the dataset . |
237,376 | def info ( self ) : buf = _C . array_int32 ( _C . H4_MAX_VAR_DIMS ) status , sds_name , rank , data_type , n_attrs = _C . SDgetinfo ( self . _id , buf ) _checkErr ( 'info' , status , "cannot execute" ) dim_sizes = _array_to_ret ( buf , rank ) return sds_name , rank , dim_sizes , data_type , n_attrs | Retrieves information about the dataset . |
237,377 | def checkempty ( self ) : status , emptySDS = _C . SDcheckempty ( self . _id ) _checkErr ( 'checkempty' , status , 'invalid SDS identifier' ) return emptySDS | Determine whether the dataset is empty . |
237,378 | def ref ( self ) : sds_ref = _C . SDidtoref ( self . _id ) _checkErr ( 'idtoref' , sds_ref , 'illegal SDS identifier' ) return sds_ref | Get the reference number of the dataset . |
237,379 | def getcal ( self ) : status , cal , cal_error , offset , offset_err , data_type = _C . SDgetcal ( self . _id ) _checkErr ( 'getcal' , status , 'no calibration record' ) return cal , cal_error , offset , offset_err , data_type | Retrieve the SDS calibration coefficients . |
237,380 | def getdatastrs ( self ) : status , label , unit , format , coord_system = _C . SDgetdatastrs ( self . _id , 128 ) _checkErr ( 'getdatastrs' , status , 'cannot execute' ) return label , unit , format , coord_system | Retrieve the dataset standard string attributes . |
237,381 | def getrange ( self ) : try : sds_name , rank , dim_sizes , data_type , n_attrs = self . info ( ) except HDF4Error : raise HDF4Error ( 'getrange : invalid SDS identifier' ) n_values = 1 convert = _array_to_ret if data_type == SDC . CHAR8 : buf1 = _C . array_byte ( n_values ) buf2 = _C . array_byte ( n_values ) convert ... | Retrieve the dataset min and max values . |
237,382 | def setcal ( self , cal , cal_error , offset , offset_err , data_type ) : status = _C . SDsetcal ( self . _id , cal , cal_error , offset , offset_err , data_type ) _checkErr ( 'setcal' , status , 'cannot execute' ) | Set the dataset calibration coefficients . |
237,383 | def setdatastrs ( self , label , unit , format , coord_sys ) : status = _C . SDsetdatastrs ( self . _id , label , unit , format , coord_sys ) _checkErr ( 'setdatastrs' , status , 'cannot execute' ) | Set the dataset standard string type attributes . |
237,384 | def setfillvalue ( self , fill_val ) : try : sds_name , rank , dim_sizes , data_type , n_attrs = self . info ( ) except HDF4Error : raise HDF4Error ( 'setfillvalue : cannot execute' ) n_values = 1 if data_type == SDC . CHAR8 : buf = _C . array_byte ( n_values ) elif data_type in [ SDC . UCHAR8 , SDC . UINT8 ] : buf = _... | Set the dataset fill value . |
237,385 | def setrange ( self , min , max ) : try : sds_name , rank , dim_sizes , data_type , n_attrs = self . info ( ) except HDF4Error : raise HDF4Error ( 'setrange : cannot execute' ) n_values = 1 if data_type == SDC . CHAR8 : buf1 = _C . array_byte ( n_values ) buf2 = _C . array_byte ( n_values ) elif data_type in [ SDC . UC... | Set the dataset min and max values . |
237,386 | def getcompress ( self ) : status , comp_type , value , v2 , v3 , v4 , v5 = _C . _SDgetcompress ( self . _id ) _checkErr ( 'getcompress' , status , 'no compression' ) if comp_type == SDC . COMP_NONE : return ( comp_type , ) elif comp_type == SDC . COMP_SZIP : return comp_type , value , v2 , v3 , v4 , v5 else : return c... | Retrieves info about dataset compression type and mode . |
237,387 | def setcompress ( self , comp_type , value = 0 , v2 = 0 ) : status = _C . _SDsetcompress ( self . _id , comp_type , value , v2 ) _checkErr ( 'setcompress' , status , 'cannot execute' ) | Compresses the dataset using a specified compression method . |
237,388 | def setexternalfile ( self , filename , offset = 0 ) : status = _C . SDsetexternalfile ( self . _id , filename , offset ) _checkErr ( 'setexternalfile' , status , 'execution error' ) | Store the dataset data in an external file . |
237,389 | def dimensions ( self , full = 0 ) : nDims , dimLen = self . info ( ) [ 1 : 3 ] if isinstance ( dimLen , int ) : dimLen = [ dimLen ] unlim = self . isrecord ( ) res = { } for n in range ( nDims ) : d = self . dim ( n ) name , k , scaleType , nAtt = d . info ( ) length = dimLen [ n ] if full : res [ name ] = ( length , ... | Return a dictionnary describing every dataset dimension . |
237,390 | def info ( self ) : status , dim_name , dim_size , data_type , n_attrs = _C . SDdiminfo ( self . _id ) _checkErr ( 'info' , status , 'cannot execute' ) return dim_name , dim_size , data_type , n_attrs | Return info about the dimension instance . |
237,391 | def setname ( self , dim_name ) : status = _C . SDsetdimname ( self . _id , dim_name ) _checkErr ( 'setname' , status , 'cannot execute' ) | Set the dimension name . |
237,392 | def getscale ( self ) : status , dim_name , dim_size , data_type , n_attrs = _C . SDdiminfo ( self . _id ) _checkErr ( 'getscale' , status , 'cannot execute' ) if data_type == 0 : raise HDF4Error ( "no scale set on that dimension" ) if dim_size == 0 : dim_size = self . _sds . info ( ) [ 2 ] [ self . _index ] if data_ty... | Obtain the scale values along a dimension . |
237,393 | def setscale ( self , data_type , scale ) : try : n_values = len ( scale ) except : n_values = 1 info = self . _sds . info ( ) if info [ 1 ] == 1 : dim_size = info [ 2 ] else : dim_size = info [ 2 ] [ self . _index ] if n_values != dim_size : raise HDF4Error ( 'number of scale values (%d) does not match ' 'dimension si... | Initialize the scale values along the dimension . |
237,394 | def getstrs ( self ) : status , label , unit , format = _C . SDgetdimstrs ( self . _id , 128 ) _checkErr ( 'getstrs' , status , 'cannot execute' ) return label , unit , format | Retrieve the dimension standard string attributes . |
237,395 | def setstrs ( self , label , unit , format ) : status = _C . SDsetdimstrs ( self . _id , label , unit , format ) _checkErr ( 'setstrs' , status , 'cannot execute' ) | Set the dimension standard string attributes . |
237,396 | def attach ( self , num_name , write = 0 ) : mode = write and 'w' or 'r' if isinstance ( num_name , str ) : num = self . find ( num_name ) else : num = num_name vd = _C . VSattach ( self . _hdf_inst . _id , num , mode ) if vd < 0 : _checkErr ( 'attach' , vd , 'cannot attach vdata' ) return VD ( self , vd ) | Locate an existing vdata or create a new vdata in the HDF file returning a VD instance . |
237,397 | def create ( self , name , fields ) : try : vd = self . attach ( - 1 , 1 ) vd . _name = name allNames = [ ] for name , type , order in fields : vd . fdefine ( name , type , order ) allNames . append ( name ) vd . setfields ( * allNames ) return vd except HDF4Error as msg : raise HDF4Error ( "error creating vdata (%s)" ... | Create a new vdata setting its name and allocating its fields . |
237,398 | def next ( self , vRef ) : num = _C . VSgetid ( self . _hdf_inst . _id , vRef ) _checkErr ( 'next' , num , 'cannot get next vdata' ) return num | Get the reference number of the vdata following a given vdata . |
237,399 | def vdatainfo ( self , listAttr = 0 ) : lst = [ ] ref = - 1 while True : try : nxtRef = self . next ( ref ) except HDF4Error : break ref = nxtRef vdObj = self . attach ( ref ) if listAttr or not vdObj . _isattr : lst . append ( ( vdObj . _name , vdObj . _class , vdObj . _refnum , vdObj . _nrecs , vdObj . _nfields , vdO... | Return info about all the file vdatas . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.