idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
57,200 | def get_table_info ( self , tablename ) : conn = self . __get_conn ( ) ret = a99 . get_table_info ( conn , tablename ) if len ( ret ) == 0 : raise RuntimeError ( "Cannot get info for table '{}'" . format ( tablename ) ) more = self . gui_info . get ( tablename ) for row in ret . values ( ) : caption , tooltip = None , ... | Returns information about fields of a specific table |
57,201 | def __get_conn ( self , flag_force_new = False , filename = None ) : flag_open_new = flag_force_new or not self . _conn_is_open ( ) if flag_open_new : if filename is None : filename = self . filename conn = self . _get_conn ( filename ) self . _conn = conn else : conn = self . _conn return conn | Returns connection to database . Tries to return existing connection unless flag_force_new |
57,202 | def flatten_multidict ( multidict ) : return dict ( [ ( key , value if len ( value ) > 1 else value [ 0 ] ) for ( key , value ) in multidict . iterlists ( ) ] ) | Return flattened dictionary from MultiDict . |
57,203 | def __setitem ( self , chunk , key , keys , value , extend = False ) : def setitem ( chunk ) : if keys : return self . __setitem ( chunk , keys [ 0 ] , keys [ 1 : ] , value , extend ) else : return value if key in [ '.' , ']' ] : chunk [ key ] = value elif ']' in key : key = int ( key [ : - 1 ] . replace ( 'n' , '-1' )... | Helper function to fill up the dictionary . |
57,204 | def set ( self , key , value , extend = False , ** kwargs ) : self . __setitem__ ( key , value , extend , ** kwargs ) | Extended standard set function . |
57,205 | def create_default_database ( reset : bool = False ) -> GraphDatabaseInterface : import sqlalchemy from sqlalchemy . ext . declarative import declarative_base from sqlalchemy . orm import sessionmaker from sqlalchemy . pool import StaticPool Base = declarative_base ( ) engine = sqlalchemy . create_engine ( "sqlite:///S... | Creates and returns a default SQLAlchemy database interface to use . |
57,206 | def _create_node ( self , index : int , name : str , external_id : Optional [ str ] = None ) -> SpotifyArtistNode : if external_id is None : graph : SpotifyArtistGraph = self . _graph items : List [ NameExternalIDPair ] = graph . client . search_artists_by_name ( name ) for item in items : if item . name == name : exte... | Returns a new SpotifyArtistNode instance with the given index and name . |
57,207 | def access_token ( self ) -> str : if self . _token_expires_at < time . time ( ) + self . _REFRESH_THRESHOLD : self . request_token ( ) return self . _token [ "access_token" ] | The access token stored within the requested token . |
57,208 | def request_token ( self ) -> None : response : requests . Response = requests . post ( self . _TOKEN_URL , auth = HTTPBasicAuth ( self . _client_id , self . _client_key ) , data = { "grant_type" : self . _GRANT_TYPE } , verify = True ) response . raise_for_status ( ) self . _token = response . json ( ) self . _token_e... | Requests a new Client Credentials Flow authentication token from the Spotify API and stores it in the token property of the object . |
57,209 | def search_artists_by_name ( self , artist_name : str , limit : int = 5 ) -> List [ NameExternalIDPair ] : response : requests . Response = requests . get ( self . _API_URL_TEMPLATE . format ( "search" ) , params = { "q" : artist_name , "type" : "artist" , "limit" : limit } , headers = { "Authorization" : "Bearer {}" .... | Returns zero or more artist name - external ID pairs that match the specified artist name . |
57,210 | def colors ( lang = "en" ) : cache_name = "colors.%s.json" % lang data = get_cached ( "colors.json" , cache_name , params = dict ( lang = lang ) ) return data [ "colors" ] | This resource returns all dyes in the game including localized names and their color component information . |
57,211 | def event_names ( lang = "en" ) : cache_name = "event_names.%s.json" % lang data = get_cached ( "event_names.json" , cache_name , params = dict ( lang = lang ) ) return dict ( [ ( event [ "id" ] , event [ "name" ] ) for event in data ] ) | This resource returns an unordered list of the localized event names for the specified language . |
57,212 | def event_details ( event_id = None , lang = "en" ) : if event_id : cache_name = "event_details.%s.%s.json" % ( event_id , lang ) params = { "event_id" : event_id , "lang" : lang } else : cache_name = "event_details.%s.json" % lang params = { "lang" : lang } data = get_cached ( "event_details.json" , cache_name , param... | This resource returns static details about available events . |
57,213 | def PhenomModel ( self , r ) : if r <= 0 : raise ValueError field = self . B0 + self . B1 * G4 . m / r + self . B2 * math . exp ( - 1 * self . H * r / G4 . m ) return field | Fit to field map |
57,214 | def set_dir ( self , dir_ ) : self . __lock_set_dir ( dir_ ) self . __lock_auto_load ( ) self . __lock_update_table ( ) self . __update_info ( ) self . __update_window_title ( ) | Sets directory auto - loads updates all GUI contents . |
57,215 | def __update_info ( self ) : from f311 import explorer as ex import f311 t = self . tableWidget z = self . listWidgetVis z . clear ( ) classes = self . __vis_classes = [ ] propss = self . __lock_get_current_propss ( ) npp = len ( propss ) s0 , s1 = "" , "" if npp == 1 : p = propss [ 0 ] if p . flag_scanned : if isinsta... | Updates visualization options and file info areas . |
57,216 | def validate ( self , value ) : if value in self . empty_values and self . required : raise ValidationError ( self . error_messages [ 'required' ] ) | This was overridden to have our own empty_values . |
57,217 | def clean ( self , value ) : obj = self . factory . create ( value ) if obj : del obj . fields del obj . alias del obj . validators del obj . required del obj . factory self . _validate_existence ( obj ) self . _run_validators ( obj ) return obj | Clean the data and validate the nested spec . |
57,218 | def serialize ( self , value , entity , request ) : self . _validate_existence ( value ) self . _run_validators ( value ) if not value : return value return self . factory . serialize ( value , request ) | Propagate to nested fields . |
57,219 | def _run_validators ( self , value ) : errors = [ ] for v in self . validators : try : v ( value ) except ValidationError , e : errors . extend ( e . messages ) if errors : raise ValidationError ( errors ) | Execute all associated validators . |
57,220 | def get_all_active ( self ) : now = timezone . now ( ) return self . select_related ( ) . filter ( active_datetime__lte = now , inactive_datetime__gte = now ) . order_by ( 'active_datetime' ) | Get all of the active messages ordered by the active_datetime . |
57,221 | def render_word ( self , word , size , color ) : pygame . font . init ( ) font = pygame . font . Font ( None , size ) self . rendered_word = font . render ( word , 0 , color ) self . word_size = font . size ( word ) | Creates a surface that contains a word . |
57,222 | def plot_word ( self , position ) : posrectangle = pygame . Rect ( position , self . word_size ) self . used_pos . append ( posrectangle ) self . cloud . blit ( self . rendered_word , position ) | Blits a rendered word on to the main display surface |
57,223 | def collides ( self , position , size ) : word_rect = pygame . Rect ( position , self . word_size ) if word_rect . collidelistall ( self . used_pos ) == [ ] : return False else : return True | Returns True if the word collides with another plotted word . |
57,224 | def expand ( self , delta_width , delta_height ) : temp_surface = pygame . Surface ( ( self . width + delta_width , self . height + delta_height ) ) ( self . width , self . height ) = ( self . width + delta_width , self . height + delta_height ) temp_surface . blit ( self . cloud , ( 0 , 0 ) ) self . cloud = temp_surfa... | Makes the cloud surface bigger . Maintains all word positions . |
57,225 | def smart_cloud ( self , input , max_text_size = 72 , min_text_size = 12 , exclude_words = True ) : self . exclude_words = exclude_words if isdir ( input ) : self . directory_cloud ( input , max_text_size , min_text_size ) elif isfile ( input ) : text = read_file ( input ) self . text_cloud ( text , max_text_size , min... | Creates a word cloud using the input . Input can be a file directory or text . Set exclude_words to true if you want to eliminate words that only occur once . |
57,226 | def directory_cloud ( self , directory , max_text_size = 72 , min_text_size = 12 , expand_width = 50 , expand_height = 50 , max_count = 100000 ) : worddict = assign_fonts ( tuplecount ( read_dir ( directory ) ) , max_text_size , min_text_size , self . exclude_words ) sorted_worddict = list ( reversed ( sorted ( worddic... | Creates a word cloud using files from a directory . The color of the words correspond to the amount of documents the word occurs in . |
57,227 | def text_cloud ( self , text , max_text_size = 72 , min_text_size = 12 , expand_width = 50 , expand_height = 50 , max_count = 100000 ) : worddict = assign_fonts ( tuplecount ( text ) , max_text_size , min_text_size , self . exclude_words ) sorted_worddict = list ( reversed ( sorted ( worddict . keys ( ) , key = lambda ... | Creates a word cloud using plain text . |
57,228 | def display ( self ) : pygame . init ( ) self . display = pygame . display . set_mode ( ( self . width , self . height ) ) self . display . blit ( self . cloud , ( 0 , 0 ) ) pygame . display . update ( ) while True : for event in pygame . event . get ( ) : if event . type == pygame . QUIT : pygame . quit ( ) return | Displays the word cloud to the screen . |
57,229 | def fermi_dist ( energy , beta ) : exponent = np . asarray ( beta * energy ) . clip ( - 600 , 600 ) return 1. / ( np . exp ( exponent ) + 1 ) | Fermi Dirac distribution |
57,230 | def diagonalize ( operator ) : eig_values , eig_vecs = LA . eigh ( operator ) emin = np . amin ( eig_values ) eig_values -= emin return eig_values , eig_vecs | diagonalizes single site Spin Hamiltonian |
57,231 | def gf_lehmann ( eig_e , eig_states , d_dag , beta , omega , d = None ) : ew = np . exp ( - beta * eig_e ) zet = ew . sum ( ) G = np . zeros_like ( omega ) basis_create = np . dot ( eig_states . T , d_dag . dot ( eig_states ) ) if d is None : tmat = np . square ( basis_create ) else : tmat = np . dot ( eig_states . T ,... | Outputs the lehmann representation of the greens function omega has to be given as matsubara or real frequencies |
57,232 | def expected_value ( operator , eig_values , eig_states , beta ) : aux = np . einsum ( 'i,ji,ji' , np . exp ( - beta * eig_values ) , eig_states , operator . dot ( eig_states ) ) return aux / partition_func ( beta , eig_values ) | Calculates the average value of an observable it requires that states and operators have the same base |
57,233 | def get_plain_text ( self ) : _msg = self . message if self . message is not None else [ "" ] msg = _msg if isinstance ( _msg , list ) else [ _msg ] line = "" if not self . line else ", line {}" . format ( self . line ) ret = [ "{} found in file '{}'{}::" . format ( self . type . capitalize ( ) , self . filename , line... | Returns a list |
57,234 | def get_plain_text ( self ) : ret = [ ] for occ in self . occurrences : ret . extend ( occ . get_plain_text ( ) ) return ret | Returns a list of strings |
57,235 | def crunch_dir ( name , n = 50 ) : if len ( name ) > n + 3 : name = "..." + name [ - n : ] return name | Puts ... in the middle of a directory name if lengh > n . |
57,236 | def _add_log_tab ( self ) : text_tab = "Log" self . pages . append ( MyPage ( text_tab = text_tab ) ) te = self . textEdit_log = self . keep_ref ( QTextEdit ( ) ) te . setReadOnly ( True ) self . tabWidget . addTab ( te , text_tab ) | Adds element to pages and new tab |
57,237 | def keyPressEvent ( self , evt ) : incr = 0 if evt . modifiers ( ) == Qt . ControlModifier : n = self . tabWidget . count ( ) if evt . key ( ) in [ Qt . Key_PageUp , Qt . Key_Backtab ] : incr = - 1 elif evt . key ( ) in [ Qt . Key_PageDown , Qt . Key_Tab ] : incr = 1 if incr != 0 : new_index = self . _get_tab_index ( )... | This handles Ctrl + PageUp Ctrl + PageDown Ctrl + Tab Ctrl + Shift + Tab |
57,238 | def _on_changed ( self ) : page = self . _get_page ( ) if not page . flag_autosave : page . flag_changed = True self . _update_gui_text_tabs ( ) | Slot for changed events |
57,239 | def _update_gui_text_tabs ( self ) : for index , page in enumerate ( self . pages ) : self . tabWidget . setTabText ( index , "{} (Alt+&{}){}" . format ( page . text_tab , index + 1 , ( " (changed)" if page . flag_changed else "" ) ) ) | Iterates through pages to update tab texts |
57,240 | def __generic_save ( self ) : page = self . _get_page ( ) f = page . editor . f if not f : return True if not page . editor . flag_valid : a99 . show_error ( "Cannot save, {0!s} has error(s)!" . format ( f . description ) ) return True if f . filename : f . save_as ( ) self . add_log ( "Saved '{}'" . format ( f . filen... | Returns False if user has cancelled a save as operation otherwise True . |
57,241 | def __generic_save_as ( self ) : page = self . _get_page ( ) if not page . editor . f : return True if page . editor . f . filename : d = page . editor . f . filename else : d = os . path . join ( self . save_dir if self . save_dir is not None else self . load_dir if self . load_dir is not None else "." , page . editor... | Returns False if user has cancelled operation otherwise True . |
57,242 | def _start_nodes_sequentially ( self , nodes ) : started_nodes = set ( ) for node in copy ( nodes ) : started = self . _start_node ( node ) if started : started_nodes . add ( node ) self . repository . save_or_update ( self ) return started_nodes | Start the nodes sequentially without forking . |
57,243 | def _start_nodes_parallel ( self , nodes , max_thread_pool_size ) : thread_pool_size = min ( len ( nodes ) , max_thread_pool_size ) thread_pool = Pool ( processes = thread_pool_size ) log . debug ( "Created pool of %d threads" , thread_pool_size ) keep_running = True def sigint_handler ( signal , frame ) : log . error ... | Start the nodes using a pool of multiprocessing threads for speed - up . |
57,244 | def _start_node ( node ) : log . debug ( "_start_node: working on node `%s`" , node . name ) if node . is_alive ( ) : log . info ( "Not starting node `%s` which is " "already up&running." , node . name ) return True else : try : node . start ( ) log . info ( "Node `%s` has been started." , node . name ) return True exc... | Start the given node VM . |
57,245 | def get_all_nodes ( self ) : nodes = self . nodes . values ( ) if nodes : return reduce ( operator . add , nodes , list ( ) ) else : return [ ] | Returns a list of all nodes in this cluster as a mixed list of different node kinds . |
57,246 | def get_frontend_node ( self ) : if self . ssh_to : if self . ssh_to in self . nodes : cls = self . nodes [ self . ssh_to ] if cls : return cls [ 0 ] else : log . warning ( "preferred `ssh_to` `%s` is empty: unable to " "get the choosen frontend node from that class." , self . ssh_to ) else : raise NodeNotFound ( "Inva... | Returns the first node of the class specified in the configuration file as ssh_to or the first node of the first class in alphabetic order . |
57,247 | def new ( self , kind , ** extra ) : if self . _free [ kind ] : index = self . _free [ kind ] . pop ( ) else : self . _top [ kind ] += 1 index = self . _top [ kind ] return self . _format ( self . pattern , kind = kind , index = index , ** extra ) | Return a host name for a new node of the given kind . |
57,248 | def use ( self , kind , name ) : try : params = self . _parse ( name ) index = int ( params [ 'index' ] , 10 ) if index in self . _free [ kind ] : self . _free [ kind ] . remove ( index ) top = self . _top [ kind ] if index > top : self . _free [ kind ] . update ( range ( top + 1 , index ) ) self . _top [ kind ] = inde... | Mark a node name as used . |
57,249 | def free ( self , kind , name ) : try : params = self . _parse ( name ) index = int ( params [ 'index' ] , 10 ) self . _free [ kind ] . add ( index ) assert index <= self . _top [ kind ] if index == self . _top [ kind ] : self . _top [ kind ] -= 1 except ValueError : pass | Mark a node name as no longer in use . |
57,250 | def is_alive ( self ) : running = False if not self . instance_id : return False try : log . debug ( "Getting information for instance %s" , self . instance_id ) running = self . _cloud_provider . is_instance_running ( self . instance_id ) except Exception as ex : log . debug ( "Ignoring error while looking for vm id %... | Checks if the current node is up and running in the cloud . It only checks the status provided by the cloud interface . Therefore a node might be running but not yet ready to ssh into it . |
57,251 | def connect ( self , keyfile = None ) : ssh = paramiko . SSHClient ( ) ssh . set_missing_host_key_policy ( paramiko . AutoAddPolicy ( ) ) if keyfile and os . path . exists ( keyfile ) : ssh . load_host_keys ( keyfile ) ips = self . ips [ : ] if self . preferred_ip : if self . preferred_ip in ips : ips . remove ( self .... | Connect to the node via ssh using the paramiko library . |
57,252 | def set_item ( self , path_ , value ) : section , path_ = self . _get_section ( path_ ) section [ path_ [ - 1 ] ] = value self . write ( ) | Sets item and automatically saves file |
57,253 | def all_subslices ( itr ) : assert iterable ( itr ) , 'generators.all_subslices only accepts iterable arguments, not {}' . format ( itr ) if not hasattr ( itr , '__len__' ) : itr = deque ( itr ) len_itr = len ( itr ) for start , _ in enumerate ( itr ) : d = deque ( ) for i in islice ( itr , start , len_itr ) : d . appe... | generates every possible slice that can be generated from an iterable |
57,254 | def data_read_write ( data_path_in , data_path_out , format_type , ** kwargs ) : if format_type == "dense" : kwargs = _set_dense_defaults_and_eval ( kwargs ) try : nlc = [ nm . strip ( ) for nm in kwargs [ 'non_label_cols' ] . split ( "," ) ] kwargs . pop ( 'non_label_cols' , None ) except KeyError : raise KeyError ( "... | General function to read format and write data . |
57,255 | def format_dense ( base_data , non_label_cols , ** kwargs ) : kwargs = _set_dense_defaults_and_eval ( kwargs ) indexed_data = base_data . set_index ( keys = non_label_cols ) columnar_data = indexed_data . stack ( dropna = False ) columnar_data = columnar_data . reset_index ( ) num = len ( non_label_cols ) columnar_data... | Formats dense data type to stacked data type . |
57,256 | def _set_dense_defaults_and_eval ( kwargs ) : kwargs [ 'delimiter' ] = kwargs . get ( 'delimiter' , ',' ) kwargs [ 'na_values' ] = kwargs . get ( 'na_values' , '' ) kwargs [ 'nan_to_zero' ] = kwargs . get ( 'nan_to_zero' , False ) kwargs [ 'drop_na' ] = kwargs . get ( 'drop_na' , False ) kwargs [ 'label_col' ] = kwargs... | Sets default values in kwargs if kwargs are not already given . |
57,257 | def plot_spectra_stacked ( ss , title = None , num_rows = None , setup = _default_setup ) : draw_spectra_stacked ( ss , title , num_rows , setup ) plt . show ( ) | Plots one or more stacked in subplots sharing same x - axis . |
57,258 | def plot_spectra_overlapped ( ss , title = None , setup = _default_setup ) : plt . figure ( ) draw_spectra_overlapped ( ss , title , setup ) plt . show ( ) | Plots one or more spectra in the same plot . |
57,259 | def plot_spectra_pieces_pdf ( ss , aint = 10 , pdf_filename = 'pieces.pdf' , setup = _default_setup ) : import f311 . explorer as ex xmin , xmax , ymin_ , ymax , _ , yspan = calc_max_min ( ss ) ymin = ymin_ if setup . ymin is None else setup . ymin num_pages = int ( math . ceil ( ( xmax - xmin ) / aint ) ) a99 . format... | Plots spectra overlapped in small wavelength intervals into a PDF file one interval per page of the PDF file . |
57,260 | def plot_spectra_pages_pdf ( ss , pdf_filename = 'pages.pdf' , setup = _default_setup ) : logger = a99 . get_python_logger ( ) xmin , xmax , ymin_ , ymax , xspan , yspan = calc_max_min ( ss ) ymin = ymin_ if setup . ymin is None else setup . ymin num_pages = len ( ss ) a99 . format_BLB ( ) pdf = matplotlib . backends .... | Plots spectra into a PDF file one spectrum per page . |
57,261 | def repeal_target ( self ) : if not self . category == 'Repeal' : raise TypeError ( "This resolution doesn't repeal anything" ) return wa . resolution ( int ( self . option ) + 1 ) | The resolution this resolution has repealed or is attempting to repeal . |
57,262 | def resolution ( self , index ) : @ api_query ( 'resolution' , id = str ( index ) ) async def result ( _ , root ) : elem = root . find ( 'RESOLUTION' ) if not elem : raise NotFound ( f'No resolution found with index {index}' ) return Resolution ( elem ) return result ( self ) | Resolution with a given index . |
57,263 | async def resolution_at_vote ( self , root ) : elem = root . find ( 'RESOLUTION' ) if elem : resolution = ResolutionAtVote ( elem ) resolution . _council_id = self . _council_id return resolution | The proposal currently being voted on . |
57,264 | def indent ( self , levels , first_line = None ) : self . _indentation_levels . append ( levels ) self . _indent_first_line . append ( first_line ) | Increase indentation by levels levels . |
57,265 | def wrap ( self , text , width = None , indent = None ) : width = width if width is not None else self . options . wrap_length indent = indent if indent is not None else self . indentation initial_indent = self . initial_indentation return textwrap . fill ( text , width = width , initial_indent = initial_indent , subse... | Return text wrapped to width and indented with indent . |
57,266 | def Construct ( self ) : self . gdml_parser . Read ( self . filename ) self . world = self . gdml_parser . GetWorldVolume ( ) self . log . info ( "Materials:" ) self . log . info ( G4 . G4Material . GetMaterialTable ( ) ) return self . world | Construct a cuboid from a GDML file without sensitive detector |
57,267 | def Construct ( self ) : self . world = self . gdml_parser . GetWorldVolume ( ) self . sensitive_detector = ScintSD ( ) my_lv = G4 . G4LogicalVolumeStore . GetInstance ( ) . GetVolumeID ( 1 ) assert my_lv . GetName ( ) == "ScintillatorBarX" my_lv . SetSensitiveDetector ( self . sensitive_detector ) my_lv = G4 . G4Logic... | Construct nuSTORM from a GDML file |
57,268 | def validate ( bbllines : iter , * , profiling = False ) : if isinstance ( bbllines , str ) : if os . path . exists ( bbllines ) : bbllines = utils . file_lines ( bbllines ) elif '\n' not in bbllines or '\t' not in bbllines : bbllines = utils . file_lines ( bbllines ) else : bbllines = bbllines . split ( '\n' ) bubble ... | Yield lines of warnings and errors about input bbl lines . |
57,269 | def inclusions_validation ( tree : BubbleTree ) -> iter : for one , two in it . combinations ( tree . inclusions , 2 ) : assert len ( one ) == len ( one . strip ( ) ) assert len ( two ) == len ( two . strip ( ) ) one_inc = set ( included ( one , tree . inclusions ) ) two_inc = set ( included ( two , tree . inclusions )... | Yield message about inclusions inconsistancies |
57,270 | def mergeability_validation ( tree : BubbleTree ) -> iter : def gen_warnings ( one , two , inc_message : str ) -> [ str ] : "Yield the warning for given (power)nodes if necessary" nodetype = '' if tree . inclusions [ one ] and tree . inclusions [ two ] : nodetype = 'power' elif tree . inclusions [ one ] or tree . inclu... | Yield message about mergables powernodes |
57,271 | def guild_details ( guild_id = None , name = None ) : if guild_id and name : warnings . warn ( "both guild_id and name are specified, " "name will be ignored" ) if guild_id : params = { "guild_id" : guild_id } cache_name = "guild_details.%s.json" % guild_id elif name : params = { "guild_name" : name } cache_name = "gui... | This resource returns details about a guild . |
57,272 | def chunks ( stream , chunk_size , output_type = tuple ) : assert iterable ( stream ) , 'chunks needs stream to be iterable' assert ( isinstance ( chunk_size , int ) and chunk_size > 0 ) or callable ( chunk_size ) , 'chunks needs chunk_size to be a positive int or callable' assert callable ( output_type ) , 'chunks nee... | returns chunks of a stream |
57,273 | def get_charset ( request ) : content_type = request . META . get ( 'CONTENT_TYPE' , None ) if content_type : return extract_charset ( content_type ) if content_type else None else : return None | Extract charset from the content type |
57,274 | def parse_accept_header ( accept ) : def parse_media_range ( accept_item ) : return accept_item . split ( '/' , 1 ) def comparator ( a , b ) : result = - cmp ( a [ 2 ] , b [ 2 ] ) if result is not 0 : return result mtype_a , subtype_a = parse_media_range ( a [ 0 ] ) mtype_b , subtype_b = parse_media_range ( b [ 0 ] ) i... | Parse the Accept header |
57,275 | def in_session ( self ) : session = self . get_session ( ) try : yield session session . commit ( ) except IntegrityError : session . rollback ( ) raise DuplicateError ( "Duplicate unique value detected!" ) except ( OperationalError , DisconnectionError ) : session . rollback ( ) self . close ( ) logger . warn ( "Datab... | Provide a session scope around a series of operations . |
57,276 | def info ( self , req ) -> ResponseInfo : r = ResponseInfo ( ) r . version = "1.0" r . last_block_height = 0 r . last_block_app_hash = b'' return r | Since this will always respond with height = 0 Tendermint will resync this app from the begining |
57,277 | def check_tx ( self , tx ) -> ResponseCheckTx : value = decode_number ( tx ) if not value == ( self . txCount + 1 ) : return ResponseCheckTx ( code = 1 ) return ResponseCheckTx ( code = CodeTypeOk ) | Validate the Tx before entry into the mempool Checks the txs are submitted in order 1 2 3 ... If not an order a non - zero code is returned and the tx will be dropped . |
57,278 | def query ( self , req ) -> ResponseQuery : v = encode_number ( self . txCount ) return ResponseQuery ( code = CodeTypeOk , value = v , height = self . last_block_height ) | Return the last tx count |
57,279 | def commit ( self ) -> ResponseCommit : hash = struct . pack ( '>Q' , self . txCount ) return ResponseCommit ( data = hash ) | Return the current encode state value to tendermint |
57,280 | def track ( context , file_names ) : context . obj . find_repo_type ( ) for fn in file_names : context . obj . call ( [ context . obj . vc_name , 'add' , fn ] ) | Keep track of each file in list file_names . |
57,281 | def untrack ( context , file_names ) : context . obj . find_repo_type ( ) for fn in file_names : if context . obj . vc_name == 'git' : context . obj . call ( [ 'git' , 'rm' , '--cached' , fn ] ) elif context . obj . vc_name == 'hg' : context . obj . call ( [ 'hg' , 'forget' , fn ] ) | Forget about tracking each file in the list file_names |
57,282 | def commit ( context , message , name ) : context . obj . find_repo_type ( ) if context . obj . vc_name == 'git' : context . obj . call ( [ 'git' , 'commit' , '-a' , '-m' , message ] ) elif context . obj . vc_name == 'hg' : context . obj . call ( [ 'hg' , 'commit' , '-m' , message ] ) if name != '' and context . obj . ... | Commit saved changes to the repository . message - commit message name - tag name |
57,283 | def revert ( context , file_names ) : context . obj . find_repo_type ( ) if len ( file_names ) == 0 : click . echo ( 'No file names to checkout specified.' ) click . echo ( 'The following have changed since the last check in.' ) context . invoke ( status ) for fn in file_names : if context . obj . vc_name == 'git' : co... | Revert each file in the list file_names back to version in repo |
57,284 | def status ( context ) : context . obj . find_repo_type ( ) context . obj . call ( [ context . obj . vc_name , 'status' ] ) | See which files have changed checked in and uploaded |
57,285 | def diff ( context , file_name ) : context . obj . find_repo_type ( ) if context . obj . vc_name == 'git' : context . obj . call ( [ 'git' , 'diff' , '--color-words' , '--ignore-space-change' , file_name ] ) elif context . obj . vc_name == 'hg' : context . obj . call ( [ 'hg' , 'diff' , file_name ] ) | See changes that occured since last check in |
57,286 | def find_repo_type ( self ) : is_git = self . call ( [ 'git' , 'rev-parse' , '--is-inside-work-tree' ] , devnull = True ) if is_git != 0 : if self . debug : click . echo ( 'not git' ) is_hg = self . call ( [ 'hg' , '-q' , 'stat' ] , devnull = True ) if is_hg != 0 : if self . debug : click . echo ( 'not hg' ) exit ( 1 )... | Check for git or hg repository |
57,287 | def main ( ) : argp = _cli_argument_parser ( ) args = argp . parse_args ( ) logging . basicConfig ( level = args . loglevel , format = "%(levelname)s %(message)s" ) console . display ( "Collecting documentation from files" ) collector_metrics = metrics . Metrics ( ) docs = collector . parse ( args . path , args . trace... | The main entry point of the program |
57,288 | def process_ioc ( args ) : client = IndicatorClient . from_config ( ) client . set_debug ( True ) if args . get : response = client . get_indicators ( ) elif args . single : response = client . add_indicators ( indicators = [ args . single ] , private = args . private , tags = args . tags ) else : if not os . path . is... | Process actions related to the IOC switch . |
57,289 | def process_events ( args ) : client = EventsClient . from_config ( ) client . set_debug ( True ) if args . get : response = client . get_events ( ) elif args . flush : response = client . flush_events ( ) return response | Process actions related to events switch . |
57,290 | def main ( ) : parser = ArgumentParser ( description = "Blockade Analyst Bench" ) subs = parser . add_subparsers ( dest = 'cmd' ) ioc = subs . add_parser ( 'ioc' , help = "Perform actions with IOCs" ) ioc . add_argument ( '--single' , '-s' , help = "Send a single IOC" ) ioc . add_argument ( '--file' , '-f' , help = "Pa... | Run the code . |
57,291 | def window ( iterable , size = 2 ) : iterable = iter ( iterable ) d = deque ( islice ( iterable , size - 1 ) , maxlen = size ) for _ in map ( d . append , iterable ) : yield tuple ( d ) | yields wondows of a given size |
57,292 | def payment_mode ( self , payment_mode ) : allowed_values = [ "authorize" , "capture" ] if payment_mode is not None and payment_mode not in allowed_values : raise ValueError ( "Invalid value for `payment_mode` ({0}), must be one of {1}" . format ( payment_mode , allowed_values ) ) self . _payment_mode = payment_mode | Sets the payment_mode of this CreditCardPayment . |
57,293 | def match_via_correlation_coefficient ( image , template , raw_tolerance = 1 , normed_tolerance = 0.9 ) : h , w = image . shape th , tw = template . shape temp_mean = np . mean ( template ) temp_minus_mean = template - temp_mean convolution = fftconvolve ( image , temp_minus_mean [ : : - 1 , : : - 1 ] ) convolution = c... | Matching algorithm based on 2 - dimensional version of Pearson product - moment correlation coefficient . |
57,294 | def match_positions ( shape , list_of_coords ) : match_array = np . zeros ( shape ) try : match_array [ list_of_coords [ : , 0 ] , list_of_coords [ : , 1 ] ] = 1 labelled = label ( match_array ) objects = find_objects ( labelled [ 0 ] ) coords = [ { 'x' : ( slice_x . start , slice_x . stop ) , 'y' : ( slice_y . start ,... | In cases where we have multiple matches each highlighted by a region of coordinates we need to separate matches and find mean of each to return as match position |
57,295 | def is_empty ( self ) : return ( self . is_valid ( ) and not self . simple_lookups and not self . complex_conditions and not self . extra_conditions ) | Return True if form is valid and contains an empty lookup . |
57,296 | def load_inventory ( hosts_file = HOSTS_FILE ) : inventory = SafeConfigParser ( allow_no_value = True ) if os . path . exists ( hosts_file ) : inventory . read ( hosts_file ) else : logger . warn ( 'inventory file doesn\'t exist: %s' , hosts_file ) return inventory | Loads Ansible inventory from file . |
57,297 | def save_inventory ( inventory , hosts_file = HOSTS_FILE ) : with open ( hosts_file , 'w' ) as f : inventory . write ( f ) | Saves Ansible inventory to file . |
57,298 | def _init_config ( self , width , height , spi = None , spiMosi = None , spiDC = None , spiCS = None , spiReset = None , spiClk = None ) : self . _spi = spi self . _spi_mosi = spiMosi self . _spi_dc = spiDC self . _spi_cs = spiCS self . _spi_reset = spiReset self . _spi_clk = spiClk self . width = width self . height =... | ! SPI hardware and display width height initialization . |
57,299 | def _init_io ( self ) : GPIO . setwarnings ( False ) GPIO . setmode ( GPIO . BCM ) pins = [ self . _spi_dc ] for pin in pins : GPIO . setup ( pin , GPIO . OUT ) | ! GPIO initialization . Set GPIO into BCM mode and init other IOs mode |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.