idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
51,400 | def _has_keep_elt_in_descendants ( self , elt ) : for d in elt . iterdescendants ( ) : if d in self . elts_to_keep : return True return False | Returns whether the element has a descendant to keep or not |
51,401 | def _remove_elements ( self , elts_to_remove ) : for e in elts_to_remove : parent = e . getparent ( ) if e . tail and e . tail . strip ( ) : parent_text = parent . text or '' parent . text = parent_text + e . tail e . getparent ( ) . remove ( e ) | Removes flagged elements from the ElementTree |
51,402 | def getSystemInfo ( self , timeout = 1 ) : namespace = System . getServiceType ( "getSystemInfo" ) uri = self . getControlURL ( namespace ) results = self . execute ( uri , namespace , "GetInfo" , timeout = timeout ) return SystemInfo ( results ) | Execute GetInfo action to get information s about the System on the device . |
51,403 | def reboot ( self , timeout = 1 ) : namespace = System . getServiceType ( "reboot" ) uri = self . getControlURL ( namespace ) self . execute ( uri , namespace , "Reboot" , timeout = timeout ) | Reboot the device |
51,404 | def getTimeInfo ( self , timeout = 1 ) : namespace = System . getServiceType ( "getTimeInfo" ) uri = self . getControlURL ( namespace ) results = self . execute ( uri , namespace , "GetInfo" , timeout = timeout ) return TimeInfo ( results ) | Execute GetInfo action to get information s about the time on the device . |
51,405 | def softwareUpdateAvailable ( self , timeout = 1 ) : namespace = System . getServiceType ( "softwareUpdateAvailable" ) uri = self . getControlURL ( namespace ) results = self . execute ( uri , namespace , "GetInfo" , timeout = timeout ) return bool ( int ( results [ "NewUpgradeAvailable" ] ) ) | Returns if a software update is available |
51,406 | def make_headers ( headers ) : out = { } if 'etag' in headers : out [ 'if-none-match' ] = headers [ 'etag' ] if 'last-modified' in headers : out [ 'if-modified-since' ] = headers [ 'last-modified' ] return out | Make the cache control headers based on a previous request s response headers |
51,407 | def get ( self , prefix , url , schema_version = None ) : if not self . cache_dir : return None filename = self . _get_cache_file ( prefix , url ) try : with open ( filename , 'rb' ) as file : item = pickle . load ( file ) if schema_version and schema_version != item . schema : LOGGER . debug ( "Cache get %s %s: Wanted... | Get the cached object |
51,408 | def set ( self , prefix , url , obj ) : if not self . cache_dir : return filename = self . _get_cache_file ( prefix , url ) try : os . makedirs ( os . path . join ( self . cache_dir , prefix ) ) except OSError : pass with open ( filename , 'wb' ) as file : pickle . dump ( obj , file ) | Add an object into the cache |
51,409 | def dataset_path ( cache = None , cachefile = "~/.io3d_cache.yaml" , get_root = False ) : local_data_dir = local_dir if cachefile is not None : cache = cachef . CacheFile ( cachefile ) if cache is not None : local_data_dir = cache . get_or_save_default ( "local_dataset_dir" , local_dir ) if get_root : local_data_dir el... | Get dataset path . |
51,410 | def get_dataset_meta ( label ) : data_url = data_urls [ label ] if type ( data_url ) == str : data_url = [ data_url ] if type ( data_url ) == list : data_url . extend ( [ None , None , None , None ] ) data_url = data_url [ : 4 ] url , expected_hash , hash_path , relative_donwload_dir = data_url if hash_path is None : h... | Gives you metadata for dataset chosen via label param |
51,411 | def _expand_dataset_packages ( dataset_label_dict ) : new_dataset_label_dict = [ ] for label in dataset_label_dict : dataset_metadata = data_urls [ label ] if type ( dataset_metadata ) == dict and "package" in dataset_metadata : new_dataset_label_dict . extend ( dataset_metadata [ "package" ] ) else : new_dataset_label... | Returns list of possible packages contained in dataset in case the dataset is multi dataset eg . lisa . |
51,412 | def get_old ( dataset_label , data_id , destination_dir = None ) : if destination_dir is None : destination_dir = op . join ( dataset_path ( get_root = True ) , "medical" , "orig" ) destination_dir = op . expanduser ( destination_dir ) data_url , url , expected_hash , hash_path , relative_output_path = get_dataset_meta... | Get the 3D data from specified dataset with specified id . |
51,413 | def checksum ( path , hashfunc = "md5" ) : import checksumdir hash_func = checksumdir . HASH_FUNCS . get ( hashfunc ) if not hash_func : raise NotImplementedError ( "{} not implemented." . format ( hashfunc ) ) if os . path . isdir ( path ) : return checksumdir . dirhash ( path , hashfunc = hashfunc ) hashvalues = [ ] ... | Return checksum of files given by path . |
51,414 | def generate_face ( shape = None , face_r = 1.0 , smile_r1 = 0.5 , smile_r2 = 0.7 , eye_r = 0.2 ) : if shape is None : shape = [ 32 , 32 ] nd = len ( shape ) if nd == 2 : sh2 = shape else : sh2 = shape [ 1 : ] fc2 = _get_face2 ( sh2 , face_r = face_r , smile_r1 = smile_r1 , smile_r2 = smile_r2 , eye_r = eye_r ) if nd =... | Create 2D or 3D binar data with smile face . |
51,415 | def remove ( local_file_name ) : try : os . remove ( local_file_name ) except Exception as e : print ( "Cannot remove file '" + local_file_name + "'. Please remove it manually." ) print ( e ) | Function attempts to remove file if failure occures - > print exception |
51,416 | def unzip_recursive ( zip_file_name ) : logger . debug ( "unzipping " + zip_file_name ) fnlist = unzip_one ( zip_file_name ) for fn in fnlist : if zipfile . is_zipfile ( fn ) : local_fnlist = unzip_recursive ( fn ) fnlist . extend ( local_fnlist ) return fnlist | Unzip file with all recursive zip files inside and delete zip files after that . |
51,417 | def upload_asciinema ( filename ) : if os . path . exists ( filename ) : import asciinema . config as aconfig from asciinema . api import Api cfg = aconfig . load ( ) api = Api ( cfg . api_url , os . environ . get ( "USER" ) , cfg . install_id ) uploader = UploadCommand ( api , filename ) try : url , warn = uploader . ... | a wrapper around generation of an asciinema . api . Api to call the upload command given an already existing asciinema file . |
51,418 | def make_tls_config ( app_config ) : if not app_config [ 'DOCKER_TLS' ] : return False cert_path = app_config [ 'DOCKER_TLS_CERT_PATH' ] if cert_path : client_cert = '{0}:{1}' . format ( os . path . join ( cert_path , 'cert.pem' ) , os . path . join ( cert_path , 'key.pem' ) ) ca_cert = os . path . join ( cert_path , '... | Creates TLS configuration object . |
51,419 | def parse_client_cert_pair ( config_value ) : if not config_value : return client_cert = config_value . split ( ':' ) if len ( client_cert ) != 2 : tips = ( 'client_cert should be formatted like ' '"/path/to/cert.pem:/path/to/key.pem"' ) raise ValueError ( '{0!r} is invalid.\n{1}' . format ( config_value , tips ) ) ret... | Parses the client cert pair from config item . |
51,420 | async def process_feed ( self , url , send_mentions = True ) : self . _feed_domains . add ( utils . get_domain ( url ) ) if url in self . _processed_feeds : LOGGER . debug ( "Skipping already processed feed %s" , url ) return self . _processed_feeds . add ( url ) LOGGER . debug ( "++WAIT: %s: get feed" , url ) feed , p... | process a feed |
51,421 | async def process_entry ( self , url , add_domain = False , send_mentions = True ) : if add_domain : self . _feed_domains . add ( utils . get_domain ( url ) ) if url in self . _processed_entries : LOGGER . debug ( "Skipping already processed entry %s" , url ) return self . _processed_entries . add ( url ) LOGGER . debu... | process an entry |
51,422 | async def send_webmention ( self , entry , url ) : if ( entry . url , url ) in self . _processed_mentions : LOGGER . debug ( "Skipping already processed mention %s -> %s" , entry . url , url ) self . _processed_mentions . add ( ( entry . url , url ) ) LOGGER . debug ( "++WAIT: webmentions.get_target %s" , url ) target ... | send a webmention from an entry to a URL |
51,423 | def compilemessages ( application ) : from django . core . management import call_command with work_in ( application ) : if DJANGO_1_11 : call_command ( 'compilemessages' , all = True ) else : call_command ( 'compilemessages' ) | Compiles locale messages |
51,424 | def makemessages ( application , locale ) : from django . core . management import call_command if not locale : locale = 'en' with work_in ( application ) : call_command ( 'makemessages' , locale = ( locale , ) ) | Updates the locale message files |
51,425 | def cms_check ( migrate_cmd = False ) : from django . core . management import call_command try : import cms _create_db ( migrate_cmd ) call_command ( 'cms' , 'check' ) except ImportError : print ( 'cms_check available only if django CMS is installed' ) | Runs the django CMS cms check command |
51,426 | def generate_authors ( ) : print ( 'Generating AUTHORS' ) print ( 'Collecting author names' ) r = subprocess . Popen ( [ 'git' , 'log' , '--use-mailmap' , '--format=%aN' ] , stdout = subprocess . PIPE ) seen_authors = [ ] authors = [ ] for authfile in ( 'AUTHORS' , 'AUTHORS.rst' ) : if os . path . exists ( authfile ) :... | Updates the authors list |
51,427 | def static_analisys ( application ) : try : from cms . test_utils . util . static_analysis import pyflakes application_module = __import__ ( application ) report = pyflakes ( ( application_module , ) ) if type ( report ) == tuple : assert report [ 0 ] == 0 else : assert report == 0 except ImportError : print ( 'Static ... | Performs a pyflakes static analysis with the same configuration as django CMS testsuite |
51,428 | def build_wheel ( platform ) : if platform in [ 'x86_64' , 'i686' ] : system = 'manylinux1' else : system = 'linux' setuptools . sandbox . run_setup ( 'setup.py' , [ '-q' , 'clean' , '--all' , 'bdist_wheel' , '--plat-name' , '{}_{}' . format ( system , platform ) ] ) | Create a wheel |
51,429 | def print_mem ( unit = "MB" ) : try : import psutil B = float ( psutil . Process ( os . getpid ( ) ) . memory_info ( ) . vms ) KB = B / 1024 MB = KB / 1024 GB = MB / 1024 result = vars ( ) [ unit ] print_info ( "memory usage: %.2f(%s)" % ( result , unit ) ) return result except ImportError : print_info ( "pip install p... | Show the proc - mem - cost with psutil use this only for lazinesssss . |
51,430 | def slice_into_pieces ( seq , n ) : length = len ( seq ) if length % n == 0 : size = length // n else : size = length // n + 1 for it in slice_by_size ( seq , size ) : yield it | Slice a sequence into n pieces return a generation of n pieces |
51,431 | def slice_by_size ( seq , size ) : filling = null for it in zip ( * ( itertools_chain ( seq , [ filling ] * size ) , ) * size ) : if filling in it : it = tuple ( i for i in it if i is not filling ) if it : yield it | Slice a sequence into chunks return as a generation of chunks with size . |
51,432 | def unique ( seq , key = None , return_as = None ) : seen = set ( ) add = seen . add if key : generator = ( x for x in seq if key ( x ) not in seen and not add ( key ( x ) ) ) else : generator = ( x for x in seq if x not in seen and not add ( x ) ) if return_as : if return_as == str : return "" . join ( map ( str , gen... | Unique the seq and keep the order . |
51,433 | def unparse_qs ( qs , sort = False , reverse = False ) : result = [ ] items = qs . items ( ) if sort : items = sorted ( items , key = lambda x : x [ 0 ] , reverse = reverse ) for keys , values in items : query_name = quote ( keys ) for value in values : result . append ( query_name + "=" + quote ( value ) ) return "&" ... | Reverse conversion for parse_qs |
51,434 | def unparse_qsl ( qsl , sort = False , reverse = False ) : result = [ ] items = qsl if sort : items = sorted ( items , key = lambda x : x [ 0 ] , reverse = reverse ) for keys , values in items : query_name = quote ( keys ) result . append ( query_name + "=" + quote ( values ) ) return "&" . join ( result ) | Reverse conversion for parse_qsl |
51,435 | def kill_after ( seconds , timeout = 2 ) : pid = os . getpid ( ) kill = os . kill run_after_async ( seconds , kill , pid , signal . SIGTERM ) run_after_async ( seconds + timeout , kill , pid , 9 ) | Kill self after seconds |
51,436 | def try_import ( module_name , names = None , default = ImportErrorModule , warn = True ) : try : module = importlib . import_module ( module_name ) except ImportError : if warn : if warn is True : Config . utils_logger . warning ( "Module `%s` not found. Install it to remove this warning" % module_name ) else : warn (... | Try import module_name except ImportError and return default sometimes to be used for catch ImportError and lazy - import . |
51,437 | def guess_interval ( nums , accuracy = 0 ) : if not nums : return 0 nums = sorted ( [ int ( i ) for i in nums ] ) if len ( nums ) == 1 : return nums [ 0 ] diffs = [ nums [ i + 1 ] - nums [ i ] for i in range ( len ( nums ) - 1 ) ] diffs = [ item for item in diffs if item >= accuracy ] sorted_diff = sorted ( diffs ) res... | Given a seq of number return the median only calculate interval > = accuracy . |
51,438 | def split_n ( string , seps , reg = False ) : r deep = len ( seps ) if not deep : return string return [ split_n ( i , seps [ 1 : ] ) for i in _re_split_mixin ( string , seps [ 0 ] , reg = reg ) ] | r Split strings into n - dimensional list . |
51,439 | def curlrequests ( curl_string , ** kwargs ) : req = kwargs . pop ( 'req' , tPool ( ) ) kwargs . update ( curlparse ( curl_string ) ) return req . request ( ** kwargs ) | Use tPool to request for curl string . If kwargs contains the req which hasattr request method like req = requests . |
51,440 | def register_function ( self , patterns , instances = None , ** reg_kwargs ) : def wrapper ( function ) : self . register ( patterns , function , instances = instances , ** reg_kwargs ) return function return wrapper | Decorator for register . |
51,441 | def find ( self , string , default = None ) : return self . match ( string ) or self . search ( string ) or default | Return match or search result . |
51,442 | def search ( self , string , default = None ) : default = default if default else [ ] result = [ item [ 1 ] for item in self . container if item [ 0 ] . search ( string ) ] if self . ensure_mapping : assert len ( result ) < 2 , "%s matches more than one pattern: %s" % ( string , result , ) return result if result else ... | Use re . search to find the result |
51,443 | def fuzzy ( self , key , limit = 5 ) : instances = [ i [ 2 ] for i in self . container if i [ 2 ] ] if not instances : return instances = sum ( instances , [ ] ) from fuzzywuzzy import process maybe = process . extract ( key , instances , limit = limit ) return maybe | Give suggestion from all instances . |
51,444 | def show_all ( self , as_string = True ) : result = [ ] for item in self . container : pattern = str ( item [ 0 ] ) [ 10 : ] if PY3 else item [ 0 ] . pattern instances = item [ 2 ] or [ ] value = ( '%s "%s"' % ( item [ 1 ] . __name__ , ( item [ 1 ] . __doc__ or "" ) ) if callable ( item [ 1 ] ) else str ( item [ 1 ] ) ... | python2 will not show flags |
51,445 | def tick ( self ) : string = self . passed if self . rounding : string = round ( string ) if self . readable : string = self . readable ( string ) return string | Return the time cost string as expect . |
51,446 | def watch ( * timer_args , ** timer_kwargs ) : def wrapper ( function ) : @ wraps ( function ) def inner ( * args , ** kwargs ) : args1 = ", " . join ( map ( repr , args ) ) if args else "" kwargs1 = ", " . join ( [ "%s=%s" % ( i , repr ( kwargs [ i ] ) ) for i in sorted ( kwargs . keys ( ) ) ] ) arg = ", " . join ( fi... | Decorator for Timer . |
51,447 | def default_callback ( self , text ) : text = text . replace ( "\r\n" , "\n" ) text = "%s\n" % text flush_print ( text , sep = "" , end = "" ) return text | Default clean the \\ n in text . |
51,448 | def watch ( self , limit = None , timeout = None ) : start_time = time . time ( ) count = 0 while not timeout or time . time ( ) - start_time < timeout : new = self . read ( ) if new != self . temp : count += 1 self . callback ( new ) if count == limit : break self . temp = new time . sleep ( self . interval ) | Block method to watch the clipboard changing . |
51,449 | def watch_async ( self , limit = None , timeout = None ) : return self . watch ( limit = limit , timeout = timeout ) | Non - block method to watch the clipboard changing . |
51,450 | def find_one ( cls , pattern , string , flags = 0 ) : item = re . search ( pattern , string , flags = flags ) return cls ( item ) | JS - like match object . Use index number to get groups if not match or no group will return . |
51,451 | def create_issue ( title , body , repo , token ) : owner , name = repo . split ( '/' ) url = 'https://api.github.com/repos/%s/%s/issues' % ( owner , name ) data = { 'title' : title , 'body' : body } headers = { "Authorization" : "token %s" % token , "Accept" : "application/vnd.github.symmetra-preview+json" } response =... | create a Github issue given a title body repo and token . |
51,452 | async def get_target ( config , url ) : previous = config . cache . get ( 'target' , url , schema_version = SCHEMA_VERSION ) if config . cache else None headers = previous . caching if previous else None request = await utils . retry_get ( config , url , headers = headers ) if not request or not request . success : ret... | Given a URL get the webmention endpoint |
51,453 | async def send ( self , config , entry ) : if self . endpoint : LOGGER . debug ( "%s -> %s" , entry . url , self . url ) try : await self . endpoint . send ( config , entry . url , self . url ) except Exception as err : LOGGER . warning ( "Ping %s: got %s: %s" , self . url , err . __class__ . __name__ , err ) | Send a webmention to this target from the specified entry |
51,454 | def get_helper ( name = None , quiet = True , ** kwargs ) : from helpme . defaults import HELPME_CLIENT if name is not None : HELPME_CLIENT = name if HELPME_CLIENT == 'github' : from . github import Helper elif HELPME_CLIENT == 'uservoice' : from . uservoice import Helper elif HELPME_CLIENT == 'discourse' : from . disc... | get the correct helper depending on the environment variable HELPME_CLIENT |
51,455 | def mock_bable ( monkeypatch ) : mocked_bable = MockBaBLE ( ) mocked_bable . set_controllers ( [ Controller ( 0 , '11:22:33:44:55:66' , '#0' ) , Controller ( 1 , '22:33:44:55:66:11' , '#1' , settings = { 'powered' : True , 'low_energy' : True } ) , Controller ( 2 , '33:44:55:66:11:22' , '#2' , settings = { 'powered' : ... | Mock the BaBLEInterface class with some controllers inside . |
51,456 | def handle ( self ) : self . output = PyStratumStyle ( self . input , self . output ) command = self . get_application ( ) . find ( 'constants' ) ret = command . execute ( self . input , self . output ) if ret : return ret command = self . get_application ( ) . find ( 'loader' ) ret = command . execute ( self . input ,... | Executes the actual Stratum program . |
51,457 | def load_from_file ( module_path ) : from imp import load_module , PY_SOURCE imported = None if module_path : with open ( module_path , 'r' ) as openfile : imported = load_module ( 'mod' , openfile , module_path , ( 'imported' , 'r' , PY_SOURCE ) ) return imported | Load a python module from its absolute filesystem path |
51,458 | def ensure_unicoded_and_unique ( args_list , application ) : unicoded_args = [ ] for argument in args_list : argument = ( six . u ( argument ) if not isinstance ( argument , six . text_type ) else argument ) if argument not in unicoded_args or argument == application : unicoded_args . append ( argument ) return unicode... | Iterate over args_list make it unicode if needed and ensure that there are no duplicates . Returns list of unicoded arguments in the same order . |
51,459 | def write_two_phases ( filename , data , io ) : write_flag = True if os . path . exists ( filename ) : with open ( filename , 'r' ) as file : old_data = file . read ( ) if data == old_data : write_flag = False if write_flag : tmp_filename = filename + '.tmp' with open ( tmp_filename , 'w+' ) as file : file . write ( da... | Writes a file in two phase to the filesystem . |
51,460 | async def get_entry ( config , url ) : previous = config . cache . get ( 'entry' , url , schema_version = SCHEMA_VERSION ) if config . cache else None headers = previous . caching if previous else None request = await utils . retry_get ( config , url , headers = headers ) if not request or not request . success : LOGGE... | Given an entry URL return the entry |
51,461 | def _check_rel ( attrs , rel_whitelist , rel_blacklist ) : rels = attrs . get ( 'rel' , [ None ] ) if rel_blacklist : for rel in rels : if rel in rel_blacklist : return False if rel_whitelist : for rel in rels : if rel in rel_whitelist : return True return False return True | Check a link s relations against the whitelist or blacklist . |
51,462 | def _domain_differs ( self , href ) : target = utils . get_domain ( href ) if not target : return False origin = utils . get_domain ( self . url ) return target != origin | Check that a link is not on the same domain as the source URL |
51,463 | def get_targets ( self , config ) : return { urllib . parse . urljoin ( self . url , attrs [ 'href' ] ) for attrs in self . _targets if self . _check_rel ( attrs , config . rel_whitelist , config . rel_blacklist ) and self . _domain_differs ( attrs [ 'href' ] ) } | Given an Entry object return all of the outgoing links . |
51,464 | def handle ( self ) : self . output = PyStratumStyle ( self . input , self . output ) config_file = self . argument ( 'config_file' ) sources = self . argument ( 'file_names' ) status = self . run_command ( config_file , sources ) return status | Executes loader command . |
51,465 | async def create_vm ( self , * , preset_name , image , flavor , security_groups = None , userdata = None , key_name = None , availability_zone = None , subnet = None ) : info = { 'id' : next ( self . _id_it ) , 'name' : preset_name , 'ip' : [ '127.0.0.1' ] , 'created' : 0 , 'state' : VmState . RUNNING , 'flavor' : flav... | Dummy create_vm func . |
51,466 | async def list_vms ( self , preset_name ) : return list ( vm for vm in self . _vms . values ( ) if vm . name == preset_name ) | Dummy list_vms func |
51,467 | async def terminate_vm ( self , vm_id ) : if vm_id not in self . _vms : raise DummyIaasVmNotFound ( ) del self . _vms [ vm_id ] return None | Dummy terminate_vm func |
51,468 | async def get_vm ( self , vm_id ) : if vm_id not in self . _vms : raise DummyIaasVmNotFound ( ) return self . _vms [ vm_id ] | Dummy get_vm func |
51,469 | def suggest_filename ( file_path , exists = None ) : import os . path import re if not isinstance ( exists , bool ) : exists = os . path . exists ( file_path ) if exists : file_path , file_extension = os . path . splitext ( file_path ) m = re . search ( r"_\d+$" , file_path ) if m is None : new_cislo_str = "_2" else : ... | Try if exist path and append number to its end . For debug you can set as input if file exists or not . |
51,470 | def obj_from_file ( filename = 'annotation.yaml' , filetype = 'auto' ) : if filetype == 'auto' : _ , ext = os . path . splitext ( filename ) filetype = ext [ 1 : ] if filetype in ( 'yaml' , 'yml' ) : from ruamel . yaml import YAML yaml = YAML ( typ = "unsafe" ) with open ( filename , encoding = "utf-8" ) as f : obj = y... | Read object from file |
51,471 | def read_pkl_and_pklz ( filename ) : fcontent = None try : import gzip f = gzip . open ( filename , 'rb' ) fcontent = f . read ( ) f . close ( ) except IOError as e : logger . info ( "Input gzip exception: " + str ( e ) ) f = open ( filename , 'rb' ) fcontent = f . read ( ) f . close ( ) except Exception as e : import ... | Try read zipped or not zipped pickle file |
51,472 | def obj_to_file ( obj , filename , filetype = 'auto' , ndarray_to_list = False , squeeze = True ) : if ndarray_to_list : obj = ndarray_to_list_in_structure ( obj , squeeze = squeeze ) d = os . path . dirname ( os . path . abspath ( filename ) ) if not os . path . exists ( d ) : os . makedirs ( d ) if filetype == 'auto'... | Writes annotation in file . |
51,473 | def resize_to_shape ( data , shape , zoom = None , mode = 'nearest' , order = 0 ) : try : import skimage import skimage . transform segm_orig_scale = skimage . transform . resize ( data , shape , order = 0 , preserve_range = True , mode = "constant" , ) segmentation = segm_orig_scale logger . debug ( 'resize to orig wi... | Function resize input data to specific shape . |
51,474 | def use_economic_dtype ( data3d , slope = 1 , inter = 0 , dtype = None ) : if dtype is None : dtype = data3d . dtype if issubclass ( dtype . type , np . integer ) : mn = data3d . min ( ) * slope + inter mx = data3d . max ( ) * slope + inter if suits_with_dtype ( mn , mx , dtype = np . uint8 ) : dtype = np . uint8 elif ... | Use more economic integer - like dtype if it is possible . |
51,475 | def get_sitk_image_from_ndarray ( data3d ) : import SimpleITK as sitk rescale_intercept = None if sitk . Version . MajorVersion ( ) > 0 : if data3d . dtype == np . int8 : rescale_intercept = - 2 ** 7 data3d = ( data3d - rescale_intercept ) . astype ( np . uint8 ) elif data3d . dtype == np . int16 : rescale_intercept = ... | Prepare SimpleItk Image object and rescale data to unsigned types . |
51,476 | def split_evenly ( n , chunks ) : if n < chunks : raise ChunkingError ( "Number of chunks is greater than number" ) if n % chunks == 0 : return [ n / chunks ] * chunks max_size = n / chunks + 1 return [ max_size ] + split_evenly ( n - max_size , chunks - 1 ) | Split an integer into evenly distributed list |
51,477 | def _generate_keys ( self ) : from helpme . defaults import HELPME_CLIENT_SECRETS keypair_dir = os . path . join ( os . path . dirname ( HELPME_CLIENT_SECRETS ) , 'discourse' ) self . keypair_file = os . path . join ( keypair_dir , 'private.pem' ) if not hasattr ( self , 'key' ) : self . key = generate_keypair ( self .... | the discourse API requires the interactions to be signed so we generate a keypair on behalf of the user |
51,478 | def invalidate ( self , cls , id_field , id_val ) : cache_key , flag_key = self . get_keys ( cls , id_field , id_val ) pipeline = self . redis . pipeline ( ) pipeline . delete ( cache_key ) pipeline . delete ( flag_key ) pipeline . execute ( ) | Invalidate the cache for a given Mongo object by deleting the cached data and the cache flag . |
51,479 | async def manage ( self ) : self . _vms = await self . iaas . list_vms ( self . name ) vms_stat = Counter ( [ vm . get_state ( ) for vm in self . _vms ] ) missing = self . count - len ( self . _vms ) if len ( self . _vms ) < self . count else 0 logging . info ( 'VMs Status: %s expected, %s in iaas, %s running, %s nearb... | Manage function docstring |
51,480 | def log_method ( log , level = logging . DEBUG ) : def decorator ( func ) : func_name = func . __name__ @ six . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if log . isEnabledFor ( level ) : pretty_args = [ ] if args : pretty_args . extend ( str ( a ) for a in args ) if kwargs : pretty_args . extend ( "%s... | Logs a method and its arguments when entered . |
51,481 | def check_local ( ) -> None : to_check = [ './replay' , './replay/toDo' , './replay/archive' ] for i in to_check : if not os . path . exists ( i ) : os . makedirs ( i ) | Verify required directories exist . |
51,482 | def create_file ( project : str , environment : str , feature : str , state : str ) -> None : check_local ( ) save_path = './replay/toDo/' filename = '{0}.txt' . format ( str ( uuid . uuid1 ( ) ) ) complete_name = os . path . join ( save_path , filename ) with open ( complete_name , 'w' ) as filename : filename . write... | Create file to replay . |
51,483 | def execute_replay ( ) -> None : files = glob . glob ( './replay/toDo/*' ) sorted_files = sorted ( files , key = os . path . getctime ) if not sorted_files : LOG . debug ( 'Found %s, beginning execution.' , sorted_files ) for command_file in sorted_files : with open ( command_file , 'r' ) as command : cmd = command . r... | Execute all commands . |
51,484 | def choice_prompt ( prompt , choices = None , choice = None ) : if not choices : choices = [ "y" , "n" , "Y" , "N" ] print ( prompt ) get_input = getattr ( __builtins__ , 'raw_input' , input ) pretty_choices = '/' . join ( choices ) message = 'Please enter your choice [%s] : ' % ( pretty_choices ) while choice not in c... | Ask the user for a prompt and only return when one of the requested options is provided . |
51,485 | def regexp_prompt ( prompt , regexp = '.' , answer = '' ) : get_input = getattr ( __builtins__ , 'raw_input' , input ) while not re . search ( regexp , answer ) : answer = get_input ( prompt + ': ' ) . strip ( ) message = "Your entry must match the regular expression %s" % regexp return answer | Ask the user for a text entry that matches a regular expression |
51,486 | def which ( software , strip_newline = True ) : if software is None : software = "singularity" cmd = [ 'which' , software ] try : result = run_command ( cmd ) if strip_newline is True : result [ 'message' ] = result [ 'message' ] . strip ( '\n' ) return result except : return None | get_install will return the path to where an executable is installed . |
51,487 | def guess_encoding ( request ) : ctype = request . headers . get ( 'content-type' ) if not ctype : LOGGER . warning ( "%s: no content-type; headers are %s" , request . url , request . headers ) return 'utf-8' match = re . search ( r'charset=([^ ;]*)(;| |$)' , ctype ) if match : return match [ 1 ] if ctype . startswith ... | Try to guess the encoding of a request without going through the slow chardet process |
51,488 | def _make_headers ( config , kwargs ) : headers = kwargs . get ( 'headers' ) headers = headers . copy ( ) if headers is not None else { } headers [ 'User-Agent' ] = config . args . user_agent kwargs = kwargs . copy ( ) kwargs [ 'headers' ] = headers return kwargs | Replace the kwargs with one where the headers include our user - agent |
51,489 | async def retry_get ( config , url , * args , ** kwargs ) : return await _retry_do ( config . session . get , url , * args , ** _make_headers ( config , kwargs ) ) | aiohttp wrapper for GET |
51,490 | async def retry_post ( config , url , * args , ** kwargs ) : return await _retry_do ( config . session . post , url , * args , ** _make_headers ( config , kwargs ) ) | aiohttp wrapper for POST |
51,491 | def collect_argument ( self , step , message ) : if step not in self . data : self . data [ step ] = regexp_prompt ( message ) | given a key in the configuration collect the runtime argument if provided . Otherwise prompt the user for the value . |
51,492 | def record_environment ( self ) : envars = self . _get_setting ( name = 'whitelist' , section = 'record_environment' , user = False ) if envars is not None : envars = [ x . upper ( ) for x in envars . split ( '\n' ) ] bot . custom ( prefix = "Environment " , message = '|' . join ( envars ) , color = "CYAN" ) keep = [ (... | collect a limited set of environment variables based on the list under record_envirionment in the configuration file . |
51,493 | def speak ( self ) : if self . quiet is False : bot . info ( '[helper|%s]' % ( self . name ) ) self . _speak ( ) | a function for the helper to announce him or herself depending on the level specified . If you want your client to have additional announced things here then implement the class _speak for your client . |
51,494 | def __log_number_of_constants ( self ) : n_id = len ( self . _labels ) n_widths = len ( self . _constants ) - n_id self . _io . writeln ( '' ) self . _io . text ( 'Number of constants based on column widths: {0}' . format ( n_widths ) ) self . _io . text ( 'Number of constants based on database IDs : {0}' . format ( n_... | Logs the number of constants generated . |
51,495 | def _check_env_var ( envvar : str ) -> bool : if os . getenv ( envvar ) is None : raise KeyError ( "Required ENVVAR: {0} is not set" . format ( envvar ) ) if not os . getenv ( envvar ) : raise KeyError ( "Required ENVVAR: {0} is empty" . format ( envvar ) ) return True | Check Environment Variable to verify that it is set and not empty . |
51,496 | def valid_state ( state : str ) -> bool : lower_case_state = state . lower ( ) if lower_case_state in _VALID_STATES : return True return False | Validate State Argument |
51,497 | def valid_env_vars ( ) -> bool : for envvar in _REQUIRED_ENV_VARS : try : _check_env_var ( envvar ) except KeyError as ex : LOG . error ( ex ) sys . exit ( 1 ) return True | Validate that required env vars exist . |
51,498 | def configure_panel ( self ) : webroot = os . path . dirname ( __file__ ) self . template_path = os . path . join ( webroot , 'templates' ) aiohttp_jinja2 . setup ( self , loader = jinja2 . FileSystemLoader ( self . template_path ) , filters = { 'sorted' : sorted , 'int' : int } ) self [ 'static_root_url' ] = '/static'... | Configure templates and routing |
51,499 | async def start ( self ) : logging . info ( 'Starting server, listening on %s.' , self . port ) runner = web . AppRunner ( self ) await runner . setup ( ) site = web . TCPSite ( runner , '' , self . port ) await site . start ( ) | Initialize and start WebServer |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.