idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
228,600 | def get ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . download ( '/get' , args , * * kwargs ) | Downloads a file or directory of files from IPFS . | 44 | 12 |
228,601 | def cat ( self , multihash , offset = 0 , length = - 1 , * * kwargs ) : opts = { } if offset != 0 : opts [ 'offset' ] = offset if length != - 1 : opts [ 'length' ] = length args = ( multihash , ) return self . _client . request ( '/cat' , args , opts = opts , * * kwargs ) | r Retrieves the contents of a file identified by hash . | 93 | 13 |
228,602 | def ls ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . request ( '/ls' , args , decoder = 'json' , * * kwargs ) | Returns a list of objects linked to by the given hash . | 51 | 12 |
228,603 | def refs ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . request ( '/refs' , args , decoder = 'json' , * * kwargs ) | Returns a list of hashes of objects referenced by the given hash . | 53 | 13 |
228,604 | def block_stat ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . request ( '/block/stat' , args , decoder = 'json' , * * kwargs ) | Returns a dict with the size of the block with the given hash . | 55 | 14 |
228,605 | def block_get ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . request ( '/block/get' , args , * * kwargs ) | r Returns the raw contents of a block . | 48 | 9 |
228,606 | def bitswap_wantlist ( self , peer = None , * * kwargs ) : args = ( peer , ) return self . _client . request ( '/bitswap/wantlist' , args , decoder = 'json' , * * kwargs ) | Returns blocks currently on the bitswap wantlist . | 59 | 11 |
228,607 | def bitswap_unwant ( self , key , * * kwargs ) : args = ( key , ) return self . _client . request ( '/bitswap/unwant' , args , * * kwargs ) | Remove a given block from wantlist . | 50 | 8 |
228,608 | def object_data ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . request ( '/object/data' , args , * * kwargs ) | r Returns the raw bytes in an IPFS object . | 48 | 11 |
228,609 | def object_new ( self , template = None , * * kwargs ) : args = ( template , ) if template is not None else ( ) return self . _client . request ( '/object/new' , args , decoder = 'json' , * * kwargs ) | Creates a new object from an IPFS template . | 61 | 11 |
228,610 | def object_links ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . request ( '/object/links' , args , decoder = 'json' , * * kwargs ) | Returns the links pointed to by the specified object . | 55 | 10 |
228,611 | def object_get ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . request ( '/object/get' , args , decoder = 'json' , * * kwargs ) | Get and serialize the DAG node named by multihash . | 55 | 14 |
228,612 | def object_put ( self , file , * * kwargs ) : body , headers = multipart . stream_files ( file , self . chunk_size ) return self . _client . request ( '/object/put' , decoder = 'json' , data = body , headers = headers , * * kwargs ) | Stores input as a DAG object and returns its key . | 70 | 13 |
228,613 | def object_stat ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . request ( '/object/stat' , args , decoder = 'json' , * * kwargs ) | Get stats for the DAG node named by multihash . | 55 | 13 |
228,614 | def file_ls ( self , multihash , * * kwargs ) : args = ( multihash , ) return self . _client . request ( '/file/ls' , args , decoder = 'json' , * * kwargs ) | Lists directory contents for Unix filesystem objects . | 55 | 9 |
228,615 | def resolve ( self , name , recursive = False , * * kwargs ) : kwargs . setdefault ( "opts" , { "recursive" : recursive } ) args = ( name , ) return self . _client . request ( '/resolve' , args , decoder = 'json' , * * kwargs ) | Accepts an identifier and resolves it to the referenced item . | 73 | 12 |
228,616 | def key_gen ( self , key_name , type , size = 2048 , * * kwargs ) : opts = { "type" : type , "size" : size } kwargs . setdefault ( "opts" , opts ) args = ( key_name , ) return self . _client . request ( '/key/gen' , args , decoder = 'json' , * * kwargs ) | Adds a new public key that can be used for name_publish . | 92 | 15 |
228,617 | def key_rm ( self , key_name , * key_names , * * kwargs ) : args = ( key_name , ) + key_names return self . _client . request ( '/key/rm' , args , decoder = 'json' , * * kwargs ) | Remove a keypair | 64 | 4 |
228,618 | def key_rename ( self , key_name , new_key_name , * * kwargs ) : args = ( key_name , new_key_name ) return self . _client . request ( '/key/rename' , args , decoder = 'json' , * * kwargs ) | Rename a keypair | 68 | 5 |
228,619 | def name_publish ( self , ipfs_path , resolve = True , lifetime = "24h" , ttl = None , key = None , * * kwargs ) : opts = { "lifetime" : lifetime , "resolve" : resolve } if ttl : opts [ "ttl" ] = ttl if key : opts [ "key" ] = key kwargs . setdefault ( "opts" , opts ) args = ( ipfs_path , ) return self . _client . request ( '/name/publish' , args , decoder = 'json' , * * kwargs ) | Publishes an object to IPNS . | 139 | 8 |
228,620 | def name_resolve ( self , name = None , recursive = False , nocache = False , * * kwargs ) : kwargs . setdefault ( "opts" , { "recursive" : recursive , "nocache" : nocache } ) args = ( name , ) if name is not None else ( ) return self . _client . request ( '/name/resolve' , args , decoder = 'json' , * * kwargs ) | Gets the value currently published at an IPNS name . | 104 | 12 |
228,621 | def dns ( self , domain_name , recursive = False , * * kwargs ) : kwargs . setdefault ( "opts" , { "recursive" : recursive } ) args = ( domain_name , ) return self . _client . request ( '/dns' , args , decoder = 'json' , * * kwargs ) | Resolves DNS links to the referenced object . | 78 | 9 |
228,622 | def pin_add ( self , path , * paths , * * kwargs ) : #PY2: No support for kw-only parameters after glob parameters if "recursive" in kwargs : kwargs . setdefault ( "opts" , { "recursive" : kwargs . pop ( "recursive" ) } ) args = ( path , ) + paths return self . _client . request ( '/pin/add' , args , decoder = 'json' , * * kwargs ) | Pins objects to local storage . | 113 | 7 |
228,623 | def pin_rm ( self , path , * paths , * * kwargs ) : #PY2: No support for kw-only parameters after glob parameters if "recursive" in kwargs : kwargs . setdefault ( "opts" , { "recursive" : kwargs [ "recursive" ] } ) del kwargs [ "recursive" ] args = ( path , ) + paths return self . _client . request ( '/pin/rm' , args , decoder = 'json' , * * kwargs ) | Removes a pinned object from local storage . | 121 | 9 |
228,624 | def pin_ls ( self , type = "all" , * * kwargs ) : kwargs . setdefault ( "opts" , { "type" : type } ) return self . _client . request ( '/pin/ls' , decoder = 'json' , * * kwargs ) | Lists objects pinned to local storage . | 67 | 8 |
228,625 | def pin_update ( self , from_path , to_path , * * kwargs ) : #PY2: No support for kw-only parameters after glob parameters if "unpin" in kwargs : kwargs . setdefault ( "opts" , { "unpin" : kwargs [ "unpin" ] } ) del kwargs [ "unpin" ] args = ( from_path , to_path ) return self . _client . request ( '/pin/update' , args , decoder = 'json' , * * kwargs ) | Replaces one pin with another . | 127 | 7 |
228,626 | def pin_verify ( self , path , * paths , * * kwargs ) : #PY2: No support for kw-only parameters after glob parameters if "verbose" in kwargs : kwargs . setdefault ( "opts" , { "verbose" : kwargs [ "verbose" ] } ) del kwargs [ "verbose" ] args = ( path , ) + paths return self . _client . request ( '/pin/verify' , args , decoder = 'json' , stream = True , * * kwargs ) | Verify that recursive pins are complete . | 127 | 8 |
228,627 | def id ( self , peer = None , * * kwargs ) : args = ( peer , ) if peer is not None else ( ) return self . _client . request ( '/id' , args , decoder = 'json' , * * kwargs ) | Shows IPFS Node ID info . | 57 | 8 |
228,628 | def bootstrap_add ( self , peer , * peers , * * kwargs ) : args = ( peer , ) + peers return self . _client . request ( '/bootstrap/add' , args , decoder = 'json' , * * kwargs ) | Adds peers to the bootstrap list . | 58 | 8 |
228,629 | def swarm_filters_add ( self , address , * addresses , * * kwargs ) : args = ( address , ) + addresses return self . _client . request ( '/swarm/filters/add' , args , decoder = 'json' , * * kwargs ) | Adds a given multiaddr filter to the filter list . | 63 | 11 |
228,630 | def dht_query ( self , peer_id , * peer_ids , * * kwargs ) : args = ( peer_id , ) + peer_ids return self . _client . request ( '/dht/query' , args , decoder = 'json' , * * kwargs ) | Finds the closest Peer IDs to a given Peer ID by querying the DHT . | 66 | 18 |
228,631 | def dht_findprovs ( self , multihash , * multihashes , * * kwargs ) : args = ( multihash , ) + multihashes return self . _client . request ( '/dht/findprovs' , args , decoder = 'json' , * * kwargs ) | Finds peers in the DHT that can provide a specific value . | 70 | 14 |
228,632 | def dht_get ( self , key , * keys , * * kwargs ) : args = ( key , ) + keys res = self . _client . request ( '/dht/get' , args , decoder = 'json' , * * kwargs ) if isinstance ( res , dict ) and "Extra" in res : return res [ "Extra" ] else : for r in res : if "Extra" in r and len ( r [ "Extra" ] ) > 0 : return r [ "Extra" ] raise exceptions . Error ( "empty response from DHT" ) | Queries the DHT for its best value related to given key . | 127 | 14 |
228,633 | def ping ( self , peer , * peers , * * kwargs ) : #PY2: No support for kw-only parameters after glob parameters if "count" in kwargs : kwargs . setdefault ( "opts" , { "count" : kwargs [ "count" ] } ) del kwargs [ "count" ] args = ( peer , ) + peers return self . _client . request ( '/ping' , args , decoder = 'json' , * * kwargs ) | Provides round - trip latency information for the routing system . | 113 | 12 |
228,634 | def config ( self , key , value = None , * * kwargs ) : args = ( key , value ) return self . _client . request ( '/config' , args , decoder = 'json' , * * kwargs ) | Controls configuration variables . | 52 | 5 |
228,635 | def config_replace ( self , * args , * * kwargs ) : return self . _client . request ( '/config/replace' , args , decoder = 'json' , * * kwargs ) | Replaces the existing config with a user - defined config . | 46 | 12 |
228,636 | def log_level ( self , subsystem , level , * * kwargs ) : args = ( subsystem , level ) return self . _client . request ( '/log/level' , args , decoder = 'json' , * * kwargs ) | r Changes the logging output of a running daemon . | 54 | 10 |
228,637 | def log_tail ( self , * * kwargs ) : return self . _client . request ( '/log/tail' , decoder = 'json' , stream = True , * * kwargs ) | r Reads log outputs as they are written . | 45 | 10 |
228,638 | def files_cp ( self , source , dest , * * kwargs ) : args = ( source , dest ) return self . _client . request ( '/files/cp' , args , * * kwargs ) | Copies files within the MFS . | 47 | 8 |
228,639 | def files_ls ( self , path , * * kwargs ) : args = ( path , ) return self . _client . request ( '/files/ls' , args , decoder = 'json' , * * kwargs ) | Lists contents of a directory in the MFS . | 51 | 11 |
228,640 | def files_mkdir ( self , path , parents = False , * * kwargs ) : kwargs . setdefault ( "opts" , { "parents" : parents } ) args = ( path , ) return self . _client . request ( '/files/mkdir' , args , * * kwargs ) | Creates a directory within the MFS . | 70 | 9 |
228,641 | def files_rm ( self , path , recursive = False , * * kwargs ) : kwargs . setdefault ( "opts" , { "recursive" : recursive } ) args = ( path , ) return self . _client . request ( '/files/rm' , args , * * kwargs ) | Removes a file from the MFS . | 69 | 9 |
228,642 | def files_read ( self , path , offset = 0 , count = None , * * kwargs ) : opts = { "offset" : offset } if count is not None : opts [ "count" ] = count kwargs . setdefault ( "opts" , opts ) args = ( path , ) return self . _client . request ( '/files/read' , args , * * kwargs ) | Reads a file stored in the MFS . | 92 | 10 |
228,643 | def files_write ( self , path , file , offset = 0 , create = False , truncate = False , count = None , * * kwargs ) : opts = { "offset" : offset , "create" : create , "truncate" : truncate } if count is not None : opts [ "count" ] = count kwargs . setdefault ( "opts" , opts ) args = ( path , ) body , headers = multipart . stream_files ( file , self . chunk_size ) return self . _client . request ( '/files/write' , args , data = body , headers = headers , * * kwargs ) | Writes to a mutable file in the MFS . | 145 | 12 |
228,644 | def files_mv ( self , source , dest , * * kwargs ) : args = ( source , dest ) return self . _client . request ( '/files/mv' , args , * * kwargs ) | Moves files and directories within the MFS . | 49 | 10 |
228,645 | def add_bytes ( self , data , * * kwargs ) : body , headers = multipart . stream_bytes ( data , self . chunk_size ) return self . _client . request ( '/add' , decoder = 'json' , data = body , headers = headers , * * kwargs ) | Adds a set of bytes as a file to IPFS . | 68 | 12 |
228,646 | def add_str ( self , string , * * kwargs ) : body , headers = multipart . stream_text ( string , self . chunk_size ) return self . _client . request ( '/add' , decoder = 'json' , data = body , headers = headers , * * kwargs ) | Adds a Python string as a file to IPFS . | 68 | 11 |
228,647 | def add_json ( self , json_obj , * * kwargs ) : return self . add_bytes ( encoding . Json ( ) . encode ( json_obj ) , * * kwargs ) | Adds a json - serializable Python dict as a json file to IPFS . | 45 | 16 |
228,648 | def add_pyobj ( self , py_obj , * * kwargs ) : warnings . warn ( "Using `*_pyobj` on untrusted data is a security risk" , DeprecationWarning ) return self . add_bytes ( encoding . Pickle ( ) . encode ( py_obj ) , * * kwargs ) | Adds a picklable Python object as a file to IPFS . | 74 | 14 |
228,649 | def get_pyobj ( self , multihash , * * kwargs ) : warnings . warn ( "Using `*_pyobj` on untrusted data is a security risk" , DeprecationWarning ) return self . cat ( multihash , decoder = 'pickle' , * * kwargs ) | Loads a pickled Python object from IPFS . | 70 | 11 |
228,650 | def pubsub_peers ( self , topic = None , * * kwargs ) : args = ( topic , ) if topic is not None else ( ) return self . _client . request ( '/pubsub/peers' , args , decoder = 'json' , * * kwargs ) | List the peers we are pubsubbing with . | 65 | 10 |
228,651 | def pubsub_pub ( self , topic , payload , * * kwargs ) : args = ( topic , payload ) return self . _client . request ( '/pubsub/pub' , args , decoder = 'json' , * * kwargs ) | Publish a message to a given pubsub topic | 56 | 10 |
228,652 | def pubsub_sub ( self , topic , discover = False , * * kwargs ) : args = ( topic , discover ) return SubChannel ( self . _client . request ( '/pubsub/sub' , args , stream = True , decoder = 'json' ) ) | Subscribe to mesages on a given topic | 60 | 8 |
228,653 | def guess_mimetype ( filename ) : fn = os . path . basename ( filename ) return mimetypes . guess_type ( fn ) [ 0 ] or 'application/octet-stream' | Guesses the mimetype of a file based on the given filename . | 45 | 15 |
228,654 | def ls_dir ( dirname ) : ls = os . listdir ( dirname ) files = [ p for p in ls if os . path . isfile ( os . path . join ( dirname , p ) ) ] dirs = [ p for p in ls if os . path . isdir ( os . path . join ( dirname , p ) ) ] return files , dirs | Returns files and subdirectories within a given directory . | 83 | 11 |
228,655 | def clean_files ( files ) : if isinstance ( files , ( list , tuple ) ) : for f in files : yield clean_file ( f ) else : yield clean_file ( files ) | Generates tuples with a file - like object and a close indicator . | 42 | 15 |
228,656 | def merge ( directory , message , branch_label , rev_id , revisions ) : _merge ( directory , revisions , message , branch_label , rev_id ) | Merge two revisions together creating a new revision file | 36 | 10 |
228,657 | def downgrade ( directory , sql , tag , x_arg , revision ) : _downgrade ( directory , revision , sql , tag , x_arg ) | Revert to a previous version | 32 | 7 |
228,658 | def get_metadata ( bind ) : if bind == '' : bind = None m = MetaData ( ) for t in target_metadata . tables . values ( ) : if t . info . get ( 'bind_key' ) == bind : t . tometadata ( m ) return m | Return the metadata for a bind . | 60 | 7 |
228,659 | def init ( directory = None , multidb = False ) : if directory is None : directory = current_app . extensions [ 'migrate' ] . directory config = Config ( ) config . set_main_option ( 'script_location' , directory ) config . config_file_name = os . path . join ( directory , 'alembic.ini' ) config = current_app . extensions [ 'migrate' ] . migrate . call_configure_callbacks ( config ) if multidb : command . init ( config , directory , 'flask-multidb' ) else : command . init ( config , directory , 'flask' ) | Creates a new migration repository | 142 | 6 |
228,660 | def edit ( directory = None , revision = 'current' ) : if alembic_version >= ( 0 , 8 , 0 ) : config = current_app . extensions [ 'migrate' ] . migrate . get_config ( directory ) command . edit ( config , revision ) else : raise RuntimeError ( 'Alembic 0.8.0 or greater is required' ) | Edit current revision . | 80 | 4 |
228,661 | def merge ( directory = None , revisions = '' , message = None , branch_label = None , rev_id = None ) : if alembic_version >= ( 0 , 7 , 0 ) : config = current_app . extensions [ 'migrate' ] . migrate . get_config ( directory ) command . merge ( config , revisions , message = message , branch_label = branch_label , rev_id = rev_id ) else : raise RuntimeError ( 'Alembic 0.7.0 or greater is required' ) | Merge two revisions together . Creates a new migration file | 114 | 12 |
228,662 | def heads ( directory = None , verbose = False , resolve_dependencies = False ) : if alembic_version >= ( 0 , 7 , 0 ) : config = current_app . extensions [ 'migrate' ] . migrate . get_config ( directory ) command . heads ( config , verbose = verbose , resolve_dependencies = resolve_dependencies ) else : raise RuntimeError ( 'Alembic 0.7.0 or greater is required' ) | Show current available heads in the script directory | 100 | 8 |
228,663 | def branches ( directory = None , verbose = False ) : config = current_app . extensions [ 'migrate' ] . migrate . get_config ( directory ) if alembic_version >= ( 0 , 7 , 0 ) : command . branches ( config , verbose = verbose ) else : command . branches ( config ) | Show current branch points | 70 | 4 |
228,664 | def current ( directory = None , verbose = False , head_only = False ) : config = current_app . extensions [ 'migrate' ] . migrate . get_config ( directory ) if alembic_version >= ( 0 , 7 , 0 ) : command . current ( config , verbose = verbose , head_only = head_only ) else : command . current ( config ) | Display the current revision for each database . | 84 | 8 |
228,665 | def to_json ( self , content , pretty_print = False ) : if PY3 : if isinstance ( content , bytes ) : content = content . decode ( encoding = 'utf-8' ) if pretty_print : json_ = self . _json_pretty_print ( content ) else : json_ = json . loads ( content ) logger . info ( 'To JSON using : content=%s ' % ( content ) ) logger . info ( 'To JSON using : pretty_print=%s ' % ( pretty_print ) ) return json_ | Convert a string to a JSON object | 119 | 8 |
228,666 | def get_request ( self , alias , uri , headers = None , json = None , params = None , allow_redirects = None , timeout = None ) : session = self . _cache . switch ( alias ) redir = True if allow_redirects is None else allow_redirects response = self . _get_request ( session , uri , params , headers , json , redir , timeout ) logger . info ( 'Get Request using : alias=%s, uri=%s, headers=%s json=%s' % ( alias , uri , headers , json ) ) return response | Send a GET request on the session object found using the given alias | 134 | 13 |
228,667 | def post_request ( self , alias , uri , data = None , json = None , params = None , headers = None , files = None , allow_redirects = None , timeout = None ) : session = self . _cache . switch ( alias ) if not files : data = self . _format_data_according_to_header ( session , data , headers ) redir = True if allow_redirects is None else allow_redirects response = self . _body_request ( "post" , session , uri , data , json , params , files , headers , redir , timeout ) dataStr = self . _format_data_to_log_string_according_to_header ( data , headers ) logger . info ( 'Post Request using : alias=%s, uri=%s, data=%s, headers=%s, files=%s, allow_redirects=%s ' % ( alias , uri , dataStr , headers , files , redir ) ) return response | Send a POST request on the session object found using the given alias | 222 | 13 |
228,668 | def delete_request ( self , alias , uri , data = None , json = None , params = None , headers = None , allow_redirects = None , timeout = None ) : session = self . _cache . switch ( alias ) data = self . _format_data_according_to_header ( session , data , headers ) redir = True if allow_redirects is None else allow_redirects response = self . _delete_request ( session , uri , data , json , params , headers , redir , timeout ) if isinstance ( data , bytes ) : data = data . decode ( 'utf-8' ) logger . info ( 'Delete Request using : alias=%s, uri=%s, data=%s, \ headers=%s, allow_redirects=%s ' % ( alias , uri , data , headers , redir ) ) return response | Send a DELETE request on the session object found using the given alias | 196 | 15 |
228,669 | def head_request ( self , alias , uri , headers = None , allow_redirects = None , timeout = None ) : session = self . _cache . switch ( alias ) redir = False if allow_redirects is None else allow_redirects response = self . _head_request ( session , uri , headers , redir , timeout ) logger . info ( 'Head Request using : alias=%s, uri=%s, headers=%s, \ allow_redirects=%s ' % ( alias , uri , headers , redir ) ) return response | Send a HEAD request on the session object found using the given alias | 129 | 13 |
228,670 | def options_request ( self , alias , uri , headers = None , allow_redirects = None , timeout = None ) : session = self . _cache . switch ( alias ) redir = True if allow_redirects is None else allow_redirects response = self . _options_request ( session , uri , headers , redir , timeout ) logger . info ( 'Options Request using : alias=%s, uri=%s, headers=%s, allow_redirects=%s ' % ( alias , uri , headers , redir ) ) return response | Send an OPTIONS request on the session object found using the given alias | 128 | 14 |
228,671 | def _get_url ( self , session , uri ) : url = session . url if uri : slash = '' if uri . startswith ( '/' ) else '/' url = "%s%s%s" % ( session . url , slash , uri ) return url | Helper method to get the full url | 62 | 7 |
228,672 | def _json_pretty_print ( self , content ) : temp = json . loads ( content ) return json . dumps ( temp , sort_keys = True , indent = 4 , separators = ( ',' , ': ' ) ) | Pretty print a JSON object | 50 | 5 |
228,673 | def get_measurements ( self , measurement = 'Weight' , lower_bound = None , upper_bound = None ) : if upper_bound is None : upper_bound = datetime . date . today ( ) if lower_bound is None : lower_bound = upper_bound - datetime . timedelta ( days = 30 ) # If they entered the dates in the opposite order, let's # just flip them around for them as a convenience if lower_bound > upper_bound : lower_bound , upper_bound = upper_bound , lower_bound # get the URL for the main check in page document = self . _get_document_for_url ( self . _get_url_for_measurements ( ) ) # gather the IDs for all measurement types measurement_ids = self . _get_measurement_ids ( document ) # select the measurement ID based on the input if measurement in measurement_ids . keys ( ) : measurement_id = measurement_ids [ measurement ] else : raise ValueError ( "Measurement '%s' does not exist." % measurement ) page = 1 measurements = OrderedDict ( ) # retrieve entries until finished while True : # retrieve the HTML from MyFitnessPal document = self . _get_document_for_url ( self . _get_url_for_measurements ( page , measurement_id ) ) # parse the HTML for measurement entries and add to dictionary results = self . _get_measurements ( document ) measurements . update ( results ) # stop if there are no more entries if len ( results ) == 0 : break # continue if the lower bound has not been reached elif list ( results . keys ( ) ) [ - 1 ] > lower_bound : page += 1 continue # otherwise stop else : break # remove entries that are not within the dates specified for date in list ( measurements . keys ( ) ) : if not upper_bound >= date >= lower_bound : del measurements [ date ] return measurements | Returns measurements of a given name between two dates . | 420 | 10 |
228,674 | def set_measurements ( self , measurement = 'Weight' , value = None ) : if value is None : raise ValueError ( "Cannot update blank value." ) # get the URL for the main check in page # this is left in because we need to parse # the 'measurement' name to set the value. document = self . _get_document_for_url ( self . _get_url_for_measurements ( ) ) # gather the IDs for all measurement types measurement_ids = self . _get_measurement_ids ( document ) # check if the measurement exists before going too far if measurement not in measurement_ids . keys ( ) : raise ValueError ( "Measurement '%s' does not exist." % measurement ) # build the update url. update_url = parse . urljoin ( self . BASE_URL , 'measurements/save' ) # setup a dict for the post data = { } # here's where we need that required element data [ 'authenticity_token' ] = self . _authenticity_token # Weight has it's own key value pair if measurement == 'Weight' : data [ 'weight[display_value]' ] = value # the other measurements have generic names with # an incrementing numeric index. measurement_index = 0 # iterate all the measurement_ids for measurement_id in measurement_ids . keys ( ) : # create the measurement_type[n] # key value pair n = str ( measurement_index ) meas_type = 'measurement_type[' + n + ']' meas_val = 'measurement_value[' + n + ']' data [ meas_type ] = measurement_ids [ measurement_id ] # and if it corresponds to the value we want to update if measurement == measurement_id : # create the measurement_value[n] # key value pair and assign it the value. data [ meas_val ] = value else : # otherwise, create the key value pair and leave it blank data [ meas_val ] = "" measurement_index += 1 # now post it. result = self . session . post ( update_url , data = data ) # throw an error if it failed. if not result . ok : raise RuntimeError ( "Unable to update measurement in MyFitnessPal: " "status code: {status}" . format ( status = result . status_code ) ) | Sets measurement for today s date . | 510 | 8 |
228,675 | def get_measurement_id_options ( self ) : # get the URL for the main check in page document = self . _get_document_for_url ( self . _get_url_for_measurements ( ) ) # gather the IDs for all measurement types measurement_ids = self . _get_measurement_ids ( document ) return measurement_ids | Returns list of measurement choices . | 81 | 6 |
228,676 | def file_supports_color ( file_obj ) : plat = sys . platform supported_platform = plat != 'Pocket PC' and ( plat != 'win32' or 'ANSICON' in os . environ ) is_a_tty = file_is_a_tty ( file_obj ) return ( supported_platform and is_a_tty ) | Returns True if the running system s terminal supports color . | 78 | 11 |
228,677 | def load_report ( identifier = None ) : path = os . path . join ( report_dir ( ) , identifier + '.pyireport' ) return ProfilerSession . load ( path ) | Returns the session referred to by identifier | 41 | 7 |
228,678 | def save_report ( session ) : # prune this folder to contain the last 10 sessions previous_reports = glob . glob ( os . path . join ( report_dir ( ) , '*.pyireport' ) ) previous_reports . sort ( reverse = True ) while len ( previous_reports ) > 10 : report_file = previous_reports . pop ( ) os . remove ( report_file ) identifier = time . strftime ( '%Y-%m-%dT%H-%M-%S' , time . localtime ( session . start_time ) ) path = os . path . join ( report_dir ( ) , identifier + '.pyireport' ) session . save ( path ) return path , identifier | Saves the session to a temp file and returns that path . Also prunes the number of reports to 10 so there aren t loads building up . | 157 | 30 |
228,679 | def root_frame ( self , trim_stem = True ) : root_frame = None frame_stack = [ ] for frame_tuple in self . frame_records : identifier_stack = frame_tuple [ 0 ] time = frame_tuple [ 1 ] # now we must create a stack of frame objects and assign this time to the leaf for stack_depth , frame_identifier in enumerate ( identifier_stack ) : if stack_depth < len ( frame_stack ) : if frame_identifier != frame_stack [ stack_depth ] . identifier : # trim any frames after and including this one del frame_stack [ stack_depth : ] if stack_depth >= len ( frame_stack ) : frame = Frame ( frame_identifier ) frame_stack . append ( frame ) if stack_depth == 0 : # There should only be one root frame, as far as I know assert root_frame is None , ASSERTION_MESSAGE root_frame = frame else : parent = frame_stack [ stack_depth - 1 ] parent . add_child ( frame ) # trim any extra frames del frame_stack [ stack_depth + 1 : ] # pylint: disable=W0631 # assign the time to the final frame frame_stack [ - 1 ] . add_child ( SelfTimeFrame ( self_time = time ) ) if root_frame is None : return None if trim_stem : root_frame = self . _trim_stem ( root_frame ) return root_frame | Parses the internal frame records and returns a tree of Frame objects | 325 | 14 |
228,680 | def remove_from_parent ( self ) : if self . parent : self . parent . _children . remove ( self ) self . parent . _invalidate_time_caches ( ) self . parent = None | Removes this frame from its parent and nulls the parent link | 46 | 13 |
228,681 | def add_child ( self , frame , after = None ) : frame . remove_from_parent ( ) frame . parent = self if after is None : self . _children . append ( frame ) else : index = self . _children . index ( after ) + 1 self . _children . insert ( index , frame ) self . _invalidate_time_caches ( ) | Adds a child frame updating the parent link . Optionally insert the frame in a specific position by passing the frame to insert this one after . | 81 | 28 |
228,682 | def add_children ( self , frames , after = None ) : if after is not None : # if there's an 'after' parameter, add the frames in reverse so the order is # preserved. for frame in reversed ( frames ) : self . add_child ( frame , after = after ) else : for frame in frames : self . add_child ( frame ) | Convenience method to add multiple frames at once . | 77 | 11 |
228,683 | def file_path_short ( self ) : if not hasattr ( self , '_file_path_short' ) : if self . file_path : result = None for path in sys . path : # On Windows, if self.file_path and path are on different drives, relpath # will result in exception, because it cannot compute a relpath in this case. # The root cause is that on Windows, there is no root dir like '/' on Linux. try : candidate = os . path . relpath ( self . file_path , path ) except ValueError : continue if not result or ( len ( candidate . split ( os . sep ) ) < len ( result . split ( os . sep ) ) ) : result = candidate self . _file_path_short = result else : self . _file_path_short = None return self . _file_path_short | Return the path resolved against the closest entry in sys . path | 188 | 12 |
228,684 | def exit_frames ( self ) : if self . _exit_frames is None : exit_frames = [ ] for frame in self . frames : if any ( c . group != self for c in frame . children ) : exit_frames . append ( frame ) self . _exit_frames = exit_frames return self . _exit_frames | Returns a list of frames whose children include a frame outside of the group | 72 | 14 |
228,685 | def first_interesting_frame ( self ) : root_frame = self . root_frame ( ) frame = root_frame while len ( frame . children ) <= 1 : if frame . children : frame = frame . children [ 0 ] else : # there are no branches return root_frame return frame | Traverse down the frame hierarchy until a frame is found with more than one child | 62 | 16 |
228,686 | def aggregate_repeated_calls ( frame , options ) : if frame is None : return None children_by_identifier = { } # iterate over a copy of the children since it's going to mutate while we're iterating for child in frame . children : if child . identifier in children_by_identifier : aggregate_frame = children_by_identifier [ child . identifier ] # combine the two frames, putting the children and self_time into the aggregate frame. aggregate_frame . self_time += child . self_time if child . children : aggregate_frame . add_children ( child . children ) # remove this frame, it's been incorporated into aggregate_frame child . remove_from_parent ( ) else : # never seen this identifier before. It becomes the aggregate frame. children_by_identifier [ child . identifier ] = child # recurse into the children for child in frame . children : aggregate_repeated_calls ( child , options = options ) # sort the children by time # it's okay to use the internal _children list, sinde we're not changing the tree # structure. frame . _children . sort ( key = methodcaller ( 'time' ) , reverse = True ) # pylint: disable=W0212 return frame | Converts a timeline into a time - aggregate summary . | 274 | 11 |
228,687 | def merge_consecutive_self_time ( frame , options ) : if frame is None : return None previous_self_time_frame = None for child in frame . children : if isinstance ( child , SelfTimeFrame ) : if previous_self_time_frame : # merge previous_self_time_frame . self_time += child . self_time child . remove_from_parent ( ) else : # keep a reference, maybe it'll be added to on the next loop previous_self_time_frame = child else : previous_self_time_frame = None for child in frame . children : merge_consecutive_self_time ( child , options = options ) return frame | Combines consecutive self time frames | 149 | 6 |
228,688 | def remove_unnecessary_self_time_nodes ( frame , options ) : if frame is None : return None if len ( frame . children ) == 1 and isinstance ( frame . children [ 0 ] , SelfTimeFrame ) : child = frame . children [ 0 ] frame . self_time += child . self_time child . remove_from_parent ( ) for child in frame . children : remove_unnecessary_self_time_nodes ( child , options = options ) return frame | When a frame has only one child and that is a self - time frame remove that node since it s unnecessary - it clutters the output and offers no additional information . | 105 | 34 |
228,689 | def open_in_browser ( self , session , output_filename = None ) : if output_filename is None : output_file = tempfile . NamedTemporaryFile ( suffix = '.html' , delete = False ) output_filename = output_file . name with codecs . getwriter ( 'utf-8' ) ( output_file ) as f : f . write ( self . render ( session ) ) else : with codecs . open ( output_filename , 'w' , 'utf-8' ) as f : f . write ( self . render ( session ) ) from pyinstrument . vendor . six . moves import urllib url = urllib . parse . urlunparse ( ( 'file' , '' , output_filename , '' , '' , '' ) ) webbrowser . open ( url ) return output_filename | Open the rendered HTML in a webbrowser . | 179 | 9 |
228,690 | def run ( self ) : if subprocess . call ( [ 'npm' , '--version' ] ) != 0 : raise RuntimeError ( 'npm is required to build the HTML renderer.' ) self . check_call ( [ 'npm' , 'install' ] , cwd = HTML_RENDERER_DIR ) self . check_call ( [ 'npm' , 'run' , 'build' ] , cwd = HTML_RENDERER_DIR ) self . copy_file ( HTML_RENDERER_DIR + '/dist/js/app.js' , 'pyinstrument/renderers/html_resources/app.js' ) setuptools . command . build_py . build_py . run ( self ) | compile the JS then run superclass implementation | 166 | 9 |
228,691 | def deprecated ( func , * args , * * kwargs ) : warnings . warn ( '{} is deprecated and should no longer be used.' . format ( func ) , DeprecationWarning , stacklevel = 3 ) return func ( * args , * * kwargs ) | Marks a function as deprecated . | 59 | 7 |
228,692 | def deprecated_option ( option_name , message = '' ) : def caller ( func , * args , * * kwargs ) : if option_name in kwargs : warnings . warn ( '{} is deprecated. {}' . format ( option_name , message ) , DeprecationWarning , stacklevel = 3 ) return func ( * args , * * kwargs ) return decorator ( caller ) | Marks an option as deprecated . | 88 | 7 |
228,693 | def THUMBNAIL_OPTIONS ( self ) : from django . core . exceptions import ImproperlyConfigured size = self . _setting ( 'DJNG_THUMBNAIL_SIZE' , ( 200 , 200 ) ) if not ( isinstance ( size , ( list , tuple ) ) and len ( size ) == 2 and isinstance ( size [ 0 ] , int ) and isinstance ( size [ 1 ] , int ) ) : raise ImproperlyConfigured ( "'DJNG_THUMBNAIL_SIZE' must be a 2-tuple of integers." ) return { 'crop' : True , 'size' : size } | Set the size as a 2 - tuple for thumbnailed images after uploading them . | 142 | 17 |
228,694 | def get_context ( self , name , value , attrs ) : context = super ( NgWidgetMixin , self ) . get_context ( name , value , attrs ) if callable ( getattr ( self . _field , 'update_widget_rendering_context' , None ) ) : self . _field . update_widget_rendering_context ( context ) return context | Some widgets require a modified rendering context if they contain angular directives . | 83 | 13 |
228,695 | def errors ( self ) : if not hasattr ( self , '_errors_cache' ) : self . _errors_cache = self . form . get_field_errors ( self ) return self . _errors_cache | Returns a TupleErrorList for this field . This overloaded method adds additional error lists to the errors as detected by the form validator . | 47 | 28 |
228,696 | def css_classes ( self , extra_classes = None ) : if hasattr ( extra_classes , 'split' ) : extra_classes = extra_classes . split ( ) extra_classes = set ( extra_classes or [ ] ) # field_css_classes is an optional member of a Form optimized for django-angular field_css_classes = getattr ( self . form , 'field_css_classes' , None ) if hasattr ( field_css_classes , 'split' ) : extra_classes . update ( field_css_classes . split ( ) ) elif isinstance ( field_css_classes , ( list , tuple ) ) : extra_classes . update ( field_css_classes ) elif isinstance ( field_css_classes , dict ) : extra_field_classes = [ ] for key in ( '*' , self . name ) : css_classes = field_css_classes . get ( key ) if hasattr ( css_classes , 'split' ) : extra_field_classes = css_classes . split ( ) elif isinstance ( css_classes , ( list , tuple ) ) : if '__default__' in css_classes : css_classes . remove ( '__default__' ) extra_field_classes . extend ( css_classes ) else : extra_field_classes = css_classes extra_classes . update ( extra_field_classes ) return super ( NgBoundField , self ) . css_classes ( extra_classes ) | Returns a string of space - separated CSS classes for the wrapping element of this input field . | 331 | 18 |
228,697 | def get_field_errors ( self , field ) : identifier = format_html ( '{0}[\'{1}\']' , self . form_name , field . name ) errors = self . errors . get ( field . html_name , [ ] ) return self . error_class ( [ SafeTuple ( ( identifier , self . field_error_css_classes , '$pristine' , '$pristine' , 'invalid' , e ) ) for e in errors ] ) | Return server side errors . Shall be overridden by derived forms to add their extra errors for AngularJS . | 108 | 21 |
228,698 | def update_widget_attrs ( self , bound_field , attrs ) : if bound_field . field . has_subwidgets ( ) is False : widget_classes = getattr ( self , 'widget_css_classes' , None ) if widget_classes : if 'class' in attrs : attrs [ 'class' ] += ' ' + widget_classes else : attrs . update ( { 'class' : widget_classes } ) return attrs | Updated the widget attributes which shall be added to the widget when rendering this field . | 101 | 16 |
228,699 | def rectify_multipart_form_data ( self , data ) : for name , field in self . base_fields . items ( ) : try : field . implode_multi_values ( name , data ) except AttributeError : pass return data | If a widget was converted and the Form data was submitted through a multipart request then these data fields must be converted to suit the Django Form validation | 55 | 29 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.