idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
49,400 | def add ( self , layer , items ) : for k in items . iterkeys ( ) : if k in self . model [ layer ] : raise Exception ( 'item %s is already in layer %s' % ( k , layer ) ) self . model [ layer ] . update ( items ) for k , v in items . iteritems ( ) : getattr ( self , layer ) . add ( k , v [ 'module' ] , v . get ( 'package... | Add items in model . |
49,401 | def delete ( self , layer , items ) : items = _listify ( items ) layer_obj = self . edit ( layer , dict . fromkeys ( items ) , delete = True ) for k in items : if k in layer_obj . layer : layer_obj . delete ( k ) else : raise AttributeError ( 'item %s missing from layer %s' % ( k , layer ) ) | Delete items in model . |
49,402 | def save ( self , modelfile , layer = None ) : if layer : obj = { layer : self . model [ layer ] } else : obj = self . model with open ( modelfile , 'w' ) as fp : json . dump ( obj , fp , indent = 2 , sort_keys = True ) | Save a model file . |
49,403 | def command ( self , cmd , progress_hook = None , * args , ** kwargs ) : cmds = cmd . split ( None , 1 ) sim_names = cmds [ 1 : ] if not sim_names : sim_names = self . cmd_layer . reg . iterkeys ( ) for sim_name in sim_names : sim_cmd = getattr ( self . cmd_layer . reg [ sim_name ] , cmd ) sim_cmd ( self , progress_hoo... | Execute a model command . |
49,404 | def login ( self , password ) : if self . logged_in : raise RuntimeError ( "User already logged in!" ) params = { "name" : self . nick , "password" : password } resp = self . conn . make_api_call ( "login" , params ) if "error" in resp : raise RuntimeError ( f"Login failed: {resp['error'].get('message') or resp['error'... | Attempts to log in as the current user with given password |
49,405 | def login_transplant ( self , other ) : if not other . logged_in : raise ValueError ( "Other room is not logged in" ) cookie = other . session if not cookie : raise ValueError ( "Other room has no cookie" ) self . conn . cookies . update ( { "session" : cookie } ) self . session = cookie self . logged_in = True return ... | Attempts to carry over the login state from another room |
49,406 | def logout ( self ) : if not self . logged_in : raise RuntimeError ( "User is not logged in" ) if self . conn . connected : params = { "room" : self . conn . room . room_id } resp = self . conn . make_api_call ( "logout" , params ) if not resp . get ( "success" , False ) : raise RuntimeError ( f"Logout unsuccessful: " ... | Logs your user out |
49,407 | def register ( self , password ) : if len ( password ) < 8 : raise ValueError ( "Password must be at least 8 characters." ) params = { "name" : self . nick , "password" : password } resp = self . conn . make_api_call ( "register" , params ) if "error" in resp : raise RuntimeError ( f"{resp['error'].get('message') or re... | Registers the current user with the given password . |
49,408 | def __verify_username ( self , username ) : if len ( username ) > self . __max_length or len ( username ) < 3 : raise ValueError ( f"Username must be between 3 and {self.__max_length} characters." ) if any ( c not in string . ascii_letters + string . digits for c in username ) : raise ValueError ( "Usernames can only c... | Raises an exception if the given username is not valid . |
49,409 | def update ( self , value , timestamp = None ) : if timestamp is None : timestamp = self . current_time_in_fractional_seconds ( ) self . rescale_if_needed ( ) priority = self . weight ( timestamp - self . start_time ) / random . random ( ) self . values [ priority ] = value if len ( self . values ) > self . size : self... | Add a value to the reservoir . |
49,410 | def get_objects ( classpath , calling_classpath = "" ) : module_name , class_name = classpath . rsplit ( '.' , 1 ) module = importlib . import_module ( module_name , calling_classpath ) try : klass = getattr ( module , class_name ) except AttributeError : raise AttributeError ( "module {} has no attribute {} parsing {}... | given a classpath like foo . bar . Baz return module foo . bar and class Baz objects |
49,411 | def make_dict ( fields , fields_kwargs ) : ret = { } if fields : ret . update ( fields ) if fields_kwargs : ret . update ( fields_kwargs ) return ret | lot s of methods take a dict or kwargs this combines those |
49,412 | def write_line ( self , line , count = 1 ) : self . write ( line ) self . write_newlines ( count ) | writes the line and count newlines after the line |
49,413 | def add ( self , key , val , priority = None ) : if key in self . item_finder : self . remove ( key ) else : if self . full ( ) : raise OverflowError ( "Queue is full" ) if priority is None : priority = next ( self . counter ) item = [ priority , key , val ] self . item_finder [ key ] = item heapq . heappush ( self . p... | add a value to the queue with priority using the key to know uniqueness |
49,414 | def remove ( self , key ) : item = self . item_finder . pop ( key ) item [ - 1 ] = None self . removed_count += 1 | remove the value found at key from the queue |
49,415 | def full ( self ) : if not self . size : return False return len ( self . pq ) == ( self . size + self . removed_count ) | Return True if the queue is full |
49,416 | def check_photometry_categorize ( x , y , levels , tags = None ) : x = numpy . asarray ( x ) y = numpy . asarray ( y ) ys = y . copy ( ) ys . sort ( ) m = ys [ len ( ys ) // 2 : ] . mean ( ) y /= m m = 1.0 s = ys [ len ( ys ) // 2 : ] . std ( ) result = [ ] if tags is None : tags = list ( six . moves . range ( len ( le... | Put every point in its category . |
49,417 | def client_authentication ( self , request , auth = None , ** kwargs ) : return verify_client ( self . endpoint_context , request , auth ) | Do client authentication |
49,418 | def construct ( self , response_args , request , ** kwargs ) : response_args = self . do_pre_construct ( response_args , request , ** kwargs ) response = self . response_cls ( ** response_args ) return self . do_post_construct ( response , request , ** kwargs ) | Construct the response |
49,419 | def inputs ( form_args ) : element = [ ] for name , value in form_args . items ( ) : element . append ( '<input type="hidden" name="{}" value="{}"/>' . format ( name , value ) ) return "\n" . join ( element ) | Creates list of input elements |
49,420 | def verify_uri ( endpoint_context , request , uri_type , client_id = None ) : try : _cid = request [ "client_id" ] except KeyError : _cid = client_id if not _cid : logger . error ( 'No client id found' ) raise UnknownClient ( 'No client_id provided' ) _redirect_uri = unquote ( request [ uri_type ] ) part = urlparse ( _... | A redirect URI MUST NOT contain a fragment MAY contain query component |
49,421 | def get_uri ( endpoint_context , request , uri_type ) : if uri_type in request : verify_uri ( endpoint_context , request , uri_type ) uri = request [ uri_type ] else : try : _specs = endpoint_context . cdb [ str ( request [ "client_id" ] ) ] [ "{}s" . format ( uri_type ) ] except KeyError : raise ParameterError ( "Miss... | verify that the redirect URI is reasonable |
49,422 | def post_authentication ( self , user , request , sid , ** kwargs ) : response_info = { } try : permission = self . endpoint_context . authz ( user , client_id = request [ 'client_id' ] ) except ToOld as err : return self . error_response ( response_info , 'access_denied' , 'Authentication to old {}' . format ( err . a... | Things that are done after a successful authentication . |
49,423 | def authz_part2 ( self , user , authn_event , request , ** kwargs ) : sid = setup_session ( self . endpoint_context , request , user , authn_event = authn_event ) try : resp_info = self . post_authentication ( user , request , sid , ** kwargs ) except Exception as err : return self . error_response ( { } , 'server_erro... | After the authentication this is where you should end up |
49,424 | def process_request ( self , request_info = None , ** kwargs ) : if isinstance ( request_info , AuthorizationErrorResponse ) : return request_info _cid = request_info [ "client_id" ] cinfo = self . endpoint_context . cdb [ _cid ] try : cookie = kwargs [ 'cookie' ] except KeyError : cookie = '' else : del kwargs [ 'cook... | The AuthorizationRequest endpoint |
49,425 | def setup_session ( endpoint_context , areq , uid , client_id = '' , acr = '' , salt = 'salt' , authn_event = None ) : if authn_event is None and acr : authn_event = AuthnEvent ( uid = uid , salt = salt , authn_info = acr , authn_time = time . time ( ) ) if not client_id : client_id = areq [ 'client_id' ] sid = endpoin... | Setting up a user session |
49,426 | def update ( self , sid , ** kwargs ) : item = self [ sid ] for attribute , value in kwargs . items ( ) : item [ attribute ] = value self [ sid ] = item | Add attribute value assertion to a special session |
49,427 | def update_by_token ( self , token , ** kwargs ) : _sid = self . handler . sid ( token ) return self . update ( _sid , ** kwargs ) | Updated the session info . Any type of known token can be used |
49,428 | def replace_token ( self , sid , sinfo , token_type ) : try : refresh_token = self . handler [ token_type ] ( sid , sinfo = sinfo ) except KeyError : pass else : try : self . handler [ token_type ] . black_list ( sinfo [ token_type ] ) except KeyError : pass sinfo [ token_type ] = refresh_token return sinfo | Replace an old refresh_token with a new one |
49,429 | def refresh_token ( self , token , new_refresh = False ) : try : _tinfo = self . handler [ 'refresh_token' ] . info ( token ) except KeyError : return False if is_expired ( int ( _tinfo [ 'exp' ] ) ) or _tinfo [ 'black_listed' ] : raise ExpiredToken ( ) _sid = _tinfo [ 'sid' ] session_info = self [ _sid ] session_info ... | Issue a new access token using a valid refresh token |
49,430 | def is_token_valid ( self , token ) : try : _tinfo = self . handler . info ( token ) except KeyError : return False if is_expired ( int ( _tinfo [ 'exp' ] ) ) or _tinfo [ 'black_listed' ] : return False session_info = self [ _tinfo [ 'sid' ] ] if session_info [ "oauth_state" ] == "authz" : if _tinfo [ 'handler' ] != se... | Checks validity of a given token |
49,431 | def revoke_token ( self , token , token_type = '' ) : if token_type : self . handler [ token_type ] . black_list ( token ) else : self . handler . black_list ( token ) | Revokes access token |
49,432 | def revoke_session ( self , sid = '' , token = '' ) : if not sid : if token : sid = self . handler . sid ( token ) else : raise ValueError ( 'Need one of "sid" or "token"' ) for typ in [ 'access_token' , 'refresh_token' , 'code' ] : try : self . revoke_token ( self [ sid ] [ typ ] , typ ) except KeyError : pass self . ... | Mark session as revoked but also explicitly revoke all issued tokens |
49,433 | def pick_auth ( endpoint_context , areq , all = False ) : acrs = [ ] try : if len ( endpoint_context . authn_broker ) == 1 : return endpoint_context . authn_broker . default ( ) if "acr_values" in areq : if not isinstance ( areq [ "acr_values" ] , list ) : areq [ "acr_values" ] = [ areq [ "acr_values" ] ] acrs = areq [... | Pick authentication method |
49,434 | def get_method ( self , cls_name ) : for id , spec in self . db . items ( ) : if spec [ "method" ] . __class__ . __name__ == cls_name : yield spec [ "method" ] | Generator that returns all registered authenticators based on a specific authentication class . |
49,435 | def pick ( self , acr = None ) : if acr is None : return self . db . values ( ) else : return self . _pick_by_class_ref ( acr ) | Given the authentication context find zero or more authn methods that could be used . |
49,436 | def update_config ( self ) : filter = self . config [ 'FILTER_MASK' ] rows = len ( filter ) cols = len ( filter [ 0 ] ) filter_f = __builtin__ . open ( self . config [ 'FILTER_NAME' ] , 'w' ) filter_f . write ( "CONV NORM\n" ) filter_f . write ( "# %dx%d Generated from sextractor.py module.\n" % ( rows , cols ) ) for r... | Update the configuration files according to the current in - memory SExtractor configuration . |
49,437 | def run ( self , file , updateconfig = True , clean = False , path = None ) : if updateconfig : self . update_config ( ) self . program , self . version = self . setup ( path ) commandline = ( self . program + " -c " + self . config [ 'CONFIG_FILE' ] + " " + file ) rcode = os . system ( commandline ) if ( rcode ) : rai... | Run SExtractor . |
49,438 | def offsets_from_wcs ( frames , pixref ) : result = numpy . zeros ( ( len ( frames ) , pixref . shape [ 1 ] ) ) with frames [ 0 ] . open ( ) as hdulist : wcsh = wcs . WCS ( hdulist [ 0 ] . header ) skyref = wcsh . wcs_pix2world ( pixref , 1 ) for idx , frame in enumerate ( frames [ 1 : ] ) : with frame . open ( ) as hd... | Compute offsets between frames using WCS information . |
49,439 | def _check_deployed_nodes ( nodes ) : deployed = [ ] undeployed = [ ] cmd = "! (mount | grep -E '^/dev/[[:alpha:]]+2 on / ')" deployed_check = get_execo_remote ( cmd , nodes , DEFAULT_CONN_PARAMS ) for p in deployed_check . processes : p . nolog_exit_code = True p . nolog_timeout = True p . nolog_error = True p . timeo... | This is borrowed from execo . |
49,440 | def get_networks ( self ) : networks = self . c_resources [ "networks" ] result = [ ] for net in networks : _c_network = net . get ( "_c_network" ) if _c_network is None : continue roles = utils . get_roles_as_list ( net ) result . append ( ( roles , _c_network ) ) return result | Get the networks assoiated with the resource description . |
49,441 | def get_roles ( self ) : machines = self . c_resources [ "machines" ] result = { } for desc in machines : roles = utils . get_roles_as_list ( desc ) hosts = self . _denormalize ( desc ) for role in roles : result . setdefault ( role , [ ] ) result [ role ] . extend ( hosts ) return result | Get the roles associated with the hosts . |
49,442 | async def start_client ( self , sock : anyio . abc . SocketStream , addr , path : str , headers : Optional [ List ] = None , subprotocols : Optional [ List [ str ] ] = None ) : self . _sock = sock self . _connection = WSConnection ( ConnectionType . CLIENT ) if headers is None : headers = [ ] if subprotocols is None : ... | Start a client WS connection on this socket . |
49,443 | async def start_server ( self , sock : anyio . abc . SocketStream , filter = None ) : assert self . _scope is None self . _scope = True self . _sock = sock self . _connection = WSConnection ( ConnectionType . SERVER ) try : event = await self . _next_event ( ) if not isinstance ( event , Request ) : raise ConnectionErr... | Start a server WS connection on this socket . |
49,444 | async def _next_event ( self ) : while True : for event in self . _connection . events ( ) : if isinstance ( event , Message ) : if event . message_finished : return self . _wrap_data ( self . _gather_buffers ( event ) ) self . _buffer ( event ) break else : return event data = await self . _sock . receive_some ( 4096 ... | Gets the next event . |
49,445 | async def close ( self , code : int = 1006 , reason : str = "Connection closed" ) : if self . _closed : return self . _closed = True if self . _scope is not None : await self . _scope . cancel ( ) data = self . _connection . send ( CloseConnection ( code = code , reason = reason ) ) await self . _sock . send_all ( data... | Closes the websocket . |
49,446 | async def send ( self , data : Union [ bytes , str ] , final : bool = True ) : MsgType = TextMessage if isinstance ( data , str ) else BytesMessage data = MsgType ( data = data , message_finished = final ) data = self . _connection . send ( event = data ) await self . _sock . send_all ( data ) | Sends some data down the connection . |
49,447 | def _buffer ( self , event : Message ) : if isinstance ( event , BytesMessage ) : self . _byte_buffer . write ( event . data ) elif isinstance ( event , TextMessage ) : self . _string_buffer . write ( event . data ) | Buffers an event if applicable . |
49,448 | def _gather_buffers ( self , event : Message ) : if isinstance ( event , BytesMessage ) : buf = self . _byte_buffer else : buf = self . _string_buffer buf . write ( event . data ) buf . seek ( 0 ) data = buf . read ( ) buf . seek ( 0 ) buf . truncate ( ) return data | Gathers all the data from a buffer . |
49,449 | def _wrap_data ( data : Union [ str , bytes ] ) : MsgType = TextMessage if isinstance ( data , str ) else BytesMessage return MsgType ( data = data , frame_finished = True , message_finished = True ) | Wraps data into the right event . |
49,450 | def get_field_SQL ( self , field_name , field ) : field_type = "" is_pk = field . options . get ( 'pk' , False ) if issubclass ( field . type , bool ) : field_type = 'BOOLEAN' elif issubclass ( field . type , long ) : if is_pk : field_type = 'INTEGER PRIMARY KEY' else : field_type = 'BIGINT' elif issubclass ( field . t... | returns the SQL for a given field with full type information |
49,451 | def _get_fields ( self , table_name , ** kwargs ) : ret = { } query_str = 'PRAGMA table_info({})' . format ( self . _normalize_table_name ( table_name ) ) fields = self . _query ( query_str , ** kwargs ) query_str = 'PRAGMA foreign_key_list({})' . format ( self . _normalize_table_name ( table_name ) ) fks = { f [ "from... | return all the fields for the given table |
49,452 | def _normalize_date_SQL ( self , field_name , field_kwargs , symbol ) : fstrs = [ ] k_opts = { 'day' : "CAST(strftime('%d', {}) AS integer)" , 'hour' : "CAST(strftime('%H', {}) AS integer)" , 'doy' : "CAST(strftime('%j', {}) AS integer)" , 'julian_day' : "strftime('%J', {})" , 'month' : "CAST(strftime('%m', {}) AS inte... | allow extracting information from date |
49,453 | def _normalize_sort_SQL ( self , field_name , field_vals , sort_dir_str ) : fvi = None if sort_dir_str == 'ASC' : fvi = ( t for t in enumerate ( field_vals ) ) else : fvi = ( t for t in enumerate ( reversed ( field_vals ) ) ) query_sort_str = [ ' CASE {}' . format ( self . _normalize_name ( field_name ) ) ] query_args... | allow sorting by a set of values |
49,454 | def register ( self , new_calc , * args , ** kwargs ) : kwargs . update ( zip ( self . meta_names , args ) ) if isinstance ( kwargs [ 'dependencies' ] , basestring ) : kwargs [ 'dependencies' ] = [ kwargs [ 'dependencies' ] ] super ( CalcRegistry , self ) . register ( new_calc , ** kwargs ) | Register calculations and meta data . |
49,455 | def slits_to_ds9_reg ( ds9reg , slits ) : ds9reg . write ( '# Region file format: DS9 version 4.1\n' ) ds9reg . write ( 'global color=green dashlist=8 3 width=1 font="helvetica 10 ' 'normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 ' 'move=1 delete=1 include=1 source=1\n' ) ds9reg . write ( 'physical\n' ) for id... | Transform fiber traces to ds9 - region format . |
49,456 | def id_maker ( obj ) : dtfmt = '%Y%m%d-%H%M%S' return '%s-%s' % ( obj . __class__ . __name__ , datetime . now ( ) . strftime ( dtfmt ) ) | Makes an ID from the object s class name and the datetime now in ISO format . |
49,457 | def register ( self , sim , * args , ** kwargs ) : kwargs . update ( zip ( self . meta_names , args ) ) super ( SimRegistry , self ) . register ( sim , ** kwargs ) | register simulation and metadata . |
49,458 | def check_data ( self , data ) : data_objs = { data_src : data . objects . get ( data_src ) for data_src in data . layer } self . _is_data_loaded = all ( data_objs . values ( ) ) return data_objs | Check if data loaded for all sources in data layer . |
49,459 | def initialize ( self , calc_reg ) : self . _isinitialized = True self . calc_order = topological_sort ( calc_reg . dependencies ) | Initialize the simulation . Organize calculations by dependency . |
49,460 | def index_iterator ( self ) : idx = 0 while idx < self . number_intervals : new_idx = yield idx idx += 1 if new_idx : idx = new_idx - 1 | Generator that resumes from same index or restarts from sent index . |
49,461 | def save_ds9 ( output , filename ) : ds9_file = open ( filename , 'wt' ) ds9_file . write ( output ) ds9_file . close ( ) | Save ds9 region output info filename . |
49,462 | def save_four_ds9 ( rectwv_coeff , debugplot = 0 ) : for limits , rectified , suffix in zip ( [ 'frontiers' , 'frontiers' , 'boundaries' , 'boundaries' ] , [ False , True , False , True ] , [ 'rawimage' , 'rectified' , 'rawimage' , 'rectified' ] ) : output = rectwv_coeff_to_ds9 ( rectwv_coeff = rectwv_coeff , limits = ... | Save the 4 possible ds9 region files . |
49,463 | def save_spectral_lines_ds9 ( rectwv_coeff , debugplot = 0 ) : for spectral_lines , rectified , suffix in zip ( [ 'arc' , 'arc' , 'oh' , 'oh' ] , [ False , True , False , True ] , [ 'rawimage' , 'rectified' , 'rawimage' , 'rectified' ] ) : output = spectral_lines_to_ds9 ( rectwv_coeff = rectwv_coeff , spectral_lines = ... | Save expected location of arc and OH airglow to ds9 region files . |
49,464 | def create_providerinfo ( self , capabilities ) : _pinfo = self . package_capabilities ( ) not_supported = { } for key , val in capabilities . items ( ) : try : allowed = _pinfo [ key ] except KeyError : _pinfo [ key ] = val else : if isinstance ( allowed , bool ) : if allowed is False : if val is True : not_supported ... | Dynamically create the provider info response |
49,465 | def _write_utf8 ( write , value ) : write ( 'h' , len ( value ) ) write . io . write ( value . encode ( 'utf-8' ) ) | Writes a length - prefixed UTF - 8 string . |
49,466 | def read ( cls , read , has_name = True ) : name = cls . _read_utf8 ( read ) if has_name else None if cls is TAG_Compound : final = { } while True : tag = read ( 'b' , 1 ) [ 0 ] if tag == 0 : break tmp = _tags [ tag ] . read ( read ) final [ tmp . name ] = tmp return cls ( final , name = name ) elif cls is TAG_List : t... | Read the tag in using the reader rd . If has_name is False skip reading the tag name . |
49,467 | def pretty ( self , indent = 0 , indent_str = ' ' ) : return '{0}{1}({2!r}): {3!r}' . format ( indent_str * indent , self . __class__ . __name__ , self . name , self . value ) | Pretty - print a tag in the same general style as Markus s example output . |
49,468 | def factory ( ec , code = None , token = None , refresh = None , ** kwargs ) : TTYPE = { 'code' : 'A' , 'token' : 'T' , 'refresh' : 'R' } args = { } if code : args [ 'code_handler' ] = init_token_handler ( ec , code , TTYPE [ 'code' ] ) if token : args [ 'access_token_handler' ] = init_token_handler ( ec , token , TTYP... | Create a token handler |
49,469 | def info ( self , token ) : _res = dict ( zip ( [ '_id' , 'type' , 'sid' , 'exp' ] , self . split_token ( token ) ) ) if _res [ 'type' ] != self . type : raise WrongTokenType ( _res [ 'type' ] ) else : _res [ 'handler' ] = self _res [ 'black_listed' ] = self . is_black_listed ( token ) return _res | Return token information . |
49,470 | def process_wildcard ( fractions ) : wildcard_zs = set ( ) total_fraction = 0.0 for z , fraction in fractions . items ( ) : if fraction == '?' : wildcard_zs . add ( z ) else : total_fraction += fraction if not wildcard_zs : return fractions balance_fraction = ( 1.0 - total_fraction ) / len ( wildcard_zs ) for z in wild... | Processes element with a wildcard ? weight fraction and returns composition balanced to 1 . 0 . |
49,471 | def generate_name ( atomic_fractions ) : if not atomic_fractions : return '' if len ( atomic_fractions ) == 1 : z = list ( atomic_fractions . keys ( ) ) [ 0 ] return pyxray . element_symbol ( z ) symbols = [ ] fractions = [ ] for z in sorted ( atomic_fractions . keys ( ) , reverse = True ) : symbols . append ( pyxray .... | Generates a name from the composition . The name is generated on the basis of a classical chemical formula . |
49,472 | def from_pure ( cls , z ) : return cls ( cls . _key , { z : 1.0 } , { z : 1.0 } , pyxray . element_symbol ( z ) ) | Creates a pure composition . |
49,473 | async def _collect_sample ( self , url , url_pattern ) : samples = [ ] urls = [ self . path_generator . generate_url ( url , url_pattern ) for _ in range ( self . confirmation_factor ) ] iterator = asyncio . as_completed ( [ self . _fetch_sample ( url ) for url in urls ] ) for promise in iterator : try : sig = await pr... | Sample collection is meant to be very tolerant to generic failures as failing to obtain the sample has important consequences on the results . |
49,474 | def get_boundaries ( bounddict_file , slitlet_number ) : bounddict = json . loads ( open ( bounddict_file . name ) . read ( ) ) pol_lower_boundary = None pol_upper_boundary = None xmin_lower = None xmax_lower = None xmin_upper = None xmax_upper = None csu_bar_slit_center = None slitlet_label = "slitlet" + str ( slitlet... | Read the bounddict json file and return the polynomial boundaries . |
49,475 | def _to_enos_roles ( roles ) : def to_host ( h ) : extra = { } for nic , roles in h [ "nics" ] : for role in roles : extra [ role ] = nic return Host ( h [ "host" ] , user = "root" , extra = extra ) enos_roles = { } for role , hosts in roles . items ( ) : enos_roles [ role ] = [ to_host ( h ) for h in hosts ] logger . ... | Transform the roles to use enoslib . host . Host hosts . |
49,476 | def _to_enos_networks ( networks ) : nets = [ ] for roles , network in networks : nets . append ( network . to_enos ( roles ) ) logger . debug ( nets ) return nets | Transform the networks returned by deploy5k . |
49,477 | def init ( self , force_deploy = False , client = None ) : _force_deploy = self . provider_conf . force_deploy self . provider_conf . force_deploy = _force_deploy or force_deploy self . _provider_conf = self . provider_conf . to_dict ( ) r = api . Resources ( self . _provider_conf , client = client ) r . launch ( ) rol... | Reserve and deploys the nodes according to the resources section |
49,478 | def destroy ( self ) : r = api . Resources ( self . provider_conf . to_dict ( ) ) r . destroy ( ) | Destroys the jobs . |
49,479 | def _find_wikipedia_names ( self , name_en ) : url = 'https://en.wikipedia.org/w/api.php' params = { 'action' : 'query' , 'titles' : name_en , 'prop' : 'langlinks' , 'lllimit' : 500 , 'format' : 'json' } r = requests . get ( url , params = params ) if not r : raise ValueError ( 'Could not find wikipedia page: {0}' . fo... | Finds all Wikipedia pages referring to the specified name in English and returns a dictionary where the keys are the language code and the values are the titles of the corresponding pages . |
49,480 | def append_response ( self , response ) : self . _responses . append ( response ) if 'Warning' in response . headers : LOGGER . warning ( 'HTTP %s %s Warning (%s): %s (attempt %s)' , response . request . method , response . request . url , response . code , response . headers [ 'Warning' ] , len ( self . _responses ) ) | Append the response to the stack of responses . |
49,481 | def body ( self ) : if not self . _responses : return None if self . _responses [ - 1 ] . code >= 400 : return self . _error_message ( ) return self . _deserialize ( ) | Returns the HTTP response body deserialized if possible . |
49,482 | def links ( self ) : if not self . _responses : return None if 'Link' in self . _responses [ - 1 ] . headers : links = [ ] for l in headers . parse_link ( self . _responses [ - 1 ] . headers [ 'Link' ] ) : link = { 'target' : l . target } link . update ( { k : v for ( k , v ) in l . parameters } ) links . append ( link... | Return the parsed link header if it was set returning a list of the links as a dict . |
49,483 | def _decode ( self , value ) : if isinstance ( value , list ) : return [ self . _decode ( v ) for v in value ] elif isinstance ( value , dict ) : return { self . _decode ( k ) : self . _decode ( v ) for k , v in value . items ( ) } elif isinstance ( value , bytes ) : return value . decode ( 'utf-8' ) return value | Decode bytes to UTF - 8 strings as a singe value list or dict . |
49,484 | def _deserialize ( self ) : if not self . _responses or not self . _responses [ - 1 ] . body : return None if 'Content-Type' not in self . _responses [ - 1 ] . headers : return self . _responses [ - 1 ] . body try : content_type = algorithms . select_content_type ( [ headers . parse_content_type ( self . _responses [ -... | Try and deserialize a response body based upon the specified content type . |
49,485 | def _error_message ( self ) : body = self . _deserialize ( ) return body . get ( 'message' , body ) if isinstance ( body , dict ) else body | Try and extract the error message from a HTTP error response . |
49,486 | async def http_fetch ( self , url , method = 'GET' , request_headers = None , body = None , content_type = CONTENT_TYPE_MSGPACK , follow_redirects = False , max_redirects = MAX_REDIRECTS , connect_timeout = DEFAULT_CONNECT_TIMEOUT , request_timeout = DEFAULT_REQUEST_TIMEOUT , max_http_attempts = MAX_HTTP_RETRIES , auth... | Perform a HTTP request |
49,487 | def _http_req_apply_default_headers ( self , request_headers , content_type , body ) : if not request_headers : request_headers = { } request_headers . setdefault ( 'Accept' , ', ' . join ( [ str ( ct ) for ct in AVAILABLE_CONTENT_TYPES ] ) ) if body : request_headers . setdefault ( 'Content-Type' , str ( content_type ... | Set default values for common HTTP request headers |
49,488 | def _http_req_body_serialize ( self , body , content_type ) : if not body or not isinstance ( body , ( dict , list ) ) : return body content_type = headers . parse_content_type ( content_type ) if content_type == CONTENT_TYPE_JSON : return self . __hcm_json . dumps ( body ) elif content_type == CONTENT_TYPE_MSGPACK : r... | Conditionally serialize the request body value if mime_type is set and it s serializable . |
49,489 | def _http_resp_rate_limited ( response ) : parsed = parse . urlparse ( response . request . url ) duration = int ( response . headers . get ( 'Retry-After' , 3 ) ) LOGGER . warning ( 'Rate Limited by %s, retrying in %i seconds' , parsed . netloc , duration ) return asyncio . sleep ( duration ) | Extract the Retry - After header value if the request was rate limited and return a future to sleep for the specified duration . |
49,490 | def acquires_lock ( expires , should_fail = True , should_wait = False , resource = None , prefix = DEFAULT_PREFIX ) : if isinstance ( expires , timedelta ) : expires = expires . total_seconds ( ) def decorator ( f ) : nonlocal resource if resource is None : resource = f . __name__ resource = '%s%s' % ( prefix , resour... | Decorator to ensure function only runs when it is unique holder of the resource . |
49,491 | def get_session ( ) : if os . environ . get ( "OS_IDENTITY_API_VERSION" ) == "3" : logging . info ( "Creating a v3 Keystone Session" ) auth = v3 . Password ( auth_url = os . environ [ "OS_AUTH_URL" ] , username = os . environ [ "OS_USERNAME" ] , password = os . environ [ "OS_PASSWORD" ] , project_id = os . environ [ "O... | Build the session object . |
49,492 | def check_glance ( session , image_name ) : gclient = glance . Client ( GLANCE_VERSION , session = session , region_name = os . environ [ 'OS_REGION_NAME' ] ) images = gclient . images . list ( ) name_ids = [ { 'name' : i [ 'name' ] , 'id' : i [ 'id' ] } for i in images ] if image_name not in list ( map ( itemgetter ( ... | Check that the base image is available . |
49,493 | def check_flavors ( session ) : nclient = nova . Client ( NOVA_VERSION , session = session , region_name = os . environ [ 'OS_REGION_NAME' ] ) flavors = nclient . flavors . list ( ) to_id = dict ( list ( map ( lambda n : [ n . name , n . id ] , flavors ) ) ) to_flavor = dict ( list ( map ( lambda n : [ n . id , n . nam... | Build the flavors mapping |
49,494 | def wait_for_servers ( session , servers ) : nclient = nova . Client ( NOVA_VERSION , session = session , region_name = os . environ [ 'OS_REGION_NAME' ] ) while True : deployed = [ ] undeployed = [ ] for server in servers : c = nclient . servers . get ( server . id ) if c . addresses != { } and c . status == 'ACTIVE' ... | Wait for the servers to be ready . |
49,495 | def check_servers ( session , machines , extra_prefix = "" , force_deploy = False , key_name = None , image_id = None , flavors = 'm1.medium' , network = None , ext_net = None , scheduler_hints = None ) : scheduler_hints = scheduler_hints or [ ] nclient = nova . Client ( NOVA_VERSION , session = session , region_name =... | Checks the servers status for the deployment . |
49,496 | def is_in_current_deployment ( server , extra_prefix = "" ) : return re . match ( r"^%s" % '-' . join ( [ DEFAULT_PREFIX , extra_prefix ] ) , server . name ) is not None | Check if an existing server in the system take part to the current deployment |
49,497 | def allow_address_pairs ( session , network , subnet ) : nclient = neutron . Client ( '2' , session = session , region_name = os . environ [ 'OS_REGION_NAME' ] ) ports = nclient . list_ports ( ) ports_to_update = filter ( lambda p : p [ 'network_id' ] == network [ 'id' ] , ports [ 'ports' ] ) logger . info ( '[nova]: A... | Allow several interfaces to be added and accessed from the other machines . |
49,498 | def check_environment ( provider_conf ) : session = get_session ( ) image_id = check_glance ( session , provider_conf . image ) flavor_to_id , id_to_flavor = check_flavors ( session ) ext_net , network , subnet = check_network ( session , provider_conf . configure_network , provider_conf . network , subnet = provider_c... | Check all ressources needed by Enos . |
49,499 | def collect_user_info ( endpoint_context , session , userinfo_claims = None ) : authn_req = session [ 'authn_req' ] if userinfo_claims is None : uic = scope2claims ( authn_req [ "scope" ] ) perm_set = session . get ( 'permission' ) if perm_set : uic = { key : uic [ key ] for key in uic if key in perm_set } uic = update... | Collect information about a user . This can happen in two cases either when constructing an IdToken or when returning user info through the UserInfo endpoint |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.