idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
45,300
def _assert_dirs_exist ( self , setting_name ) : v = self . _get_setting ( setting_name ) if ( not os . path . isdir ( os . path . split ( v ) [ 0 ] ) ) or os . path . isdir ( v ) : self . raise_config_error ( setting_name , v , str , 'a file path in an existing directory' , is_none_allowed = False , )
Check that the dirs leading up to the given file path exist .
45,301
def _warn_unsafe_for_prod ( self ) : safe_settings_list = [ ( 'DEBUG' , False ) , ( 'DEBUG_GMN' , False ) , ( 'STAND_ALONE' , False ) , ( 'DATABASES.default.ATOMIC_REQUESTS' , True ) , ( 'SECRET_KEY' , '<Do not modify this placeholder value>' ) , ( 'STATIC_SERVER' , False ) , ] for setting_str , setting_safe in safe_se...
Warn on settings that are not safe for production .
45,302
def _get_setting ( self , setting_dotted_name , default = None ) : name_list = setting_dotted_name . split ( '.' ) setting_obj = getattr ( django . conf . settings , name_list [ 0 ] , default ) return functools . reduce ( lambda o , a : o . get ( a , default ) , [ setting_obj ] + name_list [ 1 : ] )
Return the value of a potentially nested dict setting .
45,303
def _refresh_connection ( self ) : current_thread_id = threading . current_thread ( ) . ident if current_thread_id != self . connection_thread_id : prepare_connection ( ) self . connection_thread_id = current_thread_id
Refresh connection to Elasticsearch when worker is started .
45,304
def generate_id ( self , obj ) : object_type = type ( obj ) . __name__ . lower ( ) return '{}_{}' . format ( object_type , self . get_object_id ( obj ) )
Generate unique document id for ElasticSearch .
45,305
def process_object ( self , obj ) : document = self . document_class ( meta = { 'id' : self . generate_id ( obj ) } ) for field in document . _doc_type . mapping : if field in [ 'users_with_permissions' , 'groups_with_permissions' , 'public_permission' ] : continue try : get_value_function = getattr ( self , 'get_{}_va...
Process current object and push it to the ElasticSearch .
45,306
def create_mapping ( self ) : try : self . document_class . init ( ) self . _mapping_created = True except IllegalOperation as error : if error . args [ 0 ] . startswith ( 'You cannot update analysis configuration' ) : return raise
Create the mappings in elasticsearch .
45,307
def destroy ( self ) : self . _refresh_connection ( ) self . push_queue = [ ] index_name = self . document_class ( ) . _get_index ( ) connections . get_connection ( ) . indices . delete ( index_name , ignore = 404 ) self . _mapping_created = False
Destroy an index .
45,308
def get_permissions ( self , obj ) : filters = { 'object_pk' : obj . id , 'content_type' : ContentType . objects . get_for_model ( obj ) , 'permission__codename__startswith' : 'view' , } return { 'users' : list ( UserObjectPermission . objects . filter ( ** filters ) . distinct ( 'user' ) . values_list ( 'user_id' , fl...
Return users and groups with view permission on the current object .
45,309
def remove_object ( self , obj ) : obj_id = self . generate_id ( obj ) es_obj = self . document_class . get ( obj_id , ignore = [ 404 ] ) if es_obj : es_obj . delete ( refresh = True )
Remove current object from the ElasticSearch .
45,310
def generate_version_file ( self , schema_filename , binding_filename ) : version_filename = binding_filename + '_version.txt' version_path = os . path . join ( self . binding_dir , version_filename ) schema_path = os . path . join ( self . schema_dir , schema_filename ) try : tstamp , svnpath , svnrev , version = self...
Given a DataONE schema generates a file that contains version information about the schema .
45,311
def set_data_location ( apps , schema_editor ) : Data = apps . get_model ( 'flow' , 'Data' ) DataLocation = apps . get_model ( 'flow' , 'DataLocation' ) for data in Data . objects . all ( ) : if os . path . isdir ( os . path . join ( settings . FLOW_EXECUTOR [ 'DATA_DIR' ] , str ( data . id ) ) ) : with transaction . a...
Create DataLocation for each Data .
45,312
def _loadMore ( self , start = 0 , trys = 0 , validation = True ) : self . _log . debug ( "Loading page starting from %d" % start ) self . _czero = start self . _pageoffs = 0 try : pyxb . RequireValidWhenParsing ( validation ) self . _object_list = self . _client . listObjects ( start = start , count = self . _pagesize...
Retrieves the next page of results .
45,313
def _delete_chunked ( queryset , chunk_size = 500 ) : while True : with transaction . atomic ( ) : offset = queryset . order_by ( 'pk' ) [ : chunk_size ] . count ( ) if not offset : break last_instance = queryset . order_by ( 'pk' ) [ offset - 1 ] queryset . filter ( pk__lte = last_instance . pk ) . delete ( )
Chunked delete which should be used if deleting many objects .
45,314
def create_entity ( self ) : entity_type = self . process . entity_type entity_descriptor_schema = self . process . entity_descriptor_schema entity_input = self . process . entity_input if entity_type : data_filter = { } if entity_input : input_id = dict_dot ( self . input , entity_input , default = lambda : None ) if ...
Create entity if flow_collection is defined in process .
45,315
def save ( self , render_name = False , * args , ** kwargs ) : if self . name != self . _original_name : self . named_by_user = True create = self . pk is None if create : fill_with_defaults ( self . input , self . process . input_schema ) if not self . name : self . _render_name ( ) else : self . named_by_user = True ...
Save the data model .
45,316
def delete ( self , * args , ** kwargs ) : storage_ids = list ( self . storages . values_list ( 'pk' , flat = True ) ) super ( ) . delete ( * args , ** kwargs ) Storage . objects . filter ( pk__in = storage_ids , data = None ) . delete ( )
Delete the data model .
45,317
def _render_name ( self ) : if not self . process . data_name or self . named_by_user : return inputs = copy . deepcopy ( self . input ) hydrate_input_references ( inputs , self . process . input_schema , hydrate_values = False ) template_context = inputs try : name = render_template ( self . process , self . process ....
Render data name .
45,318
def get_path ( self , prefix = None , filename = None ) : prefix = prefix or settings . FLOW_EXECUTOR [ 'DATA_DIR' ] path = os . path . join ( prefix , self . subpath ) if filename : path = os . path . join ( path , filename ) return path
Compose data location path .
45,319
def get_runtime_path ( self , filename = None ) : return self . get_path ( prefix = settings . FLOW_EXECUTOR [ 'RUNTIME_DIR' ] , filename = filename )
Compose data runtime location path .
45,320
def get_data ( self , entity ) : data = self . _filter_queryset ( 'view_data' , entity . data . all ( ) ) return self . _serialize_data ( data )
Return serialized list of data objects on entity that user has view permission on .
45,321
def validate ( self ) : required_fields = ( 'slug' , 'name' , 'process_type' , 'version' ) for field in required_fields : if getattr ( self . metadata , field , None ) is None : raise ValidationError ( "process '{}' is missing required meta attribute: {}" . format ( self . metadata . slug or '<unknown>' , field ) ) if ...
Validate process descriptor .
45,322
def to_schema ( self ) : process_type = self . metadata . process_type if not process_type . endswith ( ':' ) : process_type = '{}:' . format ( process_type ) schema = { 'slug' : self . metadata . slug , 'name' : self . metadata . name , 'type' : process_type , 'version' : self . metadata . version , 'data_name' : '' ,...
Return process schema for this process .
45,323
def post_register_hook ( self , verbosity = 1 ) : if not getattr ( settings , 'FLOW_DOCKER_DONT_PULL' , False ) : call_command ( 'list_docker_images' , pull = True , verbosity = verbosity )
Pull Docker images needed by processes after registering .
45,324
def are_equal ( a_dt , b_dt , round_sec = 1 ) : ra_dt = round_to_nearest ( a_dt , round_sec ) rb_dt = round_to_nearest ( b_dt , round_sec ) logger . debug ( 'Rounded:' ) logger . debug ( '{} -> {}' . format ( a_dt , ra_dt ) ) logger . debug ( '{} -> {}' . format ( b_dt , rb_dt ) ) return normalize_datetime_to_utc ( ra_...
Determine if two datetimes are equal with fuzz factor .
45,325
def http_datetime_str_from_dt ( dt ) : epoch_seconds = ts_from_dt ( dt ) return email . utils . formatdate ( epoch_seconds , localtime = False , usegmt = True )
Format datetime to HTTP Full Date format .
45,326
def dt_from_http_datetime_str ( http_full_datetime ) : date_parts = list ( email . utils . parsedate ( http_full_datetime ) [ : 6 ] ) year = date_parts [ 0 ] if year <= 99 : year = year + 2000 if year < 50 else year + 1900 return create_utc_datetime ( year , * date_parts [ 1 : ] )
Parse HTTP Full Date formats and return as datetime .
45,327
def normalize_datetime_to_utc ( dt ) : return datetime . datetime ( * dt . utctimetuple ( ) [ : 6 ] , microsecond = dt . microsecond , tzinfo = datetime . timezone . utc )
Adjust datetime to UTC .
45,328
def cast_naive_datetime_to_tz ( dt , tz = UTC ( ) ) : if has_tz ( dt ) : return dt return dt . replace ( tzinfo = tz )
If datetime is tz - naive set it to tz . If datetime is tz - aware return it unmodified .
45,329
def round_to_nearest ( dt , n_round_sec = 1.0 ) : ts = ts_from_dt ( strip_timezone ( dt ) ) + n_round_sec / 2.0 res = dt_from_ts ( ts - ( ts % n_round_sec ) ) return res . replace ( tzinfo = dt . tzinfo )
Round datetime up or down to nearest divisor .
45,330
def submit ( self , data , runtime_dir , argv ) : limits = data . process . get_resource_limits ( ) logger . debug ( __ ( "Connector '{}' running for Data with id {} ({})." , self . __class__ . __module__ , data . id , repr ( argv ) ) ) partition = getattr ( settings , 'FLOW_SLURM_PARTITION_DEFAULT' , None ) if data . ...
Run process with SLURM .
45,331
def get_purge_files ( root , output , output_schema , descriptor , descriptor_schema ) : def remove_file ( fn , paths ) : while fn : for i in range ( len ( paths ) - 1 , - 1 , - 1 ) : if fn == paths [ i ] : paths . pop ( i ) fn , _ = os . path . split ( fn ) def remove_tree ( fn , paths ) : for i in range ( len ( paths...
Get files to purge .
45,332
def location_purge ( location_id , delete = False , verbosity = 0 ) : try : location = DataLocation . objects . get ( id = location_id ) except DataLocation . DoesNotExist : logger . warning ( "Data location does not exist" , extra = { 'location_id' : location_id } ) return unreferenced_files = set ( ) purged_data = Da...
Print and conditionally delete files not referenced by meta data .
45,333
def _storage_purge_all ( delete = False , verbosity = 0 ) : orphaned_storages = Storage . objects . filter ( data = None ) if verbosity >= 1 : if orphaned_storages . exists ( ) : logger . info ( __ ( "Unreferenced storages ({}):" , orphaned_storages . count ( ) ) ) for storage_id in orphaned_storages . values_list ( 'i...
Purge unreferenced storages .
45,334
def visit_ClassDef ( self , node ) : for base in node . bases : if isinstance ( base , ast . Name ) and isinstance ( base . ctx , ast . Load ) : base = getattr ( runtime , base . id , None ) elif isinstance ( base , ast . Attribute ) and isinstance ( base . ctx , ast . Load ) : base = getattr ( runtime , base . attr , ...
Visit top - level classes .
45,335
def parse ( self ) : root = ast . parse ( self . _source ) visitor = ProcessVisitor ( source = self . _source ) visitor . visit ( root ) return visitor . processes
Parse process .
45,336
def get_permissions_class ( permissions_name = None ) : def load_permissions ( permissions_name ) : try : return import_module ( '{}' . format ( permissions_name ) ) . ResolwePermissions except AttributeError : raise AttributeError ( "'ResolwePermissions' class not found in {} module." . format ( permissions_name ) ) e...
Load and cache permissions class .
45,337
def get_identifiers ( sysmeta_pyxb ) : pid = d1_common . xml . get_opt_val ( sysmeta_pyxb , 'identifier' ) sid = d1_common . xml . get_opt_val ( sysmeta_pyxb , 'seriesId' ) obsoletes_pid = d1_common . xml . get_opt_val ( sysmeta_pyxb , 'obsoletes' ) obsoleted_by_pid = d1_common . xml . get_opt_val ( sysmeta_pyxb , 'obs...
Get set of identifiers that provide revision context for SciObj .
45,338
def topological_sort ( unsorted_dict ) : sorted_list = [ ] sorted_set = set ( ) found = True unconnected_dict = unsorted_dict . copy ( ) while found : found = False for pid , obsoletes_pid in list ( unconnected_dict . items ( ) ) : if obsoletes_pid is None or obsoletes_pid in sorted_set : found = True sorted_list . app...
Sort objects by dependency .
45,339
def wrap ( indent_int , unwrap_str ) : with io . StringIO ( ) as str_buf : is_rest_block = unwrap_str . startswith ( ( "- " , "* " ) ) while unwrap_str : cut_pos = ( unwrap_str + " " ) . rfind ( " " , 0 , WRAP_MARGIN_INT - indent_int ) if cut_pos == - 1 : cut_pos = WRAP_MARGIN_INT this_str , unwrap_str = unwrap_str [ :...
Wrap a single line to one or more lines that start at indent_int and end at the last word that will fit before WRAP_MARGIN_INT .
45,340
def createSimpleResourceMap ( ore_pid , scimeta_pid , sciobj_pid_list ) : ore = ResourceMap ( ) ore . initialize ( ore_pid ) ore . addMetadataDocument ( scimeta_pid ) ore . addDataDocuments ( sciobj_pid_list , scimeta_pid ) return ore
Create a simple OAI - ORE Resource Map with one Science Metadata document and any number of Science Data objects .
45,341
def createResourceMapFromStream ( in_stream , base_url = d1_common . const . URL_DATAONE_ROOT ) : pids = [ ] for line in in_stream : pid = line . strip ( ) if pid == "#" or pid . startswith ( "# " ) : continue if len ( pids ) < 2 : raise ValueError ( "Insufficient numbers of identifiers provided." ) logging . info ( "R...
Create a simple OAI - ORE Resource Map with one Science Metadata document and any number of Science Data objects using a stream of PIDs .
45,342
def initialize ( self , pid , ore_software_id = d1_common . const . ORE_SOFTWARE_ID ) : for k in list ( d1_common . const . ORE_NAMESPACE_DICT . keys ( ) ) : self . bind ( k , d1_common . const . ORE_NAMESPACE_DICT [ k ] ) oid = self . _pid_to_id ( pid ) ore = rdflib . URIRef ( oid ) self . add ( ( ore , rdflib . RDF ....
Create the basic ORE document structure .
45,343
def serialize_to_transport ( self , doc_format = "xml" , * args , ** kwargs ) : return super ( ResourceMap , self ) . serialize ( format = doc_format , encoding = "utf-8" , * args , ** kwargs )
Serialize ResourceMap to UTF - 8 encoded XML document .
45,344
def serialize_to_display ( self , doc_format = "pretty-xml" , * args , ** kwargs ) : return ( super ( ResourceMap , self ) . serialize ( format = doc_format , encoding = None , * args , ** kwargs ) . decode ( "utf-8" ) )
Serialize ResourceMap to an XML doc that is pretty printed for display .
45,345
def deserialize ( self , * args , ** kwargs ) : self . parse ( * args , ** kwargs ) self . _ore_initialized = True
Deserialize Resource Map XML doc .
45,346
def addResource ( self , pid ) : self . _check_initialized ( ) try : self . getObjectByPid ( pid ) return except IndexError : pass oid = self . _pid_to_id ( pid ) obj = rdflib . URIRef ( oid ) ag = self . getAggregation ( ) self . add ( ( ag , ORE . aggregates , obj ) ) self . add ( ( obj , ORE . isAggregatedBy , ag ) ...
Add a resource to the Resource Map .
45,347
def setDocuments ( self , documenting_pid , documented_pid ) : self . _check_initialized ( ) documenting_id = self . getObjectByPid ( documenting_pid ) documented_id = self . getObjectByPid ( documented_pid ) self . add ( ( documenting_id , CITO . documents , documented_id ) )
Add a CiTO the Citation Typing Ontology triple asserting that documenting_pid documents documented_pid .
45,348
def setDocumentedBy ( self , documented_pid , documenting_pid ) : self . _check_initialized ( ) documented_id = self . getObjectByPid ( documented_pid ) documenting_id = self . getObjectByPid ( documenting_pid ) self . add ( ( documented_id , CITO . isDocumentedBy , documenting_id ) )
Add a CiTO the Citation Typing Ontology triple asserting that documented_pid isDocumentedBy documenting_pid .
45,349
def parseDoc ( self , doc_str , format = "xml" ) : self . parse ( data = doc_str , format = format ) self . _ore_initialized = True return self
Parse a OAI - ORE Resource Maps document .
45,350
def _pid_to_id ( self , pid ) : return d1_common . url . joinPathElements ( self . _base_url , self . _version_tag , "resolve" , d1_common . url . encodePathElement ( pid ) , )
Converts a pid to a URI that can be used as an OAI - ORE identifier .
45,351
def make_checksum_validation_script ( stats_list ) : if not os . path . exists ( './hash_check' ) : os . mkdir ( './hash_check' ) with open ( './hash_check/curl.sh' , 'w' ) as curl_f , open ( './hash_check/md5.txt' , 'w' ) as md5_f , open ( './hash_check/sha1.txt' , 'w' ) as sha1_f : curl_f . write ( '#!/usr/bin/env ba...
Make batch files required for checking checksums from another machine .
45,352
def update_dependency_kinds ( apps , schema_editor ) : DataDependency = apps . get_model ( 'flow' , 'DataDependency' ) for dependency in DataDependency . objects . all ( ) : dependency . kind = 'subprocess' child = dependency . child parent = dependency . parent for field_schema , fields in iterate_fields ( child . inp...
Update historical dependency kinds as they may be wrong .
45,353
def escape ( self , value ) : value = soft_unicode ( value ) if self . _engine . _escape is None : return value return self . _engine . _escape ( value )
Escape given value .
45,354
def _wrap_jinja_filter ( self , function ) : def wrapper ( * args , ** kwargs ) : try : return function ( * args , ** kwargs ) except Exception : return NestedUndefined ( ) for attribute in dir ( function ) : if attribute . endswith ( 'filter' ) : setattr ( wrapper , attribute , getattr ( function , attribute ) ) retur...
Propagate exceptions as undefined values filter .
45,355
def _register_custom_filters ( self ) : custom_filters = self . settings . get ( 'CUSTOM_FILTERS' , [ ] ) if not isinstance ( custom_filters , list ) : raise KeyError ( "`CUSTOM_FILTERS` setting must be a list." ) for filter_module_name in custom_filters : try : filter_module = import_module ( filter_module_name ) exce...
Register any custom filter modules .
45,356
def _evaluation_context ( self , escape , safe_wrapper ) : self . _escape = escape self . _safe_wrapper = safe_wrapper try : yield finally : self . _escape = None self . _safe_wrapper = None
Configure the evaluation context .
45,357
def evaluate_block ( self , template , context = None , escape = None , safe_wrapper = None ) : if context is None : context = { } try : with self . _evaluation_context ( escape , safe_wrapper ) : template = self . _environment . from_string ( template ) return template . render ( ** context ) except jinja2 . TemplateE...
Evaluate a template block .
45,358
def evaluate_inline ( self , expression , context = None , escape = None , safe_wrapper = None ) : if context is None : context = { } try : with self . _evaluation_context ( escape , safe_wrapper ) : compiled = self . _environment . compile_expression ( expression ) return compiled ( ** context ) except jinja2 . Templa...
Evaluate an inline expression .
45,359
def update_module_file ( redbaron_tree , module_path , show_diff = False , dry_run = False ) : with tempfile . NamedTemporaryFile ( ) as tmp_file : tmp_file . write ( redbaron_tree_to_module_str ( redbaron_tree ) ) tmp_file . seek ( 0 ) if are_files_equal ( module_path , tmp_file . name ) : logging . debug ( 'Source un...
Set show_diff to False to overwrite module_path with a new file generated from redbaron_tree .
45,360
def find_repo_root_by_path ( path ) : repo = git . Repo ( path , search_parent_directories = True ) repo_path = repo . git . rev_parse ( '--show-toplevel' ) logging . info ( 'Repository: {}' . format ( repo_path ) ) return repo_path
Given a path to an item in a git repository find the root of the repository .
45,361
def _format_value ( self , operation , key , indent ) : v = self . _find_value ( operation , key ) if v == "NOT_FOUND" : return [ ] if not isinstance ( v , list ) : v = [ v ] if not len ( v ) : v = [ None ] key = key + ":" lines = [ ] for s in v : if isinstance ( s , tuple ) : s = "{}: {}" . format ( * s ) lines . appe...
A value that exists in the operation but has value None is displayed .
45,362
def run_process ( self , slug , inputs ) : def export_files ( value ) : if isinstance ( value , str ) and os . path . isfile ( value ) : print ( "export {}" . format ( value ) ) elif isinstance ( value , dict ) : for item in value . values ( ) : export_files ( item ) elif isinstance ( value , list ) : for item in value...
Run a new process from a running process .
45,363
def info ( self , * args ) : report = resolwe_runtime_utils . info ( ' ' . join ( [ str ( x ) for x in args ] ) ) print ( report )
Log informational message .
45,364
def get_data_id_by_slug ( self , slug ) : resolwe_host = os . environ . get ( 'RESOLWE_HOST_URL' ) url = urllib . parse . urljoin ( resolwe_host , '/api/data?slug={}&fields=id' . format ( slug ) ) with urllib . request . urlopen ( url , timeout = 60 ) as f : data = json . loads ( f . read ( ) . decode ( 'utf-8' ) ) if ...
Find data object ID for given slug .
45,365
def requirements ( self ) : class dotdict ( dict ) : def __getattr__ ( self , attr ) : value = self . get ( attr ) return dotdict ( value ) if isinstance ( value , dict ) else value return dotdict ( self . _meta . metadata . requirements )
Process requirements .
45,366
def prepare_runtime ( self , runtime_dir , data ) : import resolwe . process as runtime_package src_dir = os . path . dirname ( inspect . getsourcefile ( runtime_package ) ) dest_package_dir = os . path . join ( runtime_dir , PYTHON_RUNTIME_DIRNAME , 'resolwe' , 'process' ) shutil . copytree ( src_dir , dest_package_di...
Prepare runtime directory .
45,367
def get_subject_with_local_validation ( jwt_bu64 , cert_obj ) : try : jwt_dict = validate_and_decode ( jwt_bu64 , cert_obj ) except JwtException as e : return log_jwt_bu64_info ( logging . error , str ( e ) , jwt_bu64 ) try : return jwt_dict [ 'sub' ] except LookupError : log_jwt_dict_info ( logging . error , 'Missing ...
Validate the JWT and return the subject it contains .
45,368
def get_subject_without_validation ( jwt_bu64 ) : try : jwt_dict = get_jwt_dict ( jwt_bu64 ) except JwtException as e : return log_jwt_bu64_info ( logging . error , str ( e ) , jwt_bu64 ) try : return jwt_dict [ 'sub' ] except LookupError : log_jwt_dict_info ( logging . error , 'Missing "sub" key' , jwt_dict )
Extract subject from the JWT without validating the JWT .
45,369
def get_jwt_dict ( jwt_bu64 ) : jwt_tup = get_jwt_tup ( jwt_bu64 ) try : jwt_dict = json . loads ( jwt_tup [ 0 ] . decode ( 'utf-8' ) ) jwt_dict . update ( json . loads ( jwt_tup [ 1 ] . decode ( 'utf-8' ) ) ) jwt_dict [ '_sig_sha1' ] = hashlib . sha1 ( jwt_tup [ 2 ] ) . hexdigest ( ) except TypeError as e : raise JwtE...
Parse Base64 encoded JWT and return as a dict .
45,370
def validate_and_decode ( jwt_bu64 , cert_obj ) : try : return jwt . decode ( jwt_bu64 . strip ( ) , cert_obj . public_key ( ) , algorithms = [ 'RS256' ] , verify = True ) except jwt . InvalidTokenError as e : raise JwtException ( 'Signature is invalid. error="{}"' . format ( str ( e ) ) )
Validate the JWT and return as a dict .
45,371
def log_jwt_dict_info ( log , msg_str , jwt_dict ) : d = ts_to_str ( jwt_dict ) log_list = [ ( b , d . pop ( a ) ) for a , b , c in CLAIM_LIST if a in d ] + [ ( k , d [ k ] ) for k in sorted ( d ) ] list ( map ( log , [ '{}:' . format ( msg_str ) ] + [ ' {}: {}' . format ( k , v ) for k , v in log_list ] , ) )
Dump JWT to log .
45,372
def ts_to_str ( jwt_dict ) : d = ts_to_dt ( jwt_dict ) for k , v in list ( d . items ( ) ) : if isinstance ( v , datetime . datetime ) : d [ k ] = v . isoformat ( ) . replace ( 'T' , ' ' ) return d
Convert timestamps in JWT to human readable dates .
45,373
def ts_to_dt ( jwt_dict ) : d = jwt_dict . copy ( ) for k , v in [ v [ : 2 ] for v in CLAIM_LIST if v [ 2 ] ] : if k in jwt_dict : d [ k ] = d1_common . date_time . dt_from_ts ( jwt_dict [ k ] ) return d
Convert timestamps in JWT to datetime objects .
45,374
def _escape ( self , value ) : if isinstance ( value , SafeString ) : return value return shellescape . quote ( value )
Escape given value unless it is safe .
45,375
def open_sciobj_file_by_pid_ctx ( pid , write = False ) : abs_path = get_abs_sciobj_file_path_by_pid ( pid ) with open_sciobj_file_by_path_ctx ( abs_path , write ) as sciobj_file : yield sciobj_file
Open the file containing the Science Object bytes of pid in the default location within the tree of the local SciObj store .
45,376
def open_sciobj_file_by_path_ctx ( abs_path , write = False ) : if write : d1_common . utils . filesystem . create_missing_directories_for_file ( abs_path ) try : with open ( abs_path , 'wb' if write else 'rb' ) as sciobj_file : yield sciobj_file finally : if os . path . exists ( abs_path ) and not os . path . getsize ...
Open the file containing the Science Object bytes at the custom location abs_path in the local filesystem .
45,377
def open_sciobj_file_by_pid ( pid , write = False ) : abs_path = get_abs_sciobj_file_path_by_pid ( pid ) if write : d1_common . utils . filesystem . create_missing_directories_for_file ( abs_path ) return open_sciobj_file_by_path ( abs_path , write )
Open the file containing the Science Object bytes at the custom location abs_path in the local filesystem for read .
45,378
def open_sciobj_file_by_path ( abs_path , write = False ) : if write : d1_common . utils . filesystem . create_missing_directories_for_file ( abs_path ) return open ( abs_path , 'wb' if write else 'rb' )
Open a SciObj file for read or write . If opened for write create any missing directories . For a SciObj stored in the default SciObj store the path includes the PID hash based directory levels .
45,379
def get_rel_sciobj_file_path ( pid ) : hash_str = hashlib . sha1 ( pid . encode ( 'utf-8' ) ) . hexdigest ( ) return os . path . join ( hash_str [ : 2 ] , hash_str [ 2 : 4 ] , hash_str )
Get the relative local path to the file holding an object s bytes .
45,380
def get_abs_sciobj_file_path_by_url ( file_url ) : assert_sciobj_store_exists ( ) m = re . match ( r'file://(.*?)/(.*)' , file_url , re . IGNORECASE ) if m . group ( 1 ) == RELATIVE_PATH_MAGIC_HOST_STR : return os . path . join ( get_abs_sciobj_store_path ( ) , m . group ( 2 ) ) assert os . path . isabs ( m . group ( 2...
Get the absolute path to the file holding an object s bytes .
45,381
def get_gmn_version ( base_url ) : home_url = d1_common . url . joinPathElements ( base_url , 'home' ) try : response = requests . get ( home_url , verify = False ) except requests . exceptions . ConnectionError as e : return False , str ( e ) if not response . ok : return False , 'invalid /home. status={}' . format ( ...
Return the version currently running on a GMN instance .
45,382
def extract_subjects ( subject_info_xml , primary_str ) : subject_info_pyxb = deserialize_subject_info ( subject_info_xml ) subject_info_tree = gen_subject_info_tree ( subject_info_pyxb , primary_str ) return subject_info_tree . get_subject_set ( )
Extract a set of authenticated subjects from a DataONE SubjectInfo .
45,383
def deserialize_subject_info ( subject_info_xml ) : try : return d1_common . xml . deserialize ( subject_info_xml ) except ValueError as e : raise d1_common . types . exceptions . InvalidToken ( 0 , 'Could not deserialize SubjectInfo. subject_info="{}", error="{}"' . format ( subject_info_xml , str ( e ) ) , )
Deserialize SubjectInfo XML doc to native object .
45,384
def gen_subject_info_tree ( subject_info_pyxb , authn_subj , include_duplicates = False ) : class State : pass state = State ( ) state . subject_info_pyxb = subject_info_pyxb state . include_duplicates = include_duplicates state . visited_set = set ( ) state . tree = SubjectInfoNode ( "Root" , TYPE_NODE_TAG ) _add_subj...
Convert the flat self referential lists in the SubjectInfo to a tree structure .
45,385
def _trim_tree ( state ) : for n in list ( state . tree . leaf_node_gen ) : if n . type_str == TYPE_NODE_TAG : n . parent . child_list . remove ( n ) return _trim_tree ( state )
Trim empty leaf nodes from the tree .
45,386
def get_path_str ( self , sep = os . path . sep , type_str = None ) : return sep . join ( list ( reversed ( [ v . label_str for v in self . parent_gen if type_str in ( None , v . type_str ) ] ) ) )
Get path from root to this node .
45,387
def get_leaf_node_path_list ( self , sep = os . path . sep , type_str = None ) : return [ v . get_path_str ( sep , type_str ) for v in self . leaf_node_gen ]
Get paths for all leaf nodes for the tree rooted at this node .
45,388
def get_path_list ( self , type_str = None ) : return list ( reversed ( [ v . label_str for v in self . parent_gen if type_str in ( None , v . type_str ) ] ) )
Get list of the labels of the nodes leading up to this node from the root .
45,389
def get_label_set ( self , type_str = None ) : return { v . label_str for v in self . node_gen if type_str in ( None , v . type_str ) }
Get a set of label_str for the tree rooted at this node .
45,390
def start_task_type ( self , task_type_str , total_task_count ) : assert ( task_type_str not in self . _task_dict ) , "Task type has already been started" self . _task_dict [ task_type_str ] = { "start_time" : time . time ( ) , "total_task_count" : total_task_count , "task_idx" : 0 , }
Call when about to start processing a new type of task typically just before entering a loop that processes many task of the given type .
45,391
def end_task_type ( self , task_type_str ) : assert ( task_type_str in self . _task_dict ) , "Task type has not been started yet: {}" . format ( task_type_str ) self . _log_progress ( ) del self . _task_dict [ task_type_str ]
Call when processing of all tasks of the given type is completed typically just after exiting a loop that processes many tasks of the given type .
45,392
def start_task ( self , task_type_str , current_task_index = None ) : assert ( task_type_str in self . _task_dict ) , "Task type has not been started yet: {}" . format ( task_type_str ) if current_task_index is not None : self . _task_dict [ task_type_str ] [ "task_idx" ] = current_task_index else : self . _task_dict [...
Call when processing is about to start on a single task of the given task type typically at the top inside of the loop that processes the tasks .
45,393
def event ( self , event_name ) : self . _event_dict . setdefault ( event_name , 0 ) self . _event_dict [ event_name ] += 1 self . _log_progress_if_interval_elapsed ( )
Register an event that occurred during processing of a task of the given type .
45,394
def admeig ( classname , f , m_u , m_d , m_s , m_c , m_b , m_e , m_mu , m_tau ) : args = f , m_u , m_d , m_s , m_c , m_b , m_e , m_mu , m_tau A = getattr ( adm , 'adm_s_' + classname ) ( * args ) perm_keys = get_permissible_wcs ( classname , f ) if perm_keys != 'all' : A = A [ perm_keys ] [ : , perm_keys ] w , v = np ....
Compute the eigenvalues and eigenvectors for a QCD anomalous dimension matrix that is defined in adm . adm_s_X where X is the name of the sector .
45,395
def run_sector ( sector , C_in , eta_s , f , p_in , p_out , qed_order = 1 , qcd_order = 1 ) : r Cdictout = OrderedDict ( ) classname = sectors [ sector ] keylist = coeffs [ sector ] if sector == 'dF=0' : perm_keys = get_permissible_wcs ( 'dF0' , f ) else : perm_keys = get_permissible_wcs ( sector , f ) if perm_keys != ...
r Solve the WET RGE for a specific sector .
45,396
def _merge_region_trees ( self , dst_tree , src_tree , pid ) : for k , v in list ( src_tree . items ( ) ) : if k not in dst_tree or dst_tree [ k ] is None : dst_tree [ k ] = { } dst_tree [ k ] [ pid ] = None if v is not None : self . _merge_region_trees ( dst_tree [ k ] , v , pid )
Merge conflicts occur if a folder in one tree is a file in the other .
45,397
def save ( self , ** kwargs ) : try : return super ( ) . save ( ** kwargs ) except SlugError as error : raise ParseError ( error )
Override save method to catch handled errors and repackage them as 400 errors .
45,398
def get_api_major_by_base_url ( base_url , * client_arg_list , ** client_arg_dict ) : api_major = 0 client = d1_client . mnclient . MemberNodeClient ( base_url , * client_arg_list , ** client_arg_dict ) node_pyxb = client . getCapabilities ( ) for service_pyxb in node_pyxb . services . service : if service_pyxb . avail...
Read the Node document from a node and return an int containing the latest D1 API version supported by the node .
45,399
def delete_unused_subjects ( ) : query = d1_gmn . app . models . Subject . objects . all ( ) query = query . filter ( scienceobject_submitter__isnull = True ) query = query . filter ( scienceobject_rights_holder__isnull = True ) query = query . filter ( eventlog__isnull = True ) query = query . filter ( permission__isn...
Delete any unused subjects from the database .