idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
23,900
def _do_lumping ( self ) : right_eigenvectors = self . right_eigenvectors_ [ : , 1 : ] assert self . n_states_ > 0 microstate_mapping = np . zeros ( self . n_states_ , dtype = int ) def spread ( x ) : return x . max ( ) - x . min ( ) for i in range ( self . n_macrostates - 1 ) : v = right_eigenvectors [ : , i ] all_spr...
Do the PCCA lumping .
23,901
def metastability ( alpha , T , right_eigenvectors , square_map , pi ) : num_micro , num_eigen = right_eigenvectors . shape A , chi , mapping = calculate_fuzzy_chi ( alpha , square_map , right_eigenvectors ) if ( len ( np . unique ( mapping ) ) != right_eigenvectors . shape [ 1 ] or has_constraint_violation ( A , right...
Return the metastability PCCA + objective function .
23,902
def crispness ( alpha , T , right_eigenvectors , square_map , pi ) : A , chi , mapping = calculate_fuzzy_chi ( alpha , square_map , right_eigenvectors ) if ( len ( np . unique ( mapping ) ) != right_eigenvectors . shape [ 1 ] or has_constraint_violation ( A , right_eigenvectors ) ) : return - 1.0 * np . inf obj = tr ( ...
Return the crispness PCCA + objective function .
23,903
def get_maps ( A ) : N = A . shape [ 0 ] flat_map = [ ] for i in range ( 1 , N ) : for j in range ( 1 , N ) : flat_map . append ( [ i , j ] ) flat_map = np . array ( flat_map ) square_map = np . zeros ( A . shape , 'int' ) for k in range ( ( N - 1 ) ** 2 ) : i , j = flat_map [ k ] square_map [ i , j ] = k return flat_m...
Get mappings from the square array A to the flat vector of parameters alpha .
23,904
def has_constraint_violation ( A , right_eigenvectors , epsilon = 1E-8 ) : lhs = 1 - A [ 0 , 1 : ] . sum ( ) rhs = dot ( right_eigenvectors [ : , 1 : ] , A [ 1 : , 0 ] ) rhs = - 1 * rhs . min ( ) if abs ( lhs - rhs ) > epsilon : return True else : return False
Check for constraint violations in transformation matrix .
23,905
def index_search ( right_eigenvectors ) : num_micro , num_eigen = right_eigenvectors . shape index = np . zeros ( num_eigen , 'int' ) index [ 0 ] = np . argmax ( [ norm ( right_eigenvectors [ i ] ) for i in range ( num_micro ) ] ) ortho_sys = right_eigenvectors - np . outer ( np . ones ( num_micro ) , right_eigenvector...
Find simplex structure in eigenvectors to begin PCCA + .
23,906
def fill_A ( A , right_eigenvectors ) : num_micro , num_eigen = right_eigenvectors . shape A = A . copy ( ) A [ 1 : , 0 ] = - 1 * A [ 1 : , 1 : ] . sum ( 1 ) A [ 0 ] = - 1 * dot ( right_eigenvectors [ : , 1 : ] . real , A [ 1 : ] ) . min ( 0 ) A /= A [ 0 ] . sum ( ) return A
Construct feasible initial guess for transformation matrix A .
23,907
def _do_lumping ( self ) : right_eigenvectors = self . right_eigenvectors_ [ : , : self . n_macrostates ] index = index_search ( right_eigenvectors ) A = right_eigenvectors [ index , : ] A = inv ( A ) A = fill_A ( A , right_eigenvectors ) if self . do_minimization : A = self . _optimize_A ( A ) self . A_ = fill_A ( A ,...
Perform PCCA + algorithm by optimizing transformation matrix A .
23,908
def _optimize_A ( self , A ) : right_eigenvectors = self . right_eigenvectors_ [ : , : self . n_macrostates ] flat_map , square_map = get_maps ( A ) alpha = to_flat ( 1.0 * A , flat_map ) def obj ( x ) : return - 1 * self . _objective_function ( x , self . transmat_ , right_eigenvectors , square_map , self . population...
Find optimal transformation matrix A by minimization .
23,909
def _solve_msm_eigensystem ( transmat , k ) : u , lv , rv = scipy . linalg . eig ( transmat , left = True , right = True ) order = np . argsort ( - np . real ( u ) ) u = np . real_if_close ( u [ order [ : k ] ] ) lv = np . real_if_close ( lv [ : , order [ : k ] ] ) rv = np . real_if_close ( rv [ : , order [ : k ] ] ) r...
Find the dominant eigenpairs of an MSM transition matrix
23,910
def _normalize_eigensystem ( u , lv , rv ) : lv [ : , 0 ] = lv [ : , 0 ] / np . sum ( lv [ : , 0 ] ) for i in range ( 1 , lv . shape [ 1 ] ) : lv [ : , i ] = lv [ : , i ] / np . sqrt ( np . dot ( lv [ : , i ] , lv [ : , i ] / lv [ : , 0 ] ) ) for i in range ( rv . shape [ 1 ] ) : rv [ : , i ] = rv [ : , i ] / np . dot ...
Normalize the eigenvectors of a reversible Markov state model according to our preferred scheme .
23,911
def _strongly_connected_subgraph ( counts , weight = 1 , verbose = True ) : n_states_input = counts . shape [ 0 ] n_components , component_assignments = csgraph . connected_components ( csr_matrix ( counts >= weight ) , connection = "strong" ) populations = np . array ( counts . sum ( 0 ) ) . flatten ( ) component_pops...
Trim a transition count matrix down to its maximal strongly ergodic subgraph .
23,912
def _transition_counts ( sequences , lag_time = 1 , sliding_window = True ) : if ( not sliding_window ) and lag_time > 1 : return _transition_counts ( [ X [ : : lag_time ] for X in sequences ] , lag_time = 1 ) classes = np . unique ( np . concatenate ( sequences ) ) contains_nan = ( classes . dtype . kind == 'f' ) and ...
Count the number of directed transitions in a collection of sequences in a discrete space .
23,913
def partial_transform ( self , sequence , mode = 'clip' ) : if mode not in [ 'clip' , 'fill' ] : raise ValueError ( 'mode must be one of ["clip", "fill"]: %s' % mode ) sequence = np . asarray ( sequence ) if sequence . ndim != 1 : raise ValueError ( "Each sequence must be 1D" ) f = np . vectorize ( lambda k : self . ma...
Transform a sequence to internal indexing
23,914
def transform ( self , sequences , mode = 'clip' ) : if mode not in [ 'clip' , 'fill' ] : raise ValueError ( 'mode must be one of ["clip", "fill"]: %s' % mode ) sequences = list_of_1d ( sequences ) result = [ ] for y in sequences : if mode == 'fill' : result . append ( self . partial_transform ( y , mode ) ) elif mode ...
Transform a list of sequences to internal indexing
23,915
def _parse_ergodic_cutoff ( self ) : ec_is_str = isinstance ( self . ergodic_cutoff , str ) if ec_is_str and self . ergodic_cutoff . lower ( ) == 'on' : if self . sliding_window : return 1.0 / self . lag_time else : return 1.0 elif ec_is_str and self . ergodic_cutoff . lower ( ) == 'off' : return 0.0 else : return self...
Get a numeric value from the ergodic_cutoff input which can be on or off .
23,916
def inverse_transform ( self , sequences ) : sequences = list_of_1d ( sequences ) inverse_mapping = { v : k for k , v in self . mapping_ . items ( ) } f = np . vectorize ( inverse_mapping . get ) result = [ ] for y in sequences : uq = np . unique ( y ) if not np . all ( np . logical_and ( 0 <= uq , uq < self . n_states...
Transform a list of sequences from internal indexing into labels
23,917
def sample_discrete ( self , state = None , n_steps = 100 , random_state = None ) : r random = check_random_state ( random_state ) r = random . rand ( 1 + n_steps ) if state is None : initial = np . sum ( np . cumsum ( self . populations_ ) < r [ 0 ] ) elif hasattr ( state , '__len__' ) and len ( state ) == self . n_st...
r Generate a random sequence of states by propagating the model using discrete time steps given by the model lagtime .
23,918
def draw_samples ( self , sequences , n_samples , random_state = None ) : if not any ( [ isinstance ( seq , collections . Iterable ) for seq in sequences ] ) : sequences = [ sequences ] random = check_random_state ( random_state ) selected_pairs_by_state = [ ] for state in range ( self . n_states_ ) : all_frames = [ np...
Sample conformations for a sequences of states .
23,919
def _do_lumping ( self ) : model = LandmarkAgglomerative ( linkage = 'ward' , n_clusters = self . n_macrostates , metric = self . metric , n_landmarks = self . n_landmarks , landmark_strategy = self . landmark_strategy , random_state = self . random_state ) model . fit ( [ self . transmat_ ] ) if self . fit_only : micr...
Do the MVCA lumping .
23,920
def _truncate ( self , x , k ) : not_F = np . argsort ( np . abs ( x ) ) [ : - k ] x [ not_F ] = 0 return x
given a vector x leave its top - k absolute - value entries alone and set the rest to 0
23,921
def _truncated_power_method ( self , A , x0 , k , max_iter = 10000 , thresh = 1e-8 ) : xts = [ x0 ] for t in range ( max_iter ) : xts . append ( self . _normalize ( self . _truncate ( np . dot ( A , xts [ - 1 ] ) , k ) ) ) if np . linalg . norm ( xts [ - 1 ] - xts [ - 2 ] ) < thresh : break return xts [ - 1 ]
given a matrix A an initial guess x0 and a maximum cardinality k find the best k - sparse approximation to its dominant eigenvector
23,922
def _run ( self ) : n_macrostates = 1 metaQ = - 1.0 prevQ = - 1.0 global_maxQ = - 1.0 local_maxQ = - 1.0 for iter in range ( self . max_iter ) : self . __max_state = - 1 self . __micro_stack = [ ] for k in range ( n_macrostates ) : self . _do_split ( micro_state = k , sub_clus = self . sub_clus ) self . _do_time_cluste...
Do the APM lumping .
23,923
def get_atompair_indices ( reference_traj , keep_atoms = None , exclude_atoms = None , reject_bonded = True ) : if keep_atoms is None : keep_atoms = ATOM_NAMES top , bonds = reference_traj . top . to_dataframe ( ) if keep_atoms is not None : atom_indices = top [ top . name . isin ( keep_atoms ) == True ] . index . valu...
Get a list of acceptable atom pairs .
23,924
def sample_dimension ( trajs , dimension , n_frames , scheme = "linear" ) : fixed_indices = list ( trajs . keys ( ) ) trajs = [ trajs [ k ] [ : , [ dimension ] ] for k in fixed_indices ] txx = np . concatenate ( [ traj [ : , 0 ] for traj in trajs ] ) if scheme == "linear" : spaced_points = np . linspace ( np . min ( tx...
Sample a dimension of the data .
23,925
def fit ( self , X , y = None ) : X = array2d ( X ) self . n_features = X . shape [ 1 ] self . n_bins = self . n_bins_per_feature ** self . n_features if self . min is None : min = np . min ( X , axis = 0 ) elif isinstance ( self . min , numbers . Number ) : min = self . min * np . ones ( self . n_features ) else : min...
Fit the grid
23,926
def predict ( self , X ) : if np . any ( X < self . grid [ : , 0 ] ) or np . any ( X > self . grid [ : , - 1 ] ) : raise ValueError ( 'data out of min/max bounds' ) binassign = np . zeros ( ( self . n_features , len ( X ) ) , dtype = int ) for i in range ( self . n_features ) : binassign [ i ] = np . digitize ( X [ : ,...
Get the index of the grid cell containing each sample in X
23,927
def _check_same_length ( self , trajs_tuple ) : lens = [ len ( trajs ) for trajs in trajs_tuple ] if len ( set ( lens ) ) > 1 : err = "Each dataset must be the same length. You gave: {}" err = err . format ( lens ) raise ValueError ( err )
Check that the datasets are the same length
23,928
def transform ( self , trajs_tuple , y = None ) : return [ self . partial_transform ( traj_zip ) for traj_zip in zip ( * trajs_tuple ) ]
Featurize a several trajectories .
23,929
def backup ( fn ) : if not os . path . exists ( fn ) : return backnum = 1 backfmt = "{fn}.bak.{backnum}" trial_fn = backfmt . format ( fn = fn , backnum = backnum ) while os . path . exists ( trial_fn ) : backnum += 1 trial_fn = backfmt . format ( fn = fn , backnum = backnum ) warnings . warn ( "{fn} exists. Moving it ...
If fn exists rename it and issue a warning
23,930
def default_key_to_path ( key , dfmt = "{}" , ffmt = "{}.npy" ) : if isinstance ( key , tuple ) : paths = [ dfmt . format ( k ) for k in key [ : - 1 ] ] paths += [ ffmt . format ( key [ - 1 ] ) ] return os . path . join ( * paths ) else : return ffmt . format ( key )
Turn an arbitrary python object into a filename
23,931
def preload_tops ( meta ) : top_fns = set ( meta [ 'top_fn' ] ) tops = { } for tfn in top_fns : tops [ tfn ] = md . load_topology ( tfn ) return tops
Load all topology files into memory .
23,932
def preload_top ( meta ) : top_fns = set ( meta [ 'top_fn' ] ) if len ( top_fns ) != 1 : raise ValueError ( "More than one topology is used in this project!" ) return md . load_topology ( top_fns . pop ( ) )
Load one topology file into memory .
23,933
def itertrajs ( meta , stride = 1 ) : tops = preload_tops ( meta ) for i , row in meta . iterrows ( ) : yield i , md . join ( md . iterload ( row [ 'traj_fn' ] , top = tops [ row [ 'top_fn' ] ] , stride = stride ) , discard_overlapping_frames = False , check_topology = False )
Load one mdtraj trajectory at a time and yield it .
23,934
def render_meta ( meta , fn = "meta.pandas.html" , title = "Project Metadata - MSMBuilder" , pandas_kwargs = None ) : if pandas_kwargs is None : pandas_kwargs = { } kwargs_with_defaults = { 'classes' : ( 'table' , 'table-condensed' , 'table-hover' ) , } kwargs_with_defaults . update ( ** pandas_kwargs ) env = Environme...
Render a metadata dataframe as an html webpage for inspection .
23,935
def save_generic ( obj , fn ) : backup ( fn ) with open ( fn , 'wb' ) as f : pickle . dump ( obj , f )
Save Python objects including msmbuilder Estimators .
23,936
def save_trajs ( trajs , fn , meta , key_to_path = None ) : if key_to_path is None : key_to_path = default_key_to_path validate_keys ( meta . index , key_to_path ) backup ( fn ) os . mkdir ( fn ) for k in meta . index : v = trajs [ k ] npy_fn = os . path . join ( fn , key_to_path ( k ) ) os . makedirs ( os . path . dir...
Save trajectory - like data
23,937
def load_trajs ( fn , meta = 'meta.pandas.pickl' , key_to_path = None ) : if key_to_path is None : key_to_path = default_key_to_path if isinstance ( meta , str ) : meta = load_meta ( meta_fn = meta ) trajs = { } for k in meta . index : trajs [ k ] = np . load ( os . path . join ( fn , key_to_path ( k ) ) ) return meta ...
Load trajectory - like data
23,938
def query ( self , x , k = 1 , p = 2 , distance_upper_bound = np . inf ) : cdists , cinds = self . _kdtree . query ( x , k , p , distance_upper_bound ) return cdists , self . _split_indices ( cinds )
Query the kd - tree for nearest neighbors
23,939
def transform ( self , sequences ) : check_iter_of_sequences ( sequences ) transforms = [ ] for X in sequences : transforms . append ( self . partial_transform ( X ) ) return transforms
Apply dimensionality reduction to sequences
23,940
def fit_transform ( self , sequences , y = None ) : self . fit ( sequences ) transforms = self . transform ( sequences ) return transforms
Fit the model and apply dimensionality reduction
23,941
def fit ( self , sequences , y = None ) : check_iter_of_sequences ( sequences , allow_trajectory = self . _allow_trajectory ) super ( MultiSequenceClusterMixin , self ) . fit ( self . _concat ( sequences ) ) if hasattr ( self , 'labels_' ) : self . labels_ = self . _split ( self . labels_ ) return self
Fit the clustering on the data
23,942
def predict ( self , sequences , y = None ) : predictions = [ ] check_iter_of_sequences ( sequences , allow_trajectory = self . _allow_trajectory ) for X in sequences : predictions . append ( self . partial_predict ( X ) ) return predictions
Predict the closest cluster each sample in each sequence in sequences belongs to .
23,943
def fit_predict ( self , sequences , y = None ) : if hasattr ( super ( MultiSequenceClusterMixin , self ) , 'fit_predict' ) : check_iter_of_sequences ( sequences , allow_trajectory = self . _allow_trajectory ) labels = super ( MultiSequenceClusterMixin , self ) . fit_predict ( sequences ) else : self . fit ( sequences ...
Performs clustering on X and returns cluster labels .
23,944
def plot ( self , minx = - 1.5 , maxx = 1.2 , miny = - 0.2 , maxy = 2 , ** kwargs ) : import matplotlib . pyplot as pp grid_width = max ( maxx - minx , maxy - miny ) / 200.0 ax = kwargs . pop ( 'ax' , None ) xx , yy = np . mgrid [ minx : maxx : grid_width , miny : maxy : grid_width ] V = self . potential ( xx , yy ) if...
Helper function to plot the Muller potential
23,945
def gather_metadata ( fn_glob , parser ) : meta = pd . DataFrame ( parser . parse_fn ( fn ) for fn in glob . iglob ( fn_glob ) ) return meta . set_index ( parser . index ) . sort_index ( )
Given a glob and a parser object create a metadata dataframe .
23,946
def eigtransform ( self , sequences , right = True , mode = 'clip' ) : r result = [ ] for y in self . transform ( sequences , mode = mode ) : if right : op = self . right_eigenvectors_ [ : , 1 : ] else : op = self . left_eigenvectors_ [ : , 1 : ] is_finite = np . isfinite ( y ) if not np . all ( is_finite ) : value = n...
r Transform a list of sequences by projecting the sequences onto the first n_timescales dynamical eigenvectors .
23,947
def score_ll ( self , sequences ) : r counts , mapping = _transition_counts ( sequences ) if not set ( self . mapping_ . keys ( ) ) . issuperset ( mapping . keys ( ) ) : return - np . inf inverse_mapping = { v : k for k , v in mapping . items ( ) } m2 = _dict_compose ( inverse_mapping , self . mapping_ ) indices = [ e ...
r log of the likelihood of sequences with respect to the model
23,948
def summarize ( self ) : doc = counts_nz = np . count_nonzero ( self . countsmat_ ) cnz = self . countsmat_ [ np . nonzero ( self . countsmat_ ) ] return doc . format ( lag_time = self . lag_time , reversible_type = self . reversible_type , ergodic_cutoff = self . ergodic_cutoff , prior_counts = self . prior_counts , n...
Return some diagnostic summary statistics about this Markov model
23,949
def timescales_ ( self ) : u , lv , rv = self . _get_eigensystem ( ) with np . errstate ( invalid = 'ignore' , divide = 'ignore' ) : timescales = - self . lag_time / np . log ( u [ 1 : ] ) return timescales
Implied relaxation timescales of the model .
23,950
def uncertainty_eigenvalues ( self ) : if self . reversible_type is None : raise NotImplementedError ( 'reversible_type must be "mle" or "transpose"' ) n_timescales = min ( self . n_timescales if self . n_timescales is not None else self . n_states_ - 1 , self . n_states_ - 1 ) u , lv , rv = self . _get_eigensystem ( )...
Estimate of the element - wise asymptotic standard deviation in the model eigenvalues .
23,951
def uncertainty_timescales ( self ) : u = self . eigenvalues_ [ 1 : ] sigma_eigs = self . uncertainty_eigenvalues ( ) [ 1 : ] sigma_ts = sigma_eigs / ( u * np . log ( u ) ** 2 ) return sigma_ts
Estimate of the element - wise asymptotic standard deviation in the model implied timescales .
23,952
def describe_features ( self , traj ) : all_res = [ ] for feat in self . which_feat : all_res . extend ( self . features [ feat ] . describe_features ( traj ) ) return all_res
Return a list of dictionaries describing the features . Follows the ordering of featurizers in self . which_feat .
23,953
def partial_transform ( self , sequence ) : s = super ( MultiSequencePreprocessingMixin , self ) return s . transform ( sequence )
Apply preprocessing to single sequence
23,954
def retry ( max_retries = 1 ) : def retry_func ( func ) : @ wraps ( func ) def wrapper ( * args , ** kwargs ) : num_retries = 0 while num_retries <= max_retries : try : ret = func ( * args , ** kwargs ) break except HTTPError : if num_retries == max_retries : raise num_retries += 1 time . sleep ( 5 ) return ret return ...
Retry a function max_retries times .
23,955
def get_data_home ( data_home = None ) : if data_home is not None : return _expand_and_makedir ( data_home ) msmb_data = has_msmb_data ( ) if msmb_data is not None : return _expand_and_makedir ( msmb_data ) data_home = environ . get ( 'MSMBUILDER_DATA' , join ( '~' , 'msmbuilder_data' ) ) return _expand_and_makedir ( d...
Return the path of the msmbuilder data dir .
23,956
def description ( cls ) : lines = [ s . strip ( ) for s in cls . __doc__ . splitlines ( ) ] note_i = lines . index ( "Notes" ) return "\n" . join ( lines [ note_i + 2 : ] )
Get a description from the Notes section of the docstring .
23,957
def wildcard_allowed_actions ( self , pattern = None ) : wildcard_allowed = [ ] for statement in self . statements : if statement . wildcard_actions ( pattern ) and statement . effect == "Allow" : wildcard_allowed . append ( statement ) return wildcard_allowed
Find statements which allow wildcard actions .
23,958
def wildcard_allowed_principals ( self , pattern = None ) : wildcard_allowed = [ ] for statement in self . statements : if statement . wildcard_principals ( pattern ) and statement . effect == "Allow" : wildcard_allowed . append ( statement ) return wildcard_allowed
Find statements which allow wildcard principals .
23,959
def nonwhitelisted_allowed_principals ( self , whitelist = None ) : if not whitelist : return [ ] nonwhitelisted = [ ] for statement in self . statements : if statement . non_whitelisted_principals ( whitelist ) and statement . effect == "Allow" : nonwhitelisted . append ( statement ) return nonwhitelisted
Find non whitelisted allowed principals .
23,960
def allows_not_principal ( self ) : not_principals = [ ] for statement in self . statements : if statement . not_principal and statement . effect == "Allow" : not_principals . append ( statement ) return not_principals
Find allowed not - principals .
23,961
def parse_parameters ( self , parameters ) : self . parameters = [ ] for param_name , param_value in parameters . items ( ) : p = Parameter ( param_name , param_value ) if p : self . parameters . append ( p )
Parses and sets parameters in the model .
23,962
def parse_resources ( self , resources ) : self . resources = { } resource_factory = ResourceFactory ( ) for res_id , res_value in resources . items ( ) : r = resource_factory . create_resource ( res_id , res_value ) if r : if r . resource_type in self . resources : self . resources [ r . resource_type ] . append ( r )...
Parses and sets resources in the model using a factory .
23,963
def session ( self ) : if self . _session is None : self . _session = requests . Session ( ) self . _session . headers . update ( self . _headers ) return self . _session
Get session object to benefit from connection pooling .
23,964
def open_id_connect ( self , client_id , client_secret ) : return KeycloakOpenidConnect ( realm = self , client_id = client_id , client_secret = client_secret )
Get OpenID Connect client
23,965
def create ( self , username , ** kwargs ) : payload = OrderedDict ( username = username ) for key in USER_KWARGS : from keycloak . admin . clientroles import to_camel_case if key in kwargs : payload [ to_camel_case ( key ) ] = kwargs [ key ] return self . _client . post ( url = self . _client . get_full_url ( self . g...
Create a user in Keycloak
23,966
def all ( self ) : return self . _client . get ( url = self . _client . get_full_url ( self . get_path ( 'collection' , realm = self . _realm_name ) ) )
Return all registered users
23,967
def get ( self ) : self . _user = self . _client . get ( url = self . _client . get_full_url ( self . get_path ( 'single' , realm = self . _realm_name , user_id = self . _user_id ) ) ) self . _user_id = self . user [ "id" ] return self . _user
Return registered user with the given user id .
23,968
def update ( self , ** kwargs ) : payload = { } for k , v in self . user . items ( ) : payload [ k ] = v for key in USER_KWARGS : from keycloak . admin . clientroles import to_camel_case if key in kwargs : payload [ to_camel_case ( key ) ] = kwargs [ key ] result = self . _client . put ( url = self . _client . get_full...
Update existing user .
23,969
def resource_set_create ( self , token , name , ** kwargs ) : return self . _realm . client . post ( self . well_known [ 'resource_registration_endpoint' ] , data = self . _get_data ( name = name , ** kwargs ) , headers = self . get_headers ( token ) )
Create a resource set .
23,970
def resource_set_update ( self , token , id , name , ** kwargs ) : return self . _realm . client . put ( '{}/{}' . format ( self . well_known [ 'resource_registration_endpoint' ] , id ) , data = self . _get_data ( name = name , ** kwargs ) , headers = self . get_headers ( token ) )
Update a resource set .
23,971
def resource_set_read ( self , token , id ) : return self . _realm . client . get ( '{}/{}' . format ( self . well_known [ 'resource_registration_endpoint' ] , id ) , headers = self . get_headers ( token ) )
Read a resource set .
23,972
def resource_create_ticket ( self , token , id , scopes , ** kwargs ) : data = dict ( resource_id = id , resource_scopes = scopes , ** kwargs ) return self . _realm . client . post ( self . well_known [ 'permission_endpoint' ] , data = self . _dumps ( [ data ] ) , headers = self . get_headers ( token ) )
Create a ticket form permission to resource .
23,973
def resource_associate_permission ( self , token , id , name , scopes , ** kwargs ) : return self . _realm . client . post ( '{}/{}' . format ( self . well_known [ 'policy_endpoint' ] , id ) , data = self . _get_data ( name = name , scopes = scopes , ** kwargs ) , headers = self . get_headers ( token ) )
Associates a permission with a Resource .
23,974
def permission_update ( self , token , id , ** kwargs ) : return self . _realm . client . put ( '{}/{}' . format ( self . well_known [ 'policy_endpoint' ] , id ) , data = self . _dumps ( kwargs ) , headers = self . get_headers ( token ) )
To update an existing permission .
23,975
def permission_delete ( self , token , id ) : return self . _realm . client . delete ( '{}/{}' . format ( self . well_known [ 'policy_endpoint' ] , id ) , headers = self . get_headers ( token ) )
Removing a Permission .
23,976
def _decode_token ( cls , token ) : missing_padding = len ( token ) % 4 if missing_padding != 0 : token += '=' * ( 4 - missing_padding ) return json . loads ( base64 . b64decode ( token ) . decode ( 'utf-8' ) )
Permission information is encoded in an authorization token .
23,977
def get_permissions ( self , token , resource_scopes_tuples = None , submit_request = False , ticket = None ) : headers = { "Authorization" : "Bearer %s" % token , 'Content-type' : 'application/x-www-form-urlencoded' , } data = [ ( 'grant_type' , 'urn:ietf:params:oauth:grant-type:uma-ticket' ) , ( 'audience' , self . _...
Request permissions for user from keycloak server .
23,978
def eval_permission ( self , token , resource , scope , submit_request = False ) : return self . eval_permissions ( token = token , resource_scopes_tuples = [ ( resource , scope ) ] , submit_request = submit_request )
Evalutes if user has permission for scope on resource .
23,979
def eval_permissions ( self , token , resource_scopes_tuples = None , submit_request = False ) : permissions = self . get_permissions ( token = token , resource_scopes_tuples = resource_scopes_tuples , submit_request = submit_request ) res = [ ] for permission in permissions . get ( 'permissions' , [ ] ) : for scope in...
Evaluates if user has permission for all the resource scope combinations .
23,980
def logout ( self , refresh_token ) : return self . _realm . client . post ( self . get_url ( 'end_session_endpoint' ) , data = { 'refresh_token' : refresh_token , 'client_id' : self . _client_id , 'client_secret' : self . _client_secret } )
The logout endpoint logs out the authenticated user .
23,981
def userinfo ( self , token ) : url = self . well_known [ 'userinfo_endpoint' ] return self . _realm . client . get ( url , headers = { "Authorization" : "Bearer {}" . format ( token ) } )
The UserInfo Endpoint is an OAuth 2 . 0 Protected Resource that returns Claims about the authenticated End - User . To obtain the requested Claims about the End - User the Client makes a request to the UserInfo Endpoint using an Access Token obtained through OpenID Connect Authentication . These Claims are normally rep...
23,982
def authorization_url ( self , ** kwargs ) : payload = { 'response_type' : 'code' , 'client_id' : self . _client_id } for key in kwargs . keys ( ) : payload [ key ] = kwargs [ key ] payload = sorted ( payload . items ( ) , key = lambda val : val [ 0 ] ) params = urlencode ( payload ) url = self . get_url ( 'authorizati...
Get authorization URL to redirect the resource owner to .
23,983
def authorization_code ( self , code , redirect_uri ) : return self . _token_request ( grant_type = 'authorization_code' , code = code , redirect_uri = redirect_uri )
Retrieve access token by authorization_code grant .
23,984
def password_credentials ( self , username , password , ** kwargs ) : return self . _token_request ( grant_type = 'password' , username = username , password = password , ** kwargs )
Retrieve access token by password credentials grant .
23,985
def refresh_token ( self , refresh_token , ** kwargs ) : return self . _token_request ( grant_type = 'refresh_token' , refresh_token = refresh_token , ** kwargs )
Refresh an access token
23,986
def _token_request ( self , grant_type , ** kwargs ) : payload = { 'grant_type' : grant_type , 'client_id' : self . _client_id , 'client_secret' : self . _client_secret } payload . update ( ** kwargs ) return self . _realm . client . post ( self . get_url ( 'token_endpoint' ) , data = payload )
Do the actual call to the token end - point .
23,987
def create ( self , name , ** kwargs ) : payload = OrderedDict ( name = name ) for key in ROLE_KWARGS : if key in kwargs : payload [ to_camel_case ( key ) ] = kwargs [ key ] return self . _client . post ( url = self . _client . get_full_url ( self . get_path ( 'collection' , realm = self . _realm_name , id = self . _cl...
Create new role
23,988
def update ( self , name , ** kwargs ) : payload = OrderedDict ( name = name ) for key in ROLE_KWARGS : if key in kwargs : payload [ to_camel_case ( key ) ] = kwargs [ key ] return self . _client . put ( url = self . _client . get_full_url ( self . get_path ( 'single' , realm = self . _realm_name , id = self . _client_...
Update existing role .
23,989
def extract_rpm ( archive , compression , cmd , verbosity , interactive , outdir ) : cpio = util . find_program ( "cpio" ) if not cpio : raise util . PatoolError ( "cpio(1) is required for rpm2cpio extraction; please install it" ) path = util . shell_quote ( os . path . abspath ( archive ) ) cmdlist = [ util . shell_qu...
Extract a RPM archive .
23,990
def list_tar ( archive , compression , cmd , verbosity , interactive ) : try : with tarfile . open ( archive ) as tfile : tfile . list ( verbose = verbosity > 1 ) except Exception as err : msg = "error listing %s: %s" % ( archive , err ) raise util . PatoolError ( msg ) return None
List a TAR archive with the tarfile Python module .
23,991
def extract_tar ( archive , compression , cmd , verbosity , interactive , outdir ) : try : with tarfile . open ( archive ) as tfile : tfile . extractall ( path = outdir ) except Exception as err : msg = "error extracting %s: %s" % ( archive , err ) raise util . PatoolError ( msg ) return None
Extract a TAR archive with the tarfile Python module .
23,992
def create_tar ( archive , compression , cmd , verbosity , interactive , filenames ) : mode = get_tar_mode ( compression ) try : with tarfile . open ( archive , mode ) as tfile : for filename in filenames : tfile . add ( filename ) except Exception as err : msg = "error creating %s: %s" % ( archive , err ) raise util ....
Create a TAR archive with the tarfile Python module .
23,993
def get_tar_mode ( compression ) : if compression == 'gzip' : return 'w:gz' if compression == 'bzip2' : return 'w:bz2' if compression == 'lzma' and py_lzma : return 'w:xz' if compression : msg = 'pytarfile does not support %s for tar compression' raise util . PatoolError ( msg % compression ) return 'w'
Determine tarfile open mode according to the given compression .
23,994
def extract_arj ( archive , compression , cmd , verbosity , interactive , outdir ) : cmdlist = [ cmd , 'x' , '-r' ] if not interactive : cmdlist . append ( '-y' ) cmdlist . extend ( [ archive , outdir ] ) return cmdlist
Extract an ARJ archive .
23,995
def list_arj ( archive , compression , cmd , verbosity , interactive ) : cmdlist = [ cmd ] if verbosity > 1 : cmdlist . append ( 'v' ) else : cmdlist . append ( 'l' ) if not interactive : cmdlist . append ( '-y' ) cmdlist . extend ( [ '-r' , archive ] ) return cmdlist
List an ARJ archive .
23,996
def create_arj ( archive , compression , cmd , verbosity , interactive , filenames ) : cmdlist = [ cmd , 'a' , '-r' ] if not interactive : cmdlist . append ( '-y' ) cmdlist . append ( archive ) cmdlist . extend ( filenames ) return cmdlist
Create an ARJ archive .
23,997
def create_zpaq ( archive , compression , cmd , verbosity , interactive , filenames ) : cmdlist = [ cmd , 'a' , archive ] cmdlist . extend ( filenames ) cmdlist . extend ( [ '-method' , '4' ] ) return cmdlist
Create a ZPAQ archive .
23,998
def extract_alzip ( archive , compression , cmd , verbosity , interactive , outdir ) : return [ cmd , '-d' , outdir , archive ]
Extract a ALZIP archive .
23,999
def extract_tar ( archive , compression , cmd , verbosity , interactive , outdir ) : cmdlist = [ cmd , '--extract' ] add_tar_opts ( cmdlist , compression , verbosity ) cmdlist . extend ( [ "--file" , archive , '--directory' , outdir ] ) return cmdlist
Extract a TAR archive .