idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
229,500
def minutes_for_sessions_in_range ( self , start_session_label , end_session_label ) : first_minute , _ = self . open_and_close_for_session ( start_session_label ) _ , last_minute = self . open_and_close_for_session ( end_session_label ) return self . minutes_in_range ( first_minute , last_minute )
Returns all the minutes for all the sessions from the given start session label to the given end session label inclusive .
229,501
def open_and_close_for_session ( self , session_label ) : sched = self . schedule return ( sched . at [ session_label , 'market_open' ] . tz_localize ( UTC ) , sched . at [ session_label , 'market_close' ] . tz_localize ( UTC ) , )
Returns a tuple of timestamps of the open and close of the session represented by the given label .
229,502
def all_minutes ( self ) : opens_in_ns = self . _opens . values . astype ( 'datetime64[ns]' , ) . view ( 'int64' ) closes_in_ns = self . _closes . values . astype ( 'datetime64[ns]' , ) . view ( 'int64' ) return DatetimeIndex ( compute_all_minutes ( opens_in_ns , closes_in_ns ) , tz = UTC , )
Returns a DatetimeIndex representing all the minutes in this calendar .
229,503
def minute_to_session_label ( self , dt , direction = "next" ) : if direction == "next" : try : return self . _minute_to_session_label_cache [ dt ] except KeyError : pass idx = searchsorted ( self . market_closes_nanos , dt ) current_or_next_session = self . schedule . index [ idx ] self . _minute_to_session_label_cach...
Given a minute get the label of its containing session .
229,504
def minute_index_to_session_labels ( self , index ) : if not index . is_monotonic_increasing : raise ValueError ( "Non-ordered index passed to minute_index_to_session_labels." ) prev_opens = ( self . _opens . values . searchsorted ( index . values , side = 'right' ) - 1 ) next_closes = ( self . _closes . values . searc...
Given a sorted DatetimeIndex of market minutes return a DatetimeIndex of the corresponding session labels .
229,505
def _special_dates ( self , calendars , ad_hoc_dates , start_date , end_date ) : regular = [ scheduled_special_times ( calendar , start_date , end_date , time_ , self . tz , ) for time_ , calendar in calendars ] ad_hoc = [ pd . Series ( index = pd . to_datetime ( datetimes , utc = True ) , data = days_at_time ( datetim...
Compute a Series of times associated with special dates .
229,506
def read ( * paths ) : basedir = os . path . dirname ( __file__ ) fullpath = os . path . join ( basedir , * paths ) contents = io . open ( fullpath , encoding = 'utf-8' ) . read ( ) . strip ( ) return contents
Read a text file .
229,507
def parse ( self , raw ) : results = list ( self . parse_partial ( raw ) ) results . extend ( self . parse_finalize ( ) ) return results [ 0 ] if len ( results ) == 1 else results
Returns a Python object decoded from the bytes of this encoding .
229,508
def parse_partial ( self , data ) : try : lines = self . _decoder1 . decode ( data , False ) . split ( "\n" ) if len ( self . _buffer ) > 0 and self . _buffer [ - 1 ] is not None : self . _buffer [ - 1 ] += lines [ 0 ] self . _buffer . extend ( lines [ 1 : ] ) else : self . _buffer . extend ( lines ) except UnicodeDeco...
Incrementally decodes JSON data sets into Python objects .
229,509
def parse_finalize ( self ) : try : try : self . _decoder1 . decode ( b'' , True ) except UnicodeDecodeError as error : raise exceptions . DecodingError ( 'json' , error ) if self . _buffer : raise exceptions . DecodingError ( 'json' , self . _lasterror ) finally : self . _buffer = [ ] self . _lasterror = None self . _...
Raises errors for incomplete buffered data that could not be parsed because the end of the input data has been reached .
229,510
def encode ( self , obj ) : try : result = json . dumps ( obj , sort_keys = True , indent = None , separators = ( ',' , ':' ) , ensure_ascii = False ) if isinstance ( result , six . text_type ) : return result . encode ( "utf-8" ) else : return result except ( UnicodeEncodeError , TypeError ) as error : raise exception...
Returns obj serialized as JSON formatted bytes .
229,511
def parse_finalize ( self ) : try : self . _buffer . seek ( 0 , 0 ) yield pickle . load ( self . _buffer ) except pickle . UnpicklingError as error : raise exceptions . DecodingError ( 'pickle' , error )
Parses the buffered data and yields the result .
229,512
def encode ( self , obj ) : try : return pickle . dumps ( obj ) except pickle . PicklingError as error : raise exceptions . EncodingError ( 'pickle' , error )
Returns obj serialized as a pickle binary string .
229,513
def glob_compile ( pat ) : i , n = 0 , len ( pat ) res = '' while i < n : c = pat [ i ] i = i + 1 if c == '/' and len ( pat ) > ( i + 2 ) and pat [ i : ( i + 3 ) ] == '**/' : i = i + 3 res = res + '[/]([^/]*[/])*' elif c == '*' : if len ( pat ) > i and pat [ i ] == '*' : i = i + 1 res = res + '.*' else : res = res + '[...
Translate a shell glob PATTERN to a regular expression .
229,514
def stream_files ( files , chunk_size = default_chunk_size ) : stream = FileStream ( files , chunk_size = chunk_size ) return stream . body ( ) , stream . headers
Gets a buffered generator for streaming files .
229,515
def stream_directory ( directory , recursive = False , patterns = '**' , chunk_size = default_chunk_size ) : stream = DirectoryStream ( directory , recursive = recursive , patterns = patterns , chunk_size = chunk_size ) return stream . body ( ) , stream . headers
Gets a buffered generator for streaming directories .
229,516
def stream_filesystem_node ( path , recursive = False , patterns = '**' , chunk_size = default_chunk_size ) : is_dir = isinstance ( path , six . string_types ) and os . path . isdir ( path ) if recursive or is_dir : return stream_directory ( path , recursive , patterns , chunk_size ) else : return stream_files ( path ,...
Gets a buffered generator for streaming either files or directories .
229,517
def stream_bytes ( data , chunk_size = default_chunk_size ) : stream = BytesStream ( data , chunk_size = chunk_size ) return stream . body ( ) , stream . headers
Gets a buffered generator for streaming binary data .
229,518
def stream_text ( text , chunk_size = default_chunk_size ) : if isgenerator ( text ) : def binary_stream ( ) : for item in text : if six . PY2 and isinstance ( text , six . binary_type ) : yield text else : yield text . encode ( "utf-8" ) data = binary_stream ( ) elif six . PY2 and isinstance ( text , six . binary_type...
Gets a buffered generator for streaming text .
229,519
def _write_headers ( self , headers ) : if headers : for name in sorted ( headers . keys ( ) ) : yield name . encode ( "ascii" ) yield b': ' yield headers [ name ] . encode ( "ascii" ) yield CRLF yield CRLF
Yields the HTTP header text for some content .
229,520
def file_open ( self , fn ) : yield b'--' yield self . boundary . encode ( ) yield CRLF headers = content_disposition ( fn ) headers . update ( content_type ( fn ) ) for c in self . _write_headers ( headers ) : yield c
Yields the opening text of a file section in multipart HTTP .
229,521
def file_chunks ( self , fp ) : fsize = utils . file_size ( fp ) offset = 0 if hasattr ( fp , 'readinto' ) : while offset < fsize : nb = fp . readinto ( self . _internal ) yield self . buf [ : nb ] offset += nb else : while offset < fsize : nb = min ( self . chunk_size , fsize - offset ) yield fp . read ( nb ) offset +...
Yields chunks of a file .
229,522
def gen_chunks ( self , gen ) : for data in gen : size = len ( data ) if size < self . chunk_size : yield data else : mv = buffer ( data ) offset = 0 while offset < size : nb = min ( self . chunk_size , size - offset ) yield mv [ offset : offset + nb ] offset += nb
Generates byte chunks of a given size .
229,523
def body ( self ) : for fp , need_close in self . files : try : name = os . path . basename ( fp . name ) except AttributeError : name = '' for chunk in self . gen_chunks ( self . envelope . file_open ( name ) ) : yield chunk for chunk in self . file_chunks ( fp ) : yield chunk for chunk in self . gen_chunks ( self . e...
Yields the body of the buffered file .
229,524
def _prepare ( self ) : names = [ ] added_directories = set ( ) def add_directory ( short_path ) : if short_path in added_directories : return dir_base = short_path dir_parts = [ ] while dir_base : dir_base , dir_name = os . path . split ( dir_base ) dir_parts . append ( dir_name ) if dir_base in added_directories : br...
Pre - formats the multipart HTTP request to transmit the directory .
229,525
def body ( self ) : for chunk in self . gen_chunks ( self . envelope . file_open ( self . name ) ) : yield chunk for chunk in self . gen_chunks ( self . data ) : yield chunk for chunk in self . gen_chunks ( self . envelope . file_close ( ) ) : yield chunk for chunk in self . close ( ) : yield chunk
Yields the encoded body .
229,526
def pass_defaults ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : merged = { } merged . update ( self . defaults ) merged . update ( kwargs ) return func ( self , * args , ** merged ) return wrapper
Decorator that returns a function named wrapper .
229,527
def request ( self , path , args = [ ] , files = [ ] , opts = { } , stream = False , decoder = None , headers = { } , data = None ) : url = self . base + path params = [ ] params . append ( ( 'stream-channels' , 'true' ) ) for opt in opts . items ( ) : params . append ( opt ) for arg in args : params . append ( ( 'arg'...
Makes an HTTP request to the IPFS daemon .
229,528
def download ( self , path , args = [ ] , filepath = None , opts = { } , compress = True , ** kwargs ) : url = self . base + path wd = filepath or '.' params = [ ] params . append ( ( 'stream-channels' , 'true' ) ) params . append ( ( 'archive' , 'true' ) ) if compress : params . append ( ( 'compress' , 'true' ) ) for ...
Makes a request to the IPFS daemon to download a file .
229,529
def session ( self ) : self . _session = requests . session ( ) yield self . _session . close ( ) self . _session = None
A context manager for this client s session .
229,530
def assert_version ( version , minimum = VERSION_MINIMUM , maximum = VERSION_MAXIMUM ) : version = list ( map ( int , version . split ( '-' , 1 ) [ 0 ] . split ( '.' ) ) ) minimum = list ( map ( int , minimum . split ( '-' , 1 ) [ 0 ] . split ( '.' ) ) ) maximum = list ( map ( int , maximum . split ( '-' , 1 ) [ 0 ] . ...
Make sure that the given daemon version is supported by this client version .
229,531
def add ( self , files , recursive = False , pattern = '**' , * args , ** kwargs ) : opts = { "trickle" : kwargs . pop ( "trickle" , False ) , "only-hash" : kwargs . pop ( "only_hash" , False ) , "wrap-with-directory" : kwargs . pop ( "wrap_with_directory" , False ) , "pin" : kwargs . pop ( "pin" , True ) } if "chunker...
Add a file or directory of files to IPFS .
229,532
def get ( self , multihash , ** kwargs ) : args = ( multihash , ) return self . _client . download ( '/get' , args , ** kwargs )
Downloads a file or directory of files from IPFS .
229,533
def cat ( self , multihash , offset = 0 , length = - 1 , ** kwargs ) : r 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 .
229,534
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 .
229,535
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 .
229,536
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 .
229,537
def block_get ( self , multihash , ** kwargs ) : r args = ( multihash , ) return self . _client . request ( '/block/get' , args , ** kwargs )
r Returns the raw contents of a block .
229,538
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 .
229,539
def bitswap_unwant ( self , key , ** kwargs ) : args = ( key , ) return self . _client . request ( '/bitswap/unwant' , args , ** kwargs )
Remove a given block from wantlist .
229,540
def object_data ( self , multihash , ** kwargs ) : r args = ( multihash , ) return self . _client . request ( '/object/data' , args , ** kwargs )
r Returns the raw bytes in an IPFS object .
229,541
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 .
229,542
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 .
229,543
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 .
229,544
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 .
229,545
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 .
229,546
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 .
229,547
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 .
229,548
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 .
229,549
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
229,550
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
229,551
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 . reques...
Publishes an object to IPNS .
229,552
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 .
229,553
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 .
229,554
def pin_add ( self , path , * paths , ** kwargs ) : 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 .
229,555
def pin_rm ( self , path , * paths , ** kwargs ) : 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 .
229,556
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 .
229,557
def pin_update ( self , from_path , to_path , ** kwargs ) : 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 .
229,558
def pin_verify ( self , path , * paths , ** kwargs ) : 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 .
229,559
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 .
229,560
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 .
229,561
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 .
229,562
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 .
229,563
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 .
229,564
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" ...
Queries the DHT for its best value related to given key .
229,565
def ping ( self , peer , * peers , ** kwargs ) : 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 .
229,566
def config ( self , key , value = None , ** kwargs ) : args = ( key , value ) return self . _client . request ( '/config' , args , decoder = 'json' , ** kwargs )
Controls configuration variables .
229,567
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 .
229,568
def log_level ( self , subsystem , level , ** kwargs ) : r args = ( subsystem , level ) return self . _client . request ( '/log/level' , args , decoder = 'json' , ** kwargs )
r Changes the logging output of a running daemon .
229,569
def log_tail ( self , ** kwargs ) : r return self . _client . request ( '/log/tail' , decoder = 'json' , stream = True , ** kwargs )
r Reads log outputs as they are written .
229,570
def files_cp ( self , source , dest , ** kwargs ) : args = ( source , dest ) return self . _client . request ( '/files/cp' , args , ** kwargs )
Copies files within the MFS .
229,571
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 .
229,572
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 .
229,573
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 .
229,574
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 .
229,575
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...
Writes to a mutable file in the MFS .
229,576
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 .
229,577
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 .
229,578
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 .
229,579
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 .
229,580
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 .
229,581
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 .
229,582
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 .
229,583
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
229,584
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
229,585
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 .
229,586
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 .
229,587
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 .
229,588
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
229,589
def downgrade ( directory , sql , tag , x_arg , revision ) : _downgrade ( directory , revision , sql , tag , x_arg )
Revert to a previous version
229,590
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 .
229,591
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 . extensi...
Creates a new migration repository
229,592
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 .
229,593
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...
Merge two revisions together . Creates a new migration file
229,594
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 RuntimeEr...
Show current available heads in the script directory
229,595
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
229,596
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 .
229,597
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 ) ) log...
Convert a string to a JSON object
229,598
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 , tim...
Send a GET request on the session object found using the given alias
229,599
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_redi...
Send a POST request on the session object found using the given alias