idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
42,900 | def should_retry_on ( self , exception_class , logger = None ) : for n in ( self . retry_on or [ ] ) : try : if issubclass ( exception_class , import_attribute ( n ) ) : return True except TaskImportError : if logger : logger . error ( 'should_retry_on could not import class' , exception_name = n ) return False | Whether this task should be retried when the given exception occurs . |
42,901 | def update_scheduled_time ( self , when ) : tiger = self . tiger ts = get_timestamp ( when ) assert ts pipeline = tiger . connection . pipeline ( ) key = tiger . _key ( SCHEDULED , self . queue ) tiger . scripts . zadd ( key , ts , self . id , mode = 'xx' , client = pipeline ) pipeline . zscore ( key , self . id ) _ , ... | Updates a scheduled task s date to the given date . If the task is not scheduled a TaskNotFound exception is raised . |
42,902 | def n_executions ( self ) : pipeline = self . tiger . connection . pipeline ( ) pipeline . exists ( self . tiger . _key ( 'task' , self . id ) ) pipeline . llen ( self . tiger . _key ( 'task' , self . id , 'executions' ) ) exists , n_executions = pipeline . execute ( ) if not exists : raise TaskNotFound ( 'Task {} not ... | Queries and returns the number of past task executions . |
42,903 | def set_input ( self , nr = 2 , qd = 1 , b = 0 ) : self . nr = nr self . qd = qd self . b = b | Set inputs after initialization |
42,904 | def generateNoise ( self ) : wfb = np . zeros ( self . nr * 2 ) wfb [ : self . nr ] = np . random . normal ( 0 , np . sqrt ( self . qd ) , self . nr ) mhb = - self . b / 2.0 hfb = np . zeros ( self . nr * 2 ) hfb = np . zeros ( self . nr * 2 ) hfb [ 0 ] = 1.0 indices = np . arange ( self . nr - 1 ) hfb [ 1 : self . nr ... | Generate noise time series based on input parameters |
42,905 | def adev ( self , tau0 , tau ) : prefactor = self . adev_from_qd ( tau0 = tau0 , tau = tau ) c = self . c_avar ( ) avar = pow ( prefactor , 2 ) * pow ( tau , c ) return np . sqrt ( avar ) | return predicted ADEV of noise - type at given tau |
42,906 | def mdev ( self , tau0 , tau ) : prefactor = self . mdev_from_qd ( tau0 = tau0 , tau = tau ) c = self . c_mvar ( ) mvar = pow ( prefactor , 2 ) * pow ( tau , c ) return np . sqrt ( mvar ) | return predicted MDEV of noise - type at given tau |
42,907 | def scipy_psd ( x , f_sample = 1.0 , nr_segments = 4 ) : f_axis , psd_of_x = scipy . signal . welch ( x , f_sample , nperseg = len ( x ) / nr_segments ) return f_axis , psd_of_x | PSD routine from scipy we can compare our own numpy result against this one |
42,908 | def iterpink ( depth = 20 ) : values = numpy . random . randn ( depth ) smooth = numpy . random . randn ( depth ) source = numpy . random . randn ( depth ) sumvals = values . sum ( ) i = 0 while True : yield sumvals + smooth [ i ] i += 1 if i == depth : i = 0 smooth = numpy . random . randn ( depth ) source = numpy . r... | Generate a sequence of samples of pink noise . |
42,909 | def plotline ( plt , alpha , taus , style , label = "" ) : y = [ pow ( tt , alpha ) for tt in taus ] plt . loglog ( taus , y , style , label = label ) | plot a line with the slope alpha |
42,910 | def b1_noise_id ( x , af , rate ) : ( taus , devs , errs , ns ) = at . adev ( x , taus = [ af * rate ] , data_type = "phase" , rate = rate ) oadev_x = devs [ 0 ] y = np . diff ( x ) y_cut = np . array ( y [ : len ( y ) - ( len ( y ) % af ) ] ) assert len ( y_cut ) % af == 0 y_shaped = y_cut . reshape ( ( int ( len ( y_... | B1 ratio for noise identification ratio of Standard Variace to AVAR |
42,911 | def plot ( self , atDataset , errorbars = False , grid = False ) : if errorbars : self . ax . errorbar ( atDataset . out [ "taus" ] , atDataset . out [ "stat" ] , yerr = atDataset . out [ "stat_err" ] , ) else : self . ax . plot ( atDataset . out [ "taus" ] , atDataset . out [ "stat" ] , ) self . ax . set_xlabel ( "Tau... | use matplotlib methods for plotting |
42,912 | def greenhall_table2 ( alpha , d ) : row_idx = int ( - alpha + 2 ) assert ( row_idx in [ 0 , 1 , 2 , 3 , 4 , 5 ] ) col_idx = int ( d - 1 ) table2 = [ [ ( 3.0 / 2.0 , 1.0 / 2.0 ) , ( 35.0 / 18.0 , 1.0 ) , ( 231.0 / 100.0 , 3.0 / 2.0 ) ] , [ ( 78.6 , 25.2 ) , ( 790.0 , 410.0 ) , ( 9950.0 , 6520.0 ) ] , [ ( 2.0 / 3.0 , 1.... | Table 2 from Greenhall 2004 |
42,913 | def greenhall_table1 ( alpha , d ) : row_idx = int ( - alpha + 2 ) col_idx = int ( d - 1 ) table1 = [ [ ( 2.0 / 3.0 , 1.0 / 3.0 ) , ( 7.0 / 9.0 , 1.0 / 2.0 ) , ( 22.0 / 25.0 , 2.0 / 3.0 ) ] , [ ( 0.840 , 0.345 ) , ( 0.997 , 0.616 ) , ( 1.141 , 0.843 ) ] , [ ( 1.079 , 0.368 ) , ( 1.033 , 0.607 ) , ( 1.184 , 0.848 ) ] , ... | Table 1 from Greenhall 2004 |
42,914 | def edf_mtotdev ( N , m , alpha ) : assert ( alpha in [ 2 , 1 , 0 , - 1 , - 2 ] ) NIST_SP1065_table8 = [ ( 1.90 , 2.1 ) , ( 1.20 , 1.40 ) , ( 1.10 , 1.2 ) , ( 0.85 , 0.50 ) , ( 0.75 , 0.31 ) ] ( b , c ) = NIST_SP1065_table8 [ abs ( alpha - 2 ) ] edf = b * ( float ( N ) / float ( m ) ) - c print ( "mtotdev b,c= " , ( b ... | Equivalent degrees of freedom for Modified Total Deviation NIST SP1065 page 41 Table 8 |
42,915 | def edf_simple ( N , m , alpha ) : N = float ( N ) m = float ( m ) if alpha in [ 2 , 1 , 0 , - 1 , - 2 ] : if alpha == + 2 : edf = ( N + 1 ) * ( N - 2 * m ) / ( 2 * ( N - m ) ) if alpha == 0 : edf = ( ( ( 3 * ( N - 1 ) / ( 2 * m ) ) - ( 2 * ( N - 2 ) / N ) ) * ( ( 4 * pow ( m , 2 ) ) / ( ( 4 * pow ( m , 2 ) ) + 5 ) ) )... | Equivalent degrees of freedom . Simple approximate formulae . |
42,916 | def example1 ( ) : N = 1000 f = 1 y = np . random . randn ( 1 , N ) [ 0 , : ] x = [ xx for xx in np . linspace ( 1 , len ( y ) , len ( y ) ) ] x_ax , y_ax , ( err_l , err_h ) , ns = allan . gradev ( y , data_type = 'phase' , rate = f , taus = x ) plt . errorbar ( x_ax , y_ax , yerr = [ err_l , err_h ] , label = 'GRADEV... | Compute the GRADEV of a white phase noise . Compares two different scenarios . 1 ) The original data and 2 ) ADEV estimate with gap robust ADEV . |
42,917 | def example2 ( ) : N = 1000 f = 1 s = 1 + 5 / N * np . arange ( 0 , N ) y = s * np . random . randn ( 1 , N ) [ 0 , : ] x = [ xx for xx in np . linspace ( 1 , len ( y ) , len ( y ) ) ] x_ax , y_ax , ( err_l , err_h ) , ns = allan . gradev ( y , data_type = 'phase' , rate = f , taus = x ) plt . loglog ( x_ax , y_ax , 'b... | Compute the GRADEV of a nonstationary white phase noise . |
42,918 | def tdev ( data , rate = 1.0 , data_type = "phase" , taus = None ) : phase = input_to_phase ( data , rate , data_type ) ( taus , md , mde , ns ) = mdev ( phase , rate = rate , taus = taus ) td = taus * md / np . sqrt ( 3.0 ) tde = td / np . sqrt ( ns ) return taus , td , tde , ns | Time deviation . Based on modified Allan variance . |
42,919 | def mdev ( data , rate = 1.0 , data_type = "phase" , taus = None ) : phase = input_to_phase ( data , rate , data_type ) ( phase , ms , taus_used ) = tau_generator ( phase , rate , taus = taus ) data , taus = np . array ( phase ) , np . array ( taus ) md = np . zeros_like ( ms ) mderr = np . zeros_like ( ms ) ns = np . ... | Modified Allan deviation . Used to distinguish between White and Flicker Phase Modulation . |
42,920 | def adev ( data , rate = 1.0 , data_type = "phase" , taus = None ) : phase = input_to_phase ( data , rate , data_type ) ( phase , m , taus_used ) = tau_generator ( phase , rate , taus ) ad = np . zeros_like ( taus_used ) ade = np . zeros_like ( taus_used ) adn = np . zeros_like ( taus_used ) for idx , mj in enumerate (... | Allan deviation . Classic - use only if required - relatively poor confidence . |
42,921 | def ohdev ( data , rate = 1.0 , data_type = "phase" , taus = None ) : phase = input_to_phase ( data , rate , data_type ) ( phase , m , taus_used ) = tau_generator ( phase , rate , taus ) hdevs = np . zeros_like ( taus_used ) hdeverrs = np . zeros_like ( taus_used ) ns = np . zeros_like ( taus_used ) for idx , mj in enu... | Overlapping Hadamard deviation . Better confidence than normal Hadamard . |
42,922 | def calc_hdev_phase ( phase , rate , mj , stride ) : tau0 = 1.0 / float ( rate ) mj = int ( mj ) stride = int ( stride ) d3 = phase [ 3 * mj : : stride ] d2 = phase [ 2 * mj : : stride ] d1 = phase [ 1 * mj : : stride ] d0 = phase [ : : stride ] n = min ( len ( d0 ) , len ( d1 ) , len ( d2 ) , len ( d3 ) ) v_arr = d3 [... | main calculation fungtion for HDEV and OHDEV |
42,923 | def totdev ( data , rate = 1.0 , data_type = "phase" , taus = None ) : phase = input_to_phase ( data , rate , data_type ) ( phase , m , taus_used ) = tau_generator ( phase , rate , taus ) N = len ( phase ) x1 = 2.0 * phase [ 0 ] * np . ones ( ( N - 2 , ) ) x1 = x1 - phase [ 1 : - 1 ] x1 = x1 [ : : - 1 ] x2 = 2.0 * phas... | Total deviation . Better confidence at long averages for Allan . |
42,924 | def mtotdev ( data , rate = 1.0 , data_type = "phase" , taus = None ) : phase = input_to_phase ( data , rate , data_type ) ( phase , ms , taus_used ) = tau_generator ( phase , rate , taus , maximum_m = float ( len ( phase ) ) / 3.0 ) devs = np . zeros_like ( taus_used ) deverrs = np . zeros_like ( taus_used ) ns = np .... | PRELIMINARY - REQUIRES FURTHER TESTING . Modified Total deviation . Better confidence at long averages for modified Allan |
42,925 | def htotdev ( data , rate = 1.0 , data_type = "phase" , taus = None ) : if data_type == "phase" : phase = data freq = phase2frequency ( phase , rate ) elif data_type == "freq" : phase = frequency2phase ( data , rate ) freq = data else : raise Exception ( "unknown data_type: " + data_type ) rate = float ( rate ) ( freq ... | PRELIMINARY - REQUIRES FURTHER TESTING . Hadamard Total deviation . Better confidence at long averages for Hadamard deviation |
42,926 | def theo1 ( data , rate = 1.0 , data_type = "phase" , taus = None ) : phase = input_to_phase ( data , rate , data_type ) tau0 = 1.0 / rate ( phase , ms , taus_used ) = tau_generator ( phase , rate , taus , even = True ) devs = np . zeros_like ( taus_used ) deverrs = np . zeros_like ( taus_used ) ns = np . zeros_like ( ... | PRELIMINARY - REQUIRES FURTHER TESTING . Theo1 is a two - sample variance with improved confidence and extended averaging factor range . |
42,927 | def tierms ( data , rate = 1.0 , data_type = "phase" , taus = None ) : phase = input_to_phase ( data , rate , data_type ) ( data , m , taus_used ) = tau_generator ( phase , rate , taus ) count = len ( phase ) devs = np . zeros_like ( taus_used ) deverrs = np . zeros_like ( taus_used ) ns = np . zeros_like ( taus_used )... | Time Interval Error RMS . |
42,928 | def mtie ( data , rate = 1.0 , data_type = "phase" , taus = None ) : phase = input_to_phase ( data , rate , data_type ) ( phase , m , taus_used ) = tau_generator ( phase , rate , taus ) devs = np . zeros_like ( taus_used ) deverrs = np . zeros_like ( taus_used ) ns = np . zeros_like ( taus_used ) for idx , mj in enumer... | Maximum Time Interval Error . |
42,929 | def mtie_phase_fast ( phase , rate = 1.0 , data_type = "phase" , taus = None ) : rate = float ( rate ) phase = np . asarray ( phase ) k_max = int ( np . floor ( np . log2 ( len ( phase ) ) ) ) phase = phase [ 0 : pow ( 2 , k_max ) ] assert len ( phase ) == pow ( 2 , k_max ) taus = [ pow ( 2 , k ) for k in range ( k_max... | fast binary decomposition algorithm for MTIE |
42,930 | def gradev ( data , rate = 1.0 , data_type = "phase" , taus = None , ci = 0.9 , noisetype = 'wp' ) : if ( data_type == "freq" ) : print ( "Warning : phase data is preferred as input to gradev()" ) phase = input_to_phase ( data , rate , data_type ) ( data , m , taus_used ) = tau_generator ( phase , rate , taus ) ad = np... | gap resistant overlapping Allan deviation |
42,931 | def input_to_phase ( data , rate , data_type ) : if data_type == "phase" : return data elif data_type == "freq" : return frequency2phase ( data , rate ) else : raise Exception ( "unknown data_type: " + data_type ) | Take either phase or frequency as input and return phase |
42,932 | def trim_data ( x ) : first = 0 while np . isnan ( x [ first ] ) : first += 1 last = len ( x ) while np . isnan ( x [ last - 1 ] ) : last -= 1 return x [ first : last ] | Trim leading and trailing NaNs from dataset This is done by browsing the array from each end and store the index of the first non - NaN in each case the return the appropriate slice of the array |
42,933 | def three_cornered_hat_phase ( phasedata_ab , phasedata_bc , phasedata_ca , rate , taus , function ) : ( tau_ab , dev_ab , err_ab , ns_ab ) = function ( phasedata_ab , data_type = 'phase' , rate = rate , taus = taus ) ( tau_bc , dev_bc , err_bc , ns_bc ) = function ( phasedata_bc , data_type = 'phase' , rate = rate , t... | Three Cornered Hat Method |
42,934 | def frequency2phase ( freqdata , rate ) : dt = 1.0 / float ( rate ) freqdata = trim_data ( freqdata ) phasedata = np . cumsum ( freqdata ) * dt phasedata = np . insert ( phasedata , 0 , 0 ) return phasedata | integrate fractional frequency data and output phase data |
42,935 | def phase2radians ( phasedata , v0 ) : fi = [ 2 * np . pi * v0 * xx for xx in phasedata ] return fi | Convert phase in seconds to phase in radians |
42,936 | def frequency2fractional ( frequency , mean_frequency = - 1 ) : if mean_frequency == - 1 : mu = np . mean ( frequency ) else : mu = mean_frequency y = [ ( x - mu ) / mu for x in frequency ] return y | Convert frequency in Hz to fractional frequency |
42,937 | def set_input ( self , data , rate = 1.0 , data_type = "phase" , taus = None ) : self . inp [ "data" ] = data self . inp [ "rate" ] = rate self . inp [ "data_type" ] = data_type self . inp [ "taus" ] = taus | Optionnal method if you chose not to set inputs on init |
42,938 | def compute ( self , function ) : try : func = getattr ( allantools , function ) except AttributeError : raise AttributeError ( "function must be defined in allantools" ) whitelisted = [ "theo1" , "mtie" , "tierms" ] if function [ - 3 : ] != "dev" and function not in whitelisted : raise RuntimeError ( "function must be... | Evaluate the passed function with the supplied data . |
42,939 | def many_psds ( k = 2 , fs = 1.0 , b0 = 1.0 , N = 1024 ) : psd = [ ] for j in range ( k ) : print j x = noise . white ( N = 2 * 4096 , b0 = b0 , fs = fs ) f , tmp = noise . numpy_psd ( x , fs ) if j == 0 : psd = tmp else : psd = psd + tmp return f , psd / k | compute average of many PSDs |
42,940 | def list_my ( self ) : org_list = self . call_contract_command ( "Registry" , "listOrganizations" , [ ] ) rez_owner = [ ] rez_member = [ ] for idx , org_id in enumerate ( org_list ) : ( found , org_id , org_name , owner , members , serviceNames , repositoryNames ) = self . call_contract_command ( "Registry" , "getOrgan... | Find organization that has the current identity as the owner or as the member |
42,941 | def add_group ( self , group_name , payment_address ) : if ( self . is_group_name_exists ( group_name ) ) : raise Exception ( "the group \"%s\" is already present" % str ( group_name ) ) group_id_base64 = base64 . b64encode ( secrets . token_bytes ( 32 ) ) self . m [ "groups" ] += [ { "group_name" : group_name , "group... | Return new group_id in base64 |
42,942 | def is_group_name_exists ( self , group_name ) : groups = self . m [ "groups" ] for g in groups : if ( g [ "group_name" ] == group_name ) : return True return False | check if group with given name is already exists |
42,943 | def get_group_name_nonetrick ( self , group_name = None ) : groups = self . m [ "groups" ] if ( len ( groups ) == 0 ) : raise Exception ( "Cannot find any groups in metadata" ) if ( not group_name ) : if ( len ( groups ) > 1 ) : raise Exception ( "We have more than one payment group in metadata, so group_name should be... | In all getter function in case of single payment group group_name can be None |
42,944 | def get_from_ipfs_and_checkhash ( ipfs_client , ipfs_hash_base58 , validate = True ) : if validate : from snet_cli . resources . proto . unixfs_pb2 import Data from snet_cli . resources . proto . merckledag_pb2 import MerkleNode block_data = ipfs_client . block_get ( ipfs_hash_base58 ) mn = MerkleNode ( ) mn . ParseFro... | Get file from ipfs We must check the hash becasue we cannot believe that ipfs_client wasn t been compromise |
42,945 | def hash_to_bytesuri ( s ) : s = "ipfs://" + s return s . encode ( "ascii" ) . ljust ( 32 * ( len ( s ) // 32 + 1 ) , b"\0" ) | Convert in and from bytes uri format used in Registry contract |
42,946 | def _get_stub_and_request_classes ( self , service_name ) : codegen_dir = Path . home ( ) . joinpath ( ".snet" , "mpe_client" , "control_service" ) proto_dir = Path ( __file__ ) . absolute ( ) . parent . joinpath ( "resources" , "proto" ) if ( not codegen_dir . joinpath ( "control_service_pb2.py" ) . is_file ( ) ) : co... | import protobuf and return stub and request class |
42,947 | def _start_claim_channels ( self , grpc_channel , channels_ids ) : unclaimed_payments = self . _call_GetListUnclaimed ( grpc_channel ) unclaimed_payments_dict = { p [ "channel_id" ] : p for p in unclaimed_payments } to_claim = [ ] for channel_id in channels_ids : if ( channel_id not in unclaimed_payments_dict or unclai... | Safely run StartClaim for given channels |
42,948 | def _claim_in_progress_and_claim_channels ( self , grpc_channel , channels ) : payments = self . _call_GetListInProgress ( grpc_channel ) if ( len ( payments ) > 0 ) : self . _printout ( "There are %i payments in 'progress' (they haven't been claimed in blockchain). We will claim them." % len ( payments ) ) self . _blo... | Claim all pending payments in progress and after we claim given channels |
42,949 | def create_default_config ( self ) : self . _config_file . parent . mkdir ( mode = 0o700 , exist_ok = True ) self [ "network.kovan" ] = { "default_eth_rpc_endpoint" : "https://kovan.infura.io" , "default_gas_price" : "medium" } self [ "network.mainnet" ] = { "default_eth_rpc_endpoint" : "https://mainnet.infura.io" , "d... | Create default configuration if config file does not exist |
42,950 | def switch_to_json_payload_encoding ( call_fn , response_class ) : def json_serializer ( * args , ** kwargs ) : return bytes ( json_format . MessageToJson ( args [ 0 ] , True , preserving_proto_field_name = True ) , "utf-8" ) def json_deserializer ( * args , ** kwargs ) : resp = response_class ( ) json_format . Parse (... | Switch payload encoding to JSON for GRPC call |
42,951 | def print_agi_and_mpe_balances ( self ) : if ( self . args . account ) : account = self . args . account else : account = self . ident . address eth_wei = self . w3 . eth . getBalance ( account ) agi_cogs = self . call_contract_command ( "SingularityNetToken" , "balanceOf" , [ account ] ) mpe_cogs = self . call_contrac... | Print balance of ETH AGI and MPE wallet |
42,952 | def publish_proto_in_ipfs ( self ) : ipfs_hash_base58 = utils_ipfs . publish_proto_in_ipfs ( self . _get_ipfs_client ( ) , self . args . protodir ) self . _printout ( ipfs_hash_base58 ) | Publish proto files in ipfs and print hash |
42,953 | def publish_proto_metadata_update ( self ) : metadata = load_mpe_service_metadata ( self . args . metadata_file ) ipfs_hash_base58 = utils_ipfs . publish_proto_in_ipfs ( self . _get_ipfs_client ( ) , self . args . protodir ) metadata . set_simple_field ( "model_ipfs_hash" , ipfs_hash_base58 ) metadata . save_pretty ( s... | Publish protobuf model in ipfs and update existing metadata file |
42,954 | def _get_persistent_mpe_dir ( self ) : mpe_address = self . get_mpe_address ( ) . lower ( ) registry_address = self . get_registry_address ( ) . lower ( ) return Path . home ( ) . joinpath ( ".snet" , "mpe_client" , "%s_%s" % ( mpe_address , registry_address ) ) | get persistent storage for mpe |
42,955 | def _check_mpe_address_metadata ( self , metadata ) : mpe_address = self . get_mpe_address ( ) if ( str ( mpe_address ) . lower ( ) != str ( metadata [ "mpe_address" ] ) . lower ( ) ) : raise Exception ( "MultiPartyEscrow contract address from metadata %s do not correspond to current MultiPartyEscrow address %s" % ( me... | we make sure that MultiPartyEscrow address from metadata is correct |
42,956 | def _init_or_update_registered_service_if_needed ( self ) : if ( self . is_service_initialized ( ) ) : old_reg = self . _read_service_info ( self . args . org_id , self . args . service_id ) if ( "metadataURI" not in old_reg ) : return service_registration = self . _get_service_registration ( ) if ( not self . is_metad... | similar to _init_or_update_service_if_needed but we get service_registraion from registry so we can update only registered services |
42,957 | def _smart_get_initialized_channel_for_service ( self , metadata , filter_by , is_try_initailize = True ) : channels = self . _get_initialized_channels_for_service ( self . args . org_id , self . args . service_id ) group_id = metadata . get_group_id ( self . args . group_name ) channels = [ c for c in channels if c [ ... | - filter_by can be sender or signer |
42,958 | def _get_all_filtered_channels ( self , topics_without_signature ) : mpe_address = self . get_mpe_address ( ) event_signature = self . ident . w3 . sha3 ( text = "ChannelOpen(uint256,uint256,address,address,address,bytes32,uint256,uint256)" ) . hex ( ) topics = [ event_signature ] + topics_without_signature logs = self... | get all filtered chanels from blockchain logs |
42,959 | def list_repo ( self ) : req = proto . ListRepoRequest ( ) res = self . stub . ListRepo ( req , metadata = self . metadata ) if hasattr ( res , 'repo_info' ) : return res . repo_info return [ ] | Returns info about all Repos . |
42,960 | def delete_repo ( self , repo_name = None , force = False , all = False ) : if not all : if repo_name : req = proto . DeleteRepoRequest ( repo = proto . Repo ( name = repo_name ) , force = force ) self . stub . DeleteRepo ( req , metadata = self . metadata ) else : raise ValueError ( "Either a repo_name or all=True nee... | Deletes a repo and reclaims the storage space it was using . |
42,961 | def start_commit ( self , repo_name , branch = None , parent = None , description = None ) : req = proto . StartCommitRequest ( parent = proto . Commit ( repo = proto . Repo ( name = repo_name ) , id = parent ) , branch = branch , description = description ) res = self . stub . StartCommit ( req , metadata = self . met... | Begins the process of committing data to a Repo . Once started you can write to the Commit with PutFile and when all the data has been written you must finish the Commit with FinishCommit . NOTE data is not persisted until FinishCommit is called . A Commit object is returned . |
42,962 | def finish_commit ( self , commit ) : req = proto . FinishCommitRequest ( commit = commit_from ( commit ) ) res = self . stub . FinishCommit ( req , metadata = self . metadata ) return res | Ends the process of committing data to a Repo and persists the Commit . Once a Commit is finished the data becomes immutable and future attempts to write to it with PutFile will error . |
42,963 | def commit ( self , repo_name , branch = None , parent = None , description = None ) : commit = self . start_commit ( repo_name , branch , parent , description ) try : yield commit except Exception as e : print ( "An exception occurred during an open commit. " "Trying to finish it (Currently a commit can't be cancelled... | A context manager for doing stuff inside a commit . |
42,964 | def inspect_commit ( self , commit ) : req = proto . InspectCommitRequest ( commit = commit_from ( commit ) ) return self . stub . InspectCommit ( req , metadata = self . metadata ) | Returns info about a specific Commit . |
42,965 | def list_commit ( self , repo_name , to_commit = None , from_commit = None , number = 0 ) : req = proto . ListCommitRequest ( repo = proto . Repo ( name = repo_name ) , number = number ) if to_commit is not None : req . to . CopyFrom ( commit_from ( to_commit ) ) if from_commit is not None : getattr ( req , 'from' ) . ... | Gets a list of CommitInfo objects . |
42,966 | def delete_commit ( self , commit ) : req = proto . DeleteCommitRequest ( commit = commit_from ( commit ) ) self . stub . DeleteCommit ( req , metadata = self . metadata ) | Deletes a commit . |
42,967 | def flush_commit ( self , commits , repos = tuple ( ) ) : req = proto . FlushCommitRequest ( commit = [ commit_from ( c ) for c in commits ] , to_repo = [ proto . Repo ( name = r ) for r in repos ] ) res = self . stub . FlushCommit ( req , metadata = self . metadata ) return res | Blocks until all of the commits which have a set of commits as provenance have finished . For commits to be considered they must have all of the specified commits as provenance . This in effect waits for all of the jobs that are triggered by a set of commits to complete . It returns an error if any of the commits it s ... |
42,968 | def subscribe_commit ( self , repo_name , branch , from_commit_id = None ) : repo = proto . Repo ( name = repo_name ) req = proto . SubscribeCommitRequest ( repo = repo , branch = branch ) if from_commit_id is not None : getattr ( req , 'from' ) . CopyFrom ( proto . Commit ( repo = repo , id = from_commit_id ) ) res = ... | SubscribeCommit is like ListCommit but it keeps listening for commits as they come in . This returns an iterator Commit objects . |
42,969 | def list_branch ( self , repo_name ) : req = proto . ListBranchRequest ( repo = proto . Repo ( name = repo_name ) ) res = self . stub . ListBranch ( req , metadata = self . metadata ) if hasattr ( res , 'branch_info' ) : return res . branch_info return [ ] | Lists the active Branch objects on a Repo . |
42,970 | def set_branch ( self , commit , branch_name ) : res = proto . SetBranchRequest ( commit = commit_from ( commit ) , branch = branch_name ) self . stub . SetBranch ( res , metadata = self . metadata ) | Sets a commit and its ancestors as a branch . |
42,971 | def delete_branch ( self , repo_name , branch_name ) : res = proto . DeleteBranchRequest ( repo = Repo ( name = repo_name ) , branch = branch_name ) self . stub . DeleteBranch ( res , metadata = self . metadata ) | Deletes a branch but leaves the commits themselves intact . In other words those commits can still be accessed via commit IDs and other branches they happen to be on . |
42,972 | def put_file_url ( self , commit , path , url , recursive = False ) : req = iter ( [ proto . PutFileRequest ( file = proto . File ( commit = commit_from ( commit ) , path = path ) , url = url , recursive = recursive ) ] ) self . stub . PutFile ( req , metadata = self . metadata ) | Puts a file using the content found at a URL . The URL is sent to the server which performs the request . |
42,973 | def get_file ( self , commit , path , offset_bytes = 0 , size_bytes = 0 , extract_value = True ) : req = proto . GetFileRequest ( file = proto . File ( commit = commit_from ( commit ) , path = path ) , offset_bytes = offset_bytes , size_bytes = size_bytes ) res = self . stub . GetFile ( req , metadata = self . metadata... | Returns an iterator of the contents contents of a file at a specific Commit . |
42,974 | def get_files ( self , commit , paths , recursive = False ) : filtered_file_infos = [ ] for path in paths : fi = self . inspect_file ( commit , path ) if fi . file_type == proto . FILE : filtered_file_infos . append ( fi ) else : filtered_file_infos += self . list_file ( commit , path , recursive = recursive ) filtered... | Returns the contents of a list of files at a specific Commit as a dictionary of file paths to data . |
42,975 | def inspect_file ( self , commit , path ) : req = proto . InspectFileRequest ( file = proto . File ( commit = commit_from ( commit ) , path = path ) ) res = self . stub . InspectFile ( req , metadata = self . metadata ) return res | Returns info about a specific file . |
42,976 | def list_file ( self , commit , path , recursive = False ) : req = proto . ListFileRequest ( file = proto . File ( commit = commit_from ( commit ) , path = path ) ) res = self . stub . ListFile ( req , metadata = self . metadata ) file_infos = res . file_info if recursive : dirs = [ f for f in file_infos if f . file_ty... | Lists the files in a directory . |
42,977 | def delete_file ( self , commit , path ) : req = proto . DeleteFileRequest ( file = proto . File ( commit = commit_from ( commit ) , path = path ) ) self . stub . DeleteFile ( req , metadata = self . metadata ) | Deletes a file from a Commit . DeleteFile leaves a tombstone in the Commit assuming the file isn t written to later attempting to get the file from the finished commit will result in not found error . The file will of course remain intact in the Commit s parent . |
42,978 | def handle_authn_request ( self , context , binding_in ) : return self . _handle_authn_request ( context , binding_in , self . idp ) | This method is bound to the starting endpoint of the authentication . |
42,979 | def _create_state_data ( self , context , resp_args , relay_state ) : if "name_id_policy" in resp_args and resp_args [ "name_id_policy" ] is not None : resp_args [ "name_id_policy" ] = resp_args [ "name_id_policy" ] . to_string ( ) . decode ( "utf-8" ) return { "resp_args" : resp_args , "relay_state" : relay_state } | Returns a dict containing the state needed in the response flow . |
42,980 | def _handle_authn_request ( self , context , binding_in , idp ) : req_info = idp . parse_authn_request ( context . request [ "SAMLRequest" ] , binding_in ) authn_req = req_info . message satosa_logging ( logger , logging . DEBUG , "%s" % authn_req , context . state ) try : resp_args = idp . response_args ( authn_req ) ... | See doc for handle_authn_request method . |
42,981 | def _get_approved_attributes ( self , idp , idp_policy , sp_entity_id , state ) : name_format = idp_policy . get_name_form ( sp_entity_id ) attrconvs = idp . config . attribute_converters idp_policy . acs = attrconvs attribute_filter = [ ] for aconv in attrconvs : if aconv . name_format == name_format : all_attributes ... | Returns a list of approved attributes |
42,982 | def _build_idp_config_endpoints ( self , config , providers ) : idp_endpoints = [ ] for endp_category in self . endpoints : for func , endpoint in self . endpoints [ endp_category ] . items ( ) : for provider in providers : _endpoint = "{base}/{provider}/{endpoint}" . format ( base = self . base_url , provider = provid... | Builds the final frontend module config |
42,983 | def _load_endpoints_to_config ( self , provider , target_entity_id , config = None ) : idp_conf = copy . deepcopy ( config or self . idp_config ) for service , endpoint in self . endpoints . items ( ) : idp_endpoints = [ ] for binding , path in endpoint . items ( ) : url = "{base}/{provider}/{target_id}/{path}" . forma... | Loads approved endpoints to the config . |
42,984 | def _load_idp_dynamic_entity_id ( self , state ) : idp_config_file = copy . deepcopy ( self . idp_config ) idp_config_file [ "entityid" ] = "{}/{}" . format ( self . idp_config [ "entityid" ] , state [ self . name ] [ "target_entity_id" ] ) idp_config = IdPConfig ( ) . load ( idp_config_file , metadata_construction = F... | Loads an idp server with the entity id saved in state |
42,985 | def _get_co_name_from_path ( self , context ) : url_encoded_co_name = context . path . split ( "/" ) [ 1 ] co_name = unquote_plus ( url_encoded_co_name ) return co_name | The CO name is URL encoded and obtained from the request path for a request coming into one of the standard binding endpoints . For example the HTTP - Redirect binding request path will have the format |
42,986 | def _get_co_name ( self , context ) : try : co_name = context . state [ self . name ] [ self . KEY_CO_NAME ] logger . debug ( "Found CO {} from state" . format ( co_name ) ) except KeyError : co_name = self . _get_co_name_from_path ( context ) logger . debug ( "Found CO {} from request path" . format ( co_name ) ) retu... | Obtain the CO name previously saved in the request state or if not set use the request path obtained from the current context to determine the target CO . |
42,987 | def _add_endpoints_to_config ( self , config , co_name , backend_name ) : for service , endpoint in self . endpoints . items ( ) : idp_endpoints = [ ] for binding , path in endpoint . items ( ) : url = "{base}/{backend}/{co_name}/{path}" . format ( base = self . base_url , backend = backend_name , co_name = quote_plus ... | Use the request path from the context to determine the target backend then construct mappings from bindings to endpoints for the virtual IdP for the CO . |
42,988 | def _add_entity_id ( self , config , co_name ) : base_entity_id = config [ 'entityid' ] co_entity_id = "{}/{}" . format ( base_entity_id , quote_plus ( co_name ) ) config [ 'entityid' ] = co_entity_id return config | Use the CO name to construct the entity ID for the virtual IdP for the CO . |
42,989 | def _overlay_for_saml_metadata ( self , config , co_name ) : for co in self . config [ self . KEY_CO ] : if co [ self . KEY_ENCODEABLE_NAME ] == co_name : break key = self . KEY_ORGANIZATION if key in co : if key not in config : config [ key ] = { } for org_key in self . KEY_ORGANIZATION_KEYS : if org_key in co [ key ]... | Overlay configuration details like organization and contact person from the front end configuration onto the IdP configuration to support SAML metadata generation . |
42,990 | def _co_names_from_config ( self ) : co_names = [ co [ self . KEY_ENCODEABLE_NAME ] for co in self . config [ self . KEY_CO ] ] return co_names | Parse the configuration for the names of the COs for which to construct virtual IdPs . |
42,991 | def _create_co_virtual_idp ( self , context ) : co_name = self . _get_co_name ( context ) context . decorate ( self . KEY_CO_NAME , co_name ) co_names = self . _co_names_from_config ( ) if co_name not in co_names : msg = "CO {} not in configured list of COs {}" . format ( co_name , co_names ) satosa_logging ( logger , ... | Create a virtual IdP to represent the CO . |
42,992 | def _authn_response ( self , context ) : state_data = context . state [ self . name ] aresp = self . consumer . parse_response ( AuthorizationResponse , info = json . dumps ( context . request ) ) self . _verify_state ( aresp , state_data , context . state ) rargs = { "code" : aresp [ "code" ] , "redirect_uri" : self .... | Handles the authentication response from the AS . |
42,993 | def hash_data ( salt , value , hash_alg = None ) : hash_alg = hash_alg or 'sha512' hasher = hashlib . new ( hash_alg ) hasher . update ( value . encode ( 'utf-8' ) ) hasher . update ( salt . encode ( 'utf-8' ) ) value_hashed = hasher . hexdigest ( ) return value_hashed | Hashes a value together with a salt with the given hash algorithm . |
42,994 | def _construct_filter_value ( self , candidate , data ) : context = self . context attributes = data . attributes satosa_logging ( logger , logging . DEBUG , "Input attributes {}" . format ( attributes ) , context . state ) values = [ ] for identifier_name in candidate [ 'attribute_names' ] : v = attributes . get ( ide... | Construct and return a LDAP directory search filter value from the candidate identifier . |
42,995 | def _filter_config ( self , config , fields = None ) : filter_fields_default = [ 'bind_password' , 'connection' ] filter_fields = fields or filter_fields_default return dict ( map ( lambda key : ( key , '<hidden>' if key in filter_fields else config [ key ] ) , config . keys ( ) ) ) | Filter sensitive details like passwords from a configuration dictionary . |
42,996 | def _ldap_connection_factory ( self , config ) : ldap_url = config [ 'ldap_url' ] bind_dn = config [ 'bind_dn' ] bind_password = config [ 'bind_password' ] if not ldap_url : raise LdapAttributeStoreError ( "ldap_url is not configured" ) if not bind_dn : raise LdapAttributeStoreError ( "bind_dn is not configured" ) if n... | Use the input configuration to instantiate and return a ldap3 Connection object . |
42,997 | def _populate_attributes ( self , config , record , context , data ) : search_return_attributes = config [ 'search_return_attributes' ] for attr in search_return_attributes . keys ( ) : if attr in record [ "attributes" ] : if record [ "attributes" ] [ attr ] : data . attributes [ search_return_attributes [ attr ] ] = r... | Use a record found in LDAP to populate attributes . |
42,998 | def _populate_input_for_name_id ( self , config , record , context , data ) : user_id = "" user_id_from_attrs = config [ 'user_id_from_attrs' ] for attr in user_id_from_attrs : if attr in record [ "attributes" ] : value = record [ "attributes" ] [ attr ] if isinstance ( value , list ) : value . sort ( ) user_id += "" .... | Use a record found in LDAP to populate input for NameID generation . |
42,999 | def _verify_dict ( self , conf ) : if not conf : raise SATOSAConfigurationError ( "Missing configuration or unknown format" ) for key in SATOSAConfig . mandatory_dict_keys : if key not in conf : raise SATOSAConfigurationError ( "Missing key '%s' in config" % key ) for key in SATOSAConfig . sensitive_dict_keys : if key ... | Check that the configuration contains all necessary keys . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.