idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
10,900 | def adjustSize ( self ) : cell = self . scene ( ) . cellWidth ( ) * 2 minheight = cell minwidth = 2 * cell # fit to the grid size metrics = QFontMetrics ( QApplication . font ( ) ) width = metrics . width ( self . displayName ( ) ) + 20 width = ( ( width / cell ) * cell ) + ( cell % width ) height = self . rect ( ) . height ( ) # adjust for the icon icon = self . icon ( ) if icon and not icon . isNull ( ) : width += self . iconSize ( ) . width ( ) + 2 height = max ( height , self . iconSize ( ) . height ( ) + 2 ) w = max ( width , minwidth ) h = max ( height , minheight ) max_w = self . maximumWidth ( ) max_h = self . maximumHeight ( ) if max_w is not None : w = min ( w , max_w ) if max_h is not None : h = min ( h , max_h ) self . setMinimumWidth ( w ) self . setMinimumHeight ( h ) self . rebuild ( ) | Adjusts the size of this node to support the length of its contents . | 245 | 15 |
10,901 | def isEnabled ( self ) : if ( self . _disableWithLayer and self . _layer ) : lenabled = self . _layer . isEnabled ( ) else : lenabled = True return self . _enabled and lenabled | Returns whether or not this node is enabled . | 46 | 9 |
10,902 | def popitem ( self ) : try : item = dict . popitem ( self ) return ( item [ 0 ] , item [ 1 ] [ 0 ] ) except KeyError , e : raise BadRequestKeyError ( str ( e ) ) | Pop an item from the dict . | 50 | 7 |
10,903 | def emitCurrentRecordChanged ( self ) : record = unwrapVariant ( self . itemData ( self . currentIndex ( ) , Qt . UserRole ) ) if not Table . recordcheck ( record ) : record = None self . _currentRecord = record if not self . signalsBlocked ( ) : self . _changedRecord = record self . currentRecordChanged . emit ( record ) | Emits the current record changed signal for this combobox provided \ the signals aren t blocked . | 81 | 20 |
10,904 | def emitCurrentRecordEdited ( self ) : if self . _changedRecord == - 1 : return if self . signalsBlocked ( ) : return record = self . _changedRecord self . _changedRecord = - 1 self . currentRecordEdited . emit ( record ) | Emits the current record edited signal for this combobox provided the signals aren t blocked and the record has changed since the last time . | 55 | 28 |
10,905 | def focusInEvent ( self , event ) : self . _changedRecord = - 1 super ( XOrbRecordBox , self ) . focusInEvent ( event ) | When this widget loses focus try to emit the record changed event signal . | 35 | 14 |
10,906 | def hidePopup ( self ) : if self . _treePopupWidget and self . showTreePopup ( ) : self . _treePopupWidget . close ( ) super ( XOrbRecordBox , self ) . hidePopup ( ) | Overloads the hide popup method to handle when the user hides the popup widget . | 53 | 16 |
10,907 | def markLoadingStarted ( self ) : if self . isThreadEnabled ( ) : XLoaderWidget . start ( self ) if self . showTreePopup ( ) : tree = self . treePopupWidget ( ) tree . setCursor ( Qt . WaitCursor ) tree . clear ( ) tree . setUpdatesEnabled ( False ) tree . blockSignals ( True ) self . _baseHints = ( self . hint ( ) , tree . hint ( ) ) tree . setHint ( 'Loading records...' ) self . setHint ( 'Loading records...' ) else : self . _baseHints = ( self . hint ( ) , '' ) self . setHint ( 'Loading records...' ) self . setCursor ( Qt . WaitCursor ) self . blockSignals ( True ) self . setUpdatesEnabled ( False ) # prepare to load self . clear ( ) use_dummy = not self . isRequired ( ) or self . isCheckable ( ) if use_dummy : self . addItem ( '' ) self . loadingStarted . emit ( ) | Marks this widget as loading records . | 234 | 8 |
10,908 | def markLoadingFinished ( self ) : XLoaderWidget . stop ( self , force = True ) hint , tree_hint = self . _baseHints self . setHint ( hint ) # set the tree widget if self . showTreePopup ( ) : tree = self . treePopupWidget ( ) tree . setHint ( tree_hint ) tree . unsetCursor ( ) tree . setUpdatesEnabled ( True ) tree . blockSignals ( False ) self . unsetCursor ( ) self . blockSignals ( False ) self . setUpdatesEnabled ( True ) self . loadingFinished . emit ( ) | Marks this widget as finished loading records . | 137 | 9 |
10,909 | def destroy ( self ) : try : tree = self . treeWidget ( ) tree . destroyed . disconnect ( self . destroy ) except StandardError : pass for movie in set ( self . _movies . values ( ) ) : try : movie . frameChanged . disconnect ( self . _updateFrame ) except StandardError : pass | Destroyes this item by disconnecting any signals that may exist . This is called when the tree clears itself or is deleted . If you are manually removing an item you should call the destroy method yourself . This is required since Python allows for non - QObject connections and since QTreeWidgetItem s are not QObjects they do not properly handle being destroyed with connections on them . | 67 | 76 |
10,910 | def ensureVisible ( self ) : parent = self . parent ( ) while parent : parent . setExpanded ( True ) parent = parent . parent ( ) | Expands all the parents of this item to ensure that it is visible to the user . | 33 | 18 |
10,911 | def initGroupStyle ( self , useIcons = True , columnCount = None ) : flags = self . flags ( ) if flags & QtCore . Qt . ItemIsSelectable : flags ^= QtCore . Qt . ItemIsSelectable self . setFlags ( flags ) if useIcons : ico = QtGui . QIcon ( resources . find ( 'img/treeview/triangle_right.png' ) ) expand_ico = QtGui . QIcon ( resources . find ( 'img/treeview/triangle_down.png' ) ) self . setIcon ( 0 , ico ) self . setExpandedIcon ( 0 , expand_ico ) palette = QtGui . QApplication . palette ( ) line_clr = palette . color ( palette . Mid ) base_clr = palette . color ( palette . Button ) text_clr = palette . color ( palette . ButtonText ) gradient = QtGui . QLinearGradient ( ) gradient . setColorAt ( 0.00 , line_clr ) gradient . setColorAt ( 0.03 , line_clr ) gradient . setColorAt ( 0.04 , base_clr . lighter ( 105 ) ) gradient . setColorAt ( 0.25 , base_clr ) gradient . setColorAt ( 0.96 , base_clr . darker ( 105 ) ) gradient . setColorAt ( 0.97 , line_clr ) gradient . setColorAt ( 1.00 , line_clr ) h = self . _fixedHeight if not h : h = self . sizeHint ( 0 ) . height ( ) if not h : h = 18 gradient . setStart ( 0.0 , 0.0 ) gradient . setFinalStop ( 0.0 , h ) brush = QtGui . QBrush ( gradient ) tree = self . treeWidget ( ) columnCount = columnCount or ( tree . columnCount ( ) if tree else self . columnCount ( ) ) for i in range ( columnCount ) : self . setForeground ( i , text_clr ) self . setBackground ( i , brush ) | Initialzes this item with a grouping style option . | 456 | 10 |
10,912 | def takeFromTree ( self ) : tree = self . treeWidget ( ) parent = self . parent ( ) if parent : parent . takeChild ( parent . indexOfChild ( self ) ) else : tree . takeTopLevelItem ( tree . indexOfTopLevelItem ( self ) ) | Takes this item from the tree . | 60 | 8 |
10,913 | def find ( self , * args , * * kwargs ) : # print(f"database.collection: '{self.database.name}.{self.collection.name}'") self . print_cursor ( self . collection . find ( * args , * * kwargs ) ) | Run the pymongo find command against the default database and collection and paginate the output to the screen . | 64 | 22 |
10,914 | def find_one ( self , * args , * * kwargs ) : # print(f"database.collection: '{self.database.name}.{self.collection.name}'") self . print_doc ( self . collection . find_one ( * args , * * kwargs ) ) | Run the pymongo find_one command against the default database and collection and paginate the output to the screen . | 67 | 24 |
10,915 | def insert_one ( self , * args , * * kwargs ) : # print(f"database.collection: '{self.database.name}.{self.collection.name}'") result = self . collection . insert_one ( * args , * * kwargs ) return result . inserted_id | Run the pymongo insert_one command against the default database and collection and returne the inserted ID . | 68 | 22 |
10,916 | def insert_many ( self , * args , * * kwargs ) : # print(f"database.collection: '{self.database.name}.{self.collection.name}'") result = self . collection . insert_many ( * args , * * kwargs ) return result . inserted_ids | Run the pymongo insert_many command against the default database and collection and return the list of inserted IDs . | 68 | 23 |
10,917 | def delete_one ( self , * args , * * kwargs ) : result = self . collection . delete_one ( * args , * * kwargs ) return result . raw_result | Run the pymongo delete_one command against the default database and collection and return the deleted IDs . | 42 | 21 |
10,918 | def delete_many ( self , * args , * * kwargs ) : result = self . collection . delete_many ( * args , * * kwargs ) return result . raw_result | Run the pymongo delete_many command against the default database and collection and return the deleted IDs . | 42 | 21 |
10,919 | def count_documents ( self , filter = { } , * args , * * kwargs ) : result = self . collection . count_documents ( filter , * args , * * kwargs ) return result | Count all the documents in a collection accurately | 47 | 8 |
10,920 | def _get_collections ( self , db_names = None ) : if db_names : db_list = db_names else : db_list = self . client . list_database_names ( ) for db_name in db_list : db = self . client . get_database ( db_name ) for col_name in db . list_collection_names ( ) : size = db [ col_name ] . g yield f"{db_name}.{col_name}" | Internal function to return all the collections for every database . include a list of db_names to filter the list of collections . | 106 | 25 |
10,921 | def pager ( self , lines ) : try : line_count = 0 if self . _output_filename : print ( f"Output is also going to '{self.output_file}'" ) self . _output_file = open ( self . _output_filename , "a+" ) terminal_columns , terminal_lines = shutil . get_terminal_size ( fallback = ( 80 , 24 ) ) lines_left = terminal_lines for i , l in enumerate ( lines , 1 ) : line_residue = 0 if self . line_numbers : output_line = f"{i:<4} {l}" else : output_line = l line_overflow = int ( len ( output_line ) / terminal_columns ) if line_overflow : line_residue = len ( output_line ) % terminal_columns if line_overflow >= 1 : lines_left = lines_left - line_overflow else : lines_left = lines_left - 1 if line_residue > 1 : lines_left = lines_left - 1 # line_count = line_count + 1 print ( output_line ) if self . _output_file : self . _output_file . write ( f"{l}\n" ) self . _output_file . flush ( ) #print(lines_left) if ( lines_left - self . overlap - 1 ) <= 0 : # -1 to leave room for prompt if self . paginate : print ( "Hit Return to continue (q or quit to exit)" , end = "" ) user_input = input ( ) if user_input . lower ( ) . strip ( ) in [ "q" , "quit" , "exit" ] : break terminal_columns , terminal_lines = shutil . get_terminal_size ( fallback = ( 80 , 24 ) ) lines_left = terminal_lines # end for if self . _output_file : self . _output_file . close ( ) except KeyboardInterrupt : print ( "ctrl-C..." ) if self . _output_file : self . _output_file . close ( ) | Outputs lines to a terminal . It uses shutil . get_terminal_size to determine the height of the terminal . It expects an iterator that returns a line at a time and those lines should be terminated by a valid newline sequence . | 468 | 50 |
10,922 | def groupQuery ( self ) : items = self . uiQueryTREE . selectedItems ( ) if ( not len ( items ) > 2 ) : return if ( isinstance ( items [ - 1 ] , XJoinItem ) ) : items = items [ : - 1 ] tree = self . uiQueryTREE parent = items [ 0 ] . parent ( ) if ( not parent ) : parent = tree preceeding = items [ - 1 ] tree . blockSignals ( True ) tree . setUpdatesEnabled ( False ) grp_item = XQueryItem ( parent , Q ( ) , preceeding = preceeding ) for item in items : parent = item . parent ( ) if ( not parent ) : tree . takeTopLevelItem ( tree . indexOfTopLevelItem ( item ) ) else : parent . takeChild ( parent . indexOfChild ( item ) ) grp_item . addChild ( item ) grp_item . update ( ) tree . blockSignals ( False ) tree . setUpdatesEnabled ( True ) | Groups the selected items together into a sub query | 222 | 10 |
10,923 | def removeQuery ( self ) : items = self . uiQueryTREE . selectedItems ( ) tree = self . uiQueryTREE for item in items : parent = item . parent ( ) if ( parent ) : parent . takeChild ( parent . indexOfChild ( item ) ) else : tree . takeTopLevelItem ( tree . indexOfTopLevelItem ( item ) ) self . setQuery ( self . query ( ) ) | Removes the currently selected query . | 92 | 7 |
10,924 | def runWizard ( self ) : plugin = self . currentPlugin ( ) if ( plugin and plugin . runWizard ( self ) ) : self . accept ( ) | Runs the current wizard . | 35 | 6 |
10,925 | def showDescription ( self ) : plugin = self . currentPlugin ( ) if ( not plugin ) : self . uiDescriptionTXT . setText ( '' ) else : self . uiDescriptionTXT . setText ( plugin . description ( ) ) | Shows the description for the current plugin in the interface . | 53 | 12 |
10,926 | def showWizards ( self ) : self . uiWizardTABLE . clear ( ) item = self . uiPluginTREE . currentItem ( ) if ( not ( item and item . parent ( ) ) ) : plugins = [ ] else : wlang = nativestring ( item . parent ( ) . text ( 0 ) ) wgrp = nativestring ( item . text ( 0 ) ) plugins = self . plugins ( wlang , wgrp ) if ( not plugins ) : self . uiWizardTABLE . setEnabled ( False ) self . uiDescriptionTXT . setEnabled ( False ) return self . uiWizardTABLE . setEnabled ( True ) self . uiDescriptionTXT . setEnabled ( True ) # determine the number of columns colcount = len ( plugins ) / 2 if ( len ( plugins ) % 2 ) : colcount += 1 self . uiWizardTABLE . setRowCount ( 2 ) self . uiWizardTABLE . setColumnCount ( colcount ) header = self . uiWizardTABLE . verticalHeader ( ) header . setResizeMode ( 0 , header . Stretch ) header . setResizeMode ( 1 , header . Stretch ) header . setMinimumSectionSize ( 64 ) header . hide ( ) header = self . uiWizardTABLE . horizontalHeader ( ) header . setMinimumSectionSize ( 64 ) header . hide ( ) col = - 1 row = 1 for plugin in plugins : if ( row ) : col += 1 row = int ( not row ) widget = PluginWidget ( self , plugin ) self . uiWizardTABLE . setItem ( row , col , QTableWidgetItem ( ) ) self . uiWizardTABLE . setCellWidget ( row , col , widget ) | Show the wizards widget for the currently selected plugin . | 376 | 10 |
10,927 | def registerToDataTypes ( cls ) : from projexui . xdatatype import registerDataType registerDataType ( cls . __name__ , lambda pyvalue : pyvalue . toString ( ) , lambda qvariant : cls . fromString ( unwrapVariant ( qvariant ) ) ) | Registers this class as a valid datatype for saving and loading via the datatype system . | 69 | 21 |
10,928 | def enterEvent ( self , event ) : super ( XViewPanelItem , self ) . enterEvent ( event ) # store the hover state and mark for a repaint self . _hovered = True self . update ( ) | Mark the hovered state as being true . | 47 | 9 |
10,929 | def leaveEvent ( self , event ) : super ( XViewPanelItem , self ) . leaveEvent ( event ) # store the hover state and mark for a repaint self . _hovered = False self . update ( ) | Mark the hovered state as being false . | 47 | 9 |
10,930 | def mousePressEvent ( self , event ) : self . _moveItemStarted = False rect = QtCore . QRect ( 0 , 0 , 12 , self . height ( ) ) # drag the tab off if not self . _locked and rect . contains ( event . pos ( ) ) : tabbar = self . parent ( ) panel = tabbar . parent ( ) index = tabbar . indexOf ( self ) view = panel . widget ( index ) pixmap = QtGui . QPixmap . grabWidget ( view ) drag = QtGui . QDrag ( panel ) data = QtCore . QMimeData ( ) data . setData ( 'x-application/xview/tabbed_view' , QtCore . QByteArray ( str ( index ) ) ) drag . setMimeData ( data ) drag . setPixmap ( pixmap ) if not drag . exec_ ( ) : cursor = QtGui . QCursor . pos ( ) geom = self . window ( ) . geometry ( ) if not geom . contains ( cursor ) : view . popout ( ) # allow moving indexes around elif not self . _locked and self . isActive ( ) : self . _moveItemStarted = self . parent ( ) . count ( ) > 1 else : self . activate ( ) super ( XViewPanelItem , self ) . mousePressEvent ( event ) | Creates the mouse event for dragging or activating this tab . | 299 | 12 |
10,931 | def setFixedHeight ( self , height ) : super ( XViewPanelItem , self ) . setFixedHeight ( height ) self . _dragLabel . setFixedHeight ( height ) self . _titleLabel . setFixedHeight ( height ) self . _searchButton . setFixedHeight ( height ) self . _closeButton . setFixedHeight ( height ) | Sets the fixed height for this item to the inputed height amount . | 75 | 15 |
10,932 | def clear ( self ) : self . blockSignals ( True ) items = list ( self . items ( ) ) for item in items : item . close ( ) self . blockSignals ( False ) self . _currentIndex = - 1 self . currentIndexChanged . emit ( self . _currentIndex ) | Clears out all the items from this tab bar . | 64 | 11 |
10,933 | def closeTab ( self , item ) : index = self . indexOf ( item ) if index != - 1 : self . tabCloseRequested . emit ( index ) | Requests a close for the inputed tab item . | 35 | 11 |
10,934 | def items ( self ) : output = [ ] for i in xrange ( self . layout ( ) . count ( ) ) : item = self . layout ( ) . itemAt ( i ) try : widget = item . widget ( ) except AttributeError : break if isinstance ( widget , XViewPanelItem ) : output . append ( widget ) else : break return output | Returns a list of all the items associated with this panel . | 78 | 12 |
10,935 | def moveTab ( self , fromIndex , toIndex ) : try : item = self . layout ( ) . itemAt ( fromIndex ) self . layout ( ) . insertItem ( toIndex , item . widget ( ) ) except StandardError : pass | Moves the tab from the inputed index to the given index . | 52 | 14 |
10,936 | def removeTab ( self , index ) : curr_index = self . currentIndex ( ) items = list ( self . items ( ) ) item = items [ index ] item . close ( ) if index <= curr_index : self . _currentIndex -= 1 | Removes the tab at the inputed index . | 56 | 10 |
10,937 | def requestAddMenu ( self ) : point = QtCore . QPoint ( self . _addButton . width ( ) , 0 ) point = self . _addButton . mapToGlobal ( point ) self . addRequested . emit ( point ) | Emits the add requested signal . | 52 | 7 |
10,938 | def requestOptionsMenu ( self ) : point = QtCore . QPoint ( 0 , self . _optionsButton . height ( ) ) point = self . _optionsButton . mapToGlobal ( point ) self . optionsRequested . emit ( point ) | Emits the options request signal . | 52 | 7 |
10,939 | def setCurrentIndex ( self , index ) : if self . _currentIndex == index : return self . _currentIndex = index self . currentIndexChanged . emit ( index ) for i , item in enumerate ( self . items ( ) ) : item . setMenuEnabled ( i == index ) self . repaint ( ) | Sets the current item to the item at the inputed index . | 68 | 14 |
10,940 | def setFixedHeight ( self , height ) : super ( XViewPanelBar , self ) . setFixedHeight ( height ) # update the layout if self . layout ( ) : for i in xrange ( self . layout ( ) . count ( ) ) : try : self . layout ( ) . itemAt ( i ) . widget ( ) . setFixedHeight ( height ) except StandardError : continue | Sets the fixed height for this bar to the inputed height . | 83 | 14 |
10,941 | def setTabText ( self , index , text ) : try : self . items ( ) [ index ] . setText ( text ) except IndexError : pass | Returns the text for the tab at the inputed index . | 33 | 12 |
10,942 | def closePanel ( self ) : # make sure we can close all the widgets in the view first for i in range ( self . count ( ) ) : if not self . widget ( i ) . canClose ( ) : return False container = self . parentWidget ( ) viewWidget = self . viewWidget ( ) # close all the child views for i in xrange ( self . count ( ) - 1 , - 1 , - 1 ) : self . widget ( i ) . close ( ) self . tabBar ( ) . clear ( ) if isinstance ( container , XSplitter ) : parent_container = container . parentWidget ( ) if container . count ( ) == 2 : if isinstance ( parent_container , XSplitter ) : sizes = parent_container . sizes ( ) widget = container . widget ( int ( not container . indexOf ( self ) ) ) index = parent_container . indexOf ( container ) parent_container . insertWidget ( index , widget ) container . setParent ( None ) container . close ( ) container . deleteLater ( ) parent_container . setSizes ( sizes ) elif parent_container . parentWidget ( ) == viewWidget : widget = container . widget ( int ( not container . indexOf ( self ) ) ) widget . setParent ( viewWidget ) if projexui . QT_WRAPPER == 'PySide' : _ = viewWidget . takeWidget ( ) else : old_widget = viewWidget . widget ( ) old_widget . setParent ( None ) old_widget . close ( ) old_widget . deleteLater ( ) QtGui . QApplication . instance ( ) . processEvents ( ) viewWidget . setWidget ( widget ) else : container . setParent ( None ) container . close ( ) container . deleteLater ( ) else : self . setFocus ( ) self . _hintLabel . setText ( self . hint ( ) ) self . _hintLabel . show ( ) return True | Closes a full view panel . | 414 | 7 |
10,943 | def ensureVisible ( self , viewType ) : # make sure we're not trying to switch to the same type view = self . currentView ( ) if type ( view ) == viewType : return view self . blockSignals ( True ) self . setUpdatesEnabled ( False ) for i in xrange ( self . count ( ) ) : widget = self . widget ( i ) if type ( widget ) == viewType : self . setCurrentIndex ( i ) view = widget break else : view = self . addView ( viewType ) self . blockSignals ( False ) self . setUpdatesEnabled ( True ) return view | Find and switch to the first tab of the specified view type . If the type does not exist add it . | 133 | 22 |
10,944 | def insertTab ( self , index , widget , title ) : self . insertWidget ( index , widget ) tab = self . tabBar ( ) . insertTab ( index , title ) tab . titleChanged . connect ( widget . setWindowTitle ) | Inserts a new tab for this widget . | 51 | 9 |
10,945 | def markCurrentChanged ( self ) : view = self . currentView ( ) if view : view . setCurrent ( ) self . setFocus ( ) view . setFocus ( ) self . _hintLabel . hide ( ) else : self . _hintLabel . show ( ) self . _hintLabel . setText ( self . hint ( ) ) if not self . count ( ) : self . tabBar ( ) . clear ( ) self . adjustSizeConstraint ( ) | Marks that the current widget has changed . | 102 | 9 |
10,946 | def refreshTitles ( self ) : for index in range ( self . count ( ) ) : widget = self . widget ( index ) self . setTabText ( index , widget . windowTitle ( ) ) | Refreshes the titles for each view within this tab panel . | 43 | 13 |
10,947 | def setCurrentIndex ( self , index ) : super ( XViewPanel , self ) . setCurrentIndex ( index ) self . tabBar ( ) . setCurrentIndex ( index ) | Sets the current index on self and on the tab bar to keep the two insync . | 38 | 19 |
10,948 | def switchCurrentView ( self , viewType ) : if not self . count ( ) : return self . addView ( viewType ) # make sure we're not trying to switch to the same type view = self . currentView ( ) if type ( view ) == viewType : return view # create a new view and close the old one self . blockSignals ( True ) self . setUpdatesEnabled ( False ) # create the new view index = self . indexOf ( view ) if not view . close ( ) : return None #else: # self.tabBar().removeTab(index) index = self . currentIndex ( ) new_view = viewType . createInstance ( self . viewWidget ( ) , self . viewWidget ( ) ) # add the new view self . insertTab ( index , new_view , new_view . windowTitle ( ) ) self . blockSignals ( False ) self . setUpdatesEnabled ( True ) self . setCurrentIndex ( index ) return new_view | Swaps the current tab view for the inputed action s type . | 211 | 14 |
10,949 | async def keys ( self , prefix , * , dc = None , separator = None , watch = None , consistency = None ) : response = await self . _read ( prefix , dc = dc , separator = separator , keys = True , watch = watch , consistency = consistency ) return consul ( response ) | Returns a list of the keys under the given prefix | 67 | 10 |
10,950 | async def get_tree ( self , prefix , * , dc = None , separator = None , watch = None , consistency = None ) : response = await self . _read ( prefix , dc = dc , recurse = True , separator = separator , watch = watch , consistency = consistency ) result = response . body for data in result : data [ "Value" ] = decode_value ( data [ "Value" ] , data [ "Flags" ] ) return consul ( result , meta = extract_meta ( response . headers ) ) | Gets all keys with a prefix of Key during the transaction . | 116 | 13 |
10,951 | async def cas ( self , key , value , * , flags = None , index ) : value = encode_value ( value , flags ) index = extract_attr ( index , keys = [ "ModifyIndex" , "Index" ] ) response = await self . _write ( key , value , flags = flags , cas = index ) return response . body is True | Sets the key to the given value with check - and - set semantics . | 78 | 16 |
10,952 | async def lock ( self , key , value , * , flags = None , session ) : value = encode_value ( value , flags ) session_id = extract_attr ( session , keys = [ "ID" ] ) response = await self . _write ( key , value , flags = flags , acquire = session_id ) return response . body is True | Locks the Key with the given Session . | 76 | 9 |
10,953 | async def unlock ( self , key , value , * , flags = None , session ) : value = encode_value ( value , flags ) session_id = extract_attr ( session , keys = [ "ID" ] ) response = await self . _write ( key , value , flags = flags , release = session_id ) return response . body is True | Unlocks the Key with the given Session . | 76 | 9 |
10,954 | async def delete_tree ( self , prefix , * , separator = None ) : response = await self . _discard ( prefix , recurse = True , separator = separator ) return response . body is True | Deletes all keys with a prefix of Key . | 47 | 10 |
10,955 | def set ( self , key , value , * , flags = None ) : self . append ( { "Verb" : "set" , "Key" : key , "Value" : encode_value ( value , flags , base64 = True ) . decode ( "utf-8" ) , "Flags" : flags } ) return self | Sets the Key to the given Value | 72 | 8 |
10,956 | def cas ( self , key , value , * , flags = None , index ) : self . append ( { "Verb" : "cas" , "Key" : key , "Value" : encode_value ( value , flags , base64 = True ) . decode ( "utf-8" ) , "Flags" : flags , "Index" : extract_attr ( index , keys = [ "ModifyIndex" , "Index" ] ) } ) return self | Sets the Key to the given Value with check - and - set semantics | 99 | 15 |
10,957 | def lock ( self , key , value , * , flags = None , session ) : self . append ( { "Verb" : "lock" , "Key" : key , "Value" : encode_value ( value , flags , base64 = True ) . decode ( "utf-8" ) , "Flags" : flags , "Session" : extract_attr ( session , keys = [ "ID" ] ) } ) return self | Locks the Key with the given Session | 93 | 8 |
10,958 | def check_index ( self , key , * , index ) : self . append ( { "Verb" : "check-index" , "Key" : key , "Index" : extract_attr ( index , keys = [ "ModifyIndex" , "Index" ] ) } ) return self | Fails the transaction if Key does not have a modify index equal to Index | 64 | 15 |
10,959 | def check_session ( self , key , * , session = None ) : self . append ( { "Verb" : "check-session" , "Key" : key , "Session" : extract_attr ( session , keys = [ "ID" ] ) } ) return self | Fails the transaction if Key is not currently locked by Session | 60 | 12 |
10,960 | async def execute ( self , dc = None , token = None ) : token_id = extract_attr ( token , keys = [ "ID" ] ) try : response = await self . _api . put ( "/v1/txn" , data = self . operations , params = { "dc" : dc , "token" : token_id } ) except ConflictError as error : errors = { elt [ "OpIndex" ] : elt for elt in error . value [ "Errors" ] } operations = [ op [ "KV" ] for op in self . operations ] meta = error . meta raise TransactionError ( errors , operations , meta ) from error except Exception as error : raise error else : self . operations [ : ] = [ ] results = [ ] for _ in response . body [ "Results" ] : data = _ [ "KV" ] if data [ "Value" ] is not None : data [ "Value" ] = decode_value ( data [ "Value" ] , data [ "Flags" ] ) results . append ( data ) return results | Execute stored operations | 233 | 4 |
10,961 | def write ( self , script ) : # type: (str) -> None if self . _closed : raise IOError ( 'tried to write to closed connection' ) script = script . strip ( ) if script : assert self . _parentout is not None self . _parentout . write ( script ) self . _parentout . write ( '\n' ) | Send a script to FORM . | 78 | 6 |
10,962 | def flush ( self ) : # type: () -> None if self . _closed : raise IOError ( 'tried to flush closed connection' ) assert self . _parentout is not None self . _parentout . flush ( ) | Flush the channel to FORM . | 49 | 7 |
10,963 | def compile ( self ) : sql = '' sql += 'DELETE FROM ' + self . dialect . quote_table ( self . _table ) if self . _where : sql += ' WHERE ' + self . compile_condition ( self . _where ) if self . _order_by : sql += ' ' + self . compile_order_by ( self . _order_by ) if self . _limit : sql += ' LIMIT ' + self . _limit return sql | Compiles the delete sql statement | 101 | 6 |
10,964 | def clear ( self ) : WhereQuery . clear ( self ) self . _table = None self . _parameters = [ ] self . _sql = None | Clear and reset to orignal state | 33 | 8 |
10,965 | def startLoading ( self ) : if self . _loading : return False tree = self . treeWidget ( ) if not tree : return self . _loading = True self . setText ( 0 , '' ) # create the label for this item lbl = QtGui . QLabel ( self . treeWidget ( ) ) lbl . setMovie ( XLoaderWidget . getMovie ( ) ) lbl . setAlignment ( QtCore . Qt . AlignCenter ) tree . setItemWidget ( self , 0 , lbl ) try : tree . loadStarted . emit ( self ) except AttributeError : pass return True | Updates this item to mark the item as loading . This will create a QLabel with the loading ajax spinner to indicate that progress is occurring . | 131 | 32 |
10,966 | def emitCurrentChanged ( self ) : if not self . signalsBlocked ( ) : self . currentIndexChanged . emit ( self . currentIndex ( ) ) self . currentUrlChanged . emit ( self . currentUrl ( ) ) self . canGoBackChanged . emit ( self . canGoBack ( ) ) self . canGoForwardChanged . emit ( self . canGoForward ( ) ) | Emits the current index changed signal provided signals are not blocked . | 82 | 13 |
10,967 | def goHome ( self ) : if not self . canGoBack ( ) : return '' if self . homeUrl ( ) : self . push ( self . homeUrl ( ) ) self . _blockStack = True self . _index = 0 self . emitCurrentChanged ( ) self . _blockStack = False return self . currentUrl ( ) | Goes to the home url . If there is no home url specifically set then \ this will go to the first url in the history . Otherwise it will \ look to see if the home url is in the stack and go to that level if \ the home url is not found then it will be pushed to the top of the \ stack using the push method . | 72 | 73 |
10,968 | def cli ( conf ) : config = init_config ( conf ) nas_id = config . get ( 'DEFAULT' , 'nas_id' ) nas_addr = config . get ( 'DEFAULT' , 'nas_addr' ) secret = config . get ( 'DEFAULT' , 'radius_secret' ) radius_addr = config . get ( 'DEFAULT' , 'radius_addr' ) radius_auth_port = config . getint ( 'DEFAULT' , 'radius_auth_port' ) radius_timeout = config . getint ( 'DEFAULT' , 'radius_timeout' ) client_config_dir = config . get ( 'DEFAULT' , 'client_config_dir' ) username = os . environ . get ( 'username' ) req = { 'User-Name' : username } req [ 'CHAP-Challenge' ] = get_challenge ( ) req [ 'CHAP-Password-Plaintext' ] = os . environ . get ( 'password' ) req [ "NAS-IP-Address" ] = nas_addr req [ "NAS-Port-Id" ] = '0/0/0:0.0' req [ "NAS-Port" ] = 0 req [ "Service-Type" ] = "Login-User" req [ "NAS-Identifier" ] = nas_id req [ "Called-Station-Id" ] = '00:00:00:00:00:00' req [ "Calling-Station-Id" ] = '00:00:00:00:00:00' # req["Framed-IP-Address"] = os.environ.get('ifconfig_pool_remote_ip') # log.msg("radius auth: %s" % repr(req)) def shutdown ( exitcode = 0 ) : reactor . addSystemEventTrigger ( 'after' , 'shutdown' , os . _exit , exitcode ) reactor . stop ( ) def onresp ( r ) : if r . code == packet . AccessAccept : try : ccdattrs = [ ] userip = get_radius_addr_attr ( r , 8 ) if userip : ccdattrs . append ( 'ifconfig-push {0} 255.255.255.0' . format ( userip ) ) with open ( os . path . join ( client_config_dir , username ) , 'wb' ) as ccdfs : ccdfs . write ( '\n' . join ( ccdattrs ) ) except : traceback . print_exc ( ) shutdown ( 0 ) else : shutdown ( 1 ) def onerr ( e ) : log . err ( e ) shutdown ( 1 ) d = client . send_auth ( str ( secret ) , get_dictionary ( ) , radius_addr , authport = radius_auth_port , debug = True , * * req ) d . addCallbacks ( onresp , onerr ) reactor . callLater ( radius_timeout , shutdown , 1 ) reactor . run ( ) | OpenVPN user_pass_verify method | 654 | 9 |
10,969 | async def create ( self , session , * , dc = None ) : response = await self . _api . put ( "/v1/session/create" , data = session , params = { "dc" : dc } ) return response . body | Creates a new session | 53 | 5 |
10,970 | async def destroy ( self , session , * , dc = None ) : session_id = extract_attr ( session , keys = [ "ID" ] ) response = await self . _api . put ( "/v1/session/destroy" , session_id , params = { "dc" : dc } ) return response . body is True | Destroys a given session | 73 | 6 |
10,971 | async def info ( self , session , * , dc = None , watch = None , consistency = None ) : session_id = extract_attr ( session , keys = [ "ID" ] ) response = await self . _api . get ( "/v1/session/info" , session_id , watch = watch , consistency = consistency , params = { "dc" : dc } ) try : result = response . body [ 0 ] except IndexError : meta = extract_meta ( response . headers ) raise NotFound ( "No session for %r" % session_id , meta = meta ) return consul ( result , meta = extract_meta ( response . headers ) ) | Queries a given session | 144 | 5 |
10,972 | async def renew ( self , session , * , dc = None ) : session_id = extract_attr ( session , keys = [ "ID" ] ) response = await self . _api . put ( "/v1/session/renew" , session_id , params = { "dc" : dc } ) try : result = response . body [ 0 ] except IndexError : meta = extract_meta ( response . headers ) raise NotFound ( "No session for %r" % session_id , meta = meta ) return consul ( result , meta = extract_meta ( response . headers ) ) | Renews a TTL - based session | 129 | 7 |
10,973 | def _lazy_re_compile ( regex , flags = 0 ) : def _compile ( ) : # Compile the regex if it was not passed pre-compiled. if isinstance ( regex , str ) : return re . compile ( regex , flags ) else : assert not flags , "flags must be empty if regex is passed pre-compiled" return regex return SimpleLazyObject ( _compile ) | Lazily compile a regex with flags . | 89 | 9 |
10,974 | def deconstructible ( * args , path = None ) : def decorator ( klass ) : def __new__ ( cls , * args , * * kwargs ) : # We capture the arguments to make returning them trivial obj = super ( klass , cls ) . __new__ ( cls ) obj . _constructor_args = ( args , kwargs ) return obj klass . __new__ = staticmethod ( __new__ ) return klass if not args : return decorator return decorator ( * args ) | Class decorator that allows the decorated class to be serialized by the migrations subsystem . | 115 | 18 |
10,975 | def clear ( self ) : self . _searchEdit . blockSignals ( True ) self . _searchEdit . setText ( '' ) self . _searchEdit . blockSignals ( False ) | Clears the text from the search edit . | 41 | 9 |
10,976 | def clearAdvancedActions ( self ) : self . _advancedMap . clear ( ) margins = list ( self . getContentsMargins ( ) ) margins [ 2 ] = 0 self . setContentsMargins ( * margins ) | Clears out the advanced action map . | 48 | 8 |
10,977 | def rebuildButtons ( self ) : for btn in self . findChildren ( XAdvancedButton ) : btn . close ( ) btn . setParent ( None ) btn . deleteLater ( ) for standard , advanced in self . _advancedMap . items ( ) : rect = self . actionGeometry ( standard ) btn = XAdvancedButton ( self ) btn . setFixedWidth ( 22 ) btn . setFixedHeight ( rect . height ( ) ) btn . setDefaultAction ( advanced ) btn . setAutoRaise ( True ) btn . move ( rect . right ( ) + 1 , rect . top ( ) ) btn . show ( ) if btn . icon ( ) . isNull ( ) : btn . setIcon ( QIcon ( resources . find ( 'img/advanced.png' ) ) ) btn . clicked . connect ( self . acceptAdvanced ) | Rebuilds the buttons for the advanced actions . | 193 | 10 |
10,978 | def rebuild ( self ) : self . _buildData . clear ( ) self . _dateGrid . clear ( ) self . _dateTimeGrid . clear ( ) curr_min = self . _minimumDate curr_max = self . _maximumDate self . _maximumDate = QDate ( ) self . _minimumDate = QDate ( ) self . markForRebuild ( False ) # rebuilds the month view if ( self . currentMode ( ) == XCalendarScene . Mode . Month ) : self . rebuildMonth ( ) elif ( self . currentMode ( ) in ( XCalendarScene . Mode . Week , XCalendarScene . Mode . Day ) ) : self . rebuildDays ( ) # rebuild the items in the scene items = sorted ( self . items ( ) ) for item in items : item . setPos ( 0 , 0 ) item . hide ( ) for item in items : if ( isinstance ( item , XCalendarItem ) ) : item . rebuild ( ) if ( curr_min != self . _minimumDate or curr_max != self . _maximumDate ) : parent = self . parent ( ) if ( parent and not parent . signalsBlocked ( ) ) : parent . dateRangeChanged . emit ( self . _minimumDate , self . _maximumDate ) | Rebuilds the information for this scene . | 277 | 9 |
10,979 | def set ( self , time ) : self . _time = time self . _pb . sec = int ( self . _time ) self . _pb . nsec = int ( ( self . _time - self . _pb . sec ) * 10 ** 9 ) | Sets time in seconds since Epoch | 56 | 8 |
10,980 | def compile ( self , db ) : sql = self . expression if self . alias : sql += ( ' AS ' + db . quote_column ( self . alias ) ) return sql | Building the sql expression | 38 | 4 |
10,981 | async def register ( self , check , * , token = None ) : token_id = extract_attr ( token , keys = [ "ID" ] ) params = { "token" : token_id } response = await self . _api . put ( "/v1/agent/check/register" , params = params , data = check ) return response . status == 200 | Registers a new local check | 80 | 6 |
10,982 | async def deregister ( self , check ) : check_id = extract_attr ( check , keys = [ "CheckID" , "ID" ] ) response = await self . _api . get ( "/v1/agent/check/deregister" , check_id ) return response . status == 200 | Deregisters a local check | 68 | 7 |
10,983 | async def mark ( self , check , status , * , note = None ) : check_id = extract_attr ( check , keys = [ "CheckID" , "ID" ] ) data = { "Status" : status , "Output" : note } response = await self . _api . put ( "/v1/agent/check/update" , check_id , data = data ) return response . status == 200 | Marks a local check as passing warning or critical | 91 | 10 |
10,984 | def find_by_username ( self , username ) : data = ( db . select ( self . table ) . select ( 'username' , 'email' , 'real_name' , 'password' , 'bio' , 'status' , 'role' , 'uid' ) . condition ( 'username' , username ) . execute ( ) ) if data : return self . load ( data [ 0 ] , self . model ) | Return user by username if find in database otherwise None | 92 | 10 |
10,985 | def search ( self , * * kw ) : q = db . select ( self . table ) . condition ( 'status' , 'active' ) for k , v in kw : q . condition ( k , v ) data = q . execute ( ) users = [ ] for user in data : users . append ( self . load ( user , self . model ) ) return users | Find the users match the condition in kw | 81 | 9 |
10,986 | def paginate ( self , page = 1 , perpage = 10 , category = None ) : q = db . select ( self . table ) . fields ( 'title' , 'slug' , 'description' , 'html' , 'css' , 'js' , 'category' , 'status' , 'comments' , 'author' , 'created' , 'pid' ) if category : q . condition ( 'category' , category ) results = ( q . limit ( perpage ) . offset ( ( page - 1 ) * perpage ) . order_by ( 'created' , 'DESC' ) . execute ( ) ) return [ self . load ( data , self . model ) for data in results ] | Paginate the posts | 153 | 5 |
10,987 | def clear ( self ) : self . setCurrentLayer ( None ) self . _layers = [ ] self . _cache . clear ( ) super ( XNodeScene , self ) . clear ( ) | Clears the current scene of all the items and layers . | 42 | 12 |
10,988 | def rebuild ( self ) : rect = self . sceneRect ( ) x = rect . left ( ) y = rect . top ( ) w = rect . width ( ) h = rect . height ( ) # calculate background gridlines cx = x + ( w / 2 ) cy = y + ( h / 2 ) self . _centerLines = [ QLine ( cx , rect . top ( ) , cx , rect . bottom ( ) ) , QLine ( rect . left ( ) , cy , rect . right ( ) , cy ) ] # create the horizontal grid lines delta = self . cellHeight ( ) minor_lines = [ ] major_lines = [ ] count = 1 while delta < ( h / 2 ) : pos_line = QLine ( x , cy + delta , x + w , cy + delta ) neg_line = QLine ( x , cy - delta , x + w , cy - delta ) # every 10th line will be a major line if count == 10 : major_lines . append ( pos_line ) major_lines . append ( neg_line ) count = 1 else : minor_lines . append ( pos_line ) minor_lines . append ( neg_line ) # update the current y location delta += self . cellHeight ( ) count += 1 # create the vertical grid lines delta = self . cellWidth ( ) count = 1 while delta < ( w / 2 ) : pos_line = QLine ( cx + delta , y , cx + delta , y + h ) neg_line = QLine ( cx - delta , y , cx - delta , y + h ) # every 10th line will be a major line if count == 10 : major_lines . append ( pos_line ) major_lines . append ( neg_line ) count = 1 else : minor_lines . append ( pos_line ) minor_lines . append ( neg_line ) # update the current y location delta += self . cellWidth ( ) count += 1 # set the line cache self . _majorLines = major_lines self . _minorLines = minor_lines # unmark the scene as being dirty self . setDirty ( False ) | Rebuilds the grid lines based on the current settings and \ scene width . This method is triggered automatically and \ shouldn t need to be manually called . | 457 | 31 |
10,989 | def selectAll ( self ) : currLayer = self . _currentLayer for item in self . items ( ) : layer = item . layer ( ) if ( layer == currLayer or not layer ) : item . setSelected ( True ) | Selects all the items in the scene . | 52 | 9 |
10,990 | def selectInvert ( self ) : currLayer = self . _currentLayer for item in self . items ( ) : layer = item . layer ( ) if ( layer == currLayer or not layer ) : item . setSelected ( not item . isSelected ( ) ) | Inverts the currently selected items in the scene . | 60 | 10 |
10,991 | def selectNone ( self ) : currLayer = self . _currentLayer for item in self . items ( ) : layer = item . layer ( ) if ( layer == currLayer or not layer ) : item . setSelected ( False ) | Deselects all the items in the scene . | 52 | 11 |
10,992 | def setViewMode ( self , state = True ) : if self . _viewMode == state : return self . _viewMode = state if state : self . _mainView . setDragMode ( self . _mainView . ScrollHandDrag ) else : self . _mainView . setDragMode ( self . _mainView . RubberBandDrag ) self . emitViewModeChanged ( ) | Starts the view mode for moving around the scene . | 82 | 11 |
10,993 | def updateIsolated ( self , force = False ) : if ( not ( self . isolationMode ( ) or force ) ) : return # make sure all nodes are not being hidden because of isolation if ( not self . isolationMode ( ) ) : for node in self . nodes ( ) : node . setIsolateHidden ( False ) return # make sure all the nodes are visible or hidden based on the selection selected_nodes = self . selectedNodes ( ) isolated_nodes = set ( selected_nodes ) connections = self . connections ( ) for connection in connections : in_node = connection . inputNode ( ) out_node = connection . outputNode ( ) if ( in_node in selected_nodes or out_node in selected_nodes ) : isolated_nodes . add ( in_node ) isolated_nodes . add ( out_node ) for node in self . nodes ( ) : node . setIsolateHidden ( not node in isolated_nodes ) | Updates the visible state of nodes based on whether or not they are isolated . | 207 | 16 |
10,994 | def match ( self , version ) : return all ( constraint . match ( version ) for constraint in self . constraints ) | Match version with this collection of constraints . | 24 | 8 |
10,995 | def set_memcached_backend ( self , config ) : # This is the preferred backend as it is the fastest and most fully # featured, so we use this by default config [ 'BACKEND' ] = 'django_pylibmc.memcached.PyLibMCCache' if is_importable ( config [ 'BACKEND' ] ) : return # Otherwise, binary connections can use this pure Python implementation if config . get ( 'BINARY' ) and is_importable ( 'django_bmemcached' ) : config [ 'BACKEND' ] = 'django_bmemcached.memcached.BMemcached' return # For text-based connections without any authentication we can fall # back to Django's core backends if the supporting libraries are # installed if not any ( [ config . get ( key ) for key in ( 'BINARY' , 'USERNAME' , 'PASSWORD' ) ] ) : if is_importable ( 'pylibmc' ) : config [ 'BACKEND' ] = 'django.core.cache.backends.memcached.PyLibMCCache' elif is_importable ( 'memcached' ) : config [ 'BACKEND' ] = 'django.core.cache.backends.memcached.MemcachedCache' | Select the most suitable Memcached backend based on the config and on what s installed | 294 | 17 |
10,996 | def addEntry ( self ) : joiner = self . joiner ( ) curr_joiner = self . _containerWidget . currentJoiner ( ) # update the joining option if it is modified if joiner != curr_joiner : if not self . _last : self . updateJoin ( ) return self . _containerWidget . setCurrentJoiner ( joiner ) # otherwise, add a new entry self . _containerWidget . addEntry ( entry = self ) | This will either add a new widget or switch the joiner based on the state of the entry | 100 | 19 |
10,997 | def assignPlugin ( self ) : self . uiOperatorDDL . blockSignals ( True ) self . uiOperatorDDL . clear ( ) plugin = self . currentPlugin ( ) if plugin : flags = 0 if not self . queryWidget ( ) . showReferencePlugins ( ) : flags |= plugin . Flags . ReferenceRequired self . uiOperatorDDL . addItems ( plugin . operators ( ignore = flags ) ) self . uiOperatorDDL . blockSignals ( False ) self . assignEditor ( ) | Assigns an editor based on the current column for this schema . | 115 | 14 |
10,998 | def assignEditor ( self ) : plugin = self . currentPlugin ( ) column = self . currentColumn ( ) value = self . currentValue ( ) if not plugin : self . setEditor ( None ) return self . setUpdatesEnabled ( False ) self . blockSignals ( True ) op = self . uiOperatorDDL . currentText ( ) self . setEditor ( plugin . createEditor ( self , column , op , value ) ) self . setUpdatesEnabled ( True ) self . blockSignals ( False ) | Assigns the editor for this entry based on the plugin . | 111 | 13 |
10,999 | def refreshButtons ( self ) : last = self . _last first = self . _first joiner = self . _containerWidget . currentJoiner ( ) # the first button set can contain the toggle options if first : self . uiJoinSBTN . setActionTexts ( [ 'AND' , 'OR' ] ) elif joiner == QueryCompound . Op . And : self . uiJoinSBTN . setActionTexts ( [ 'AND' ] ) else : self . uiJoinSBTN . setActionTexts ( [ 'OR' ] ) # the last option should not show an active action if last : self . uiJoinSBTN . setCurrentAction ( None ) # otherwise, highlight the proper action else : act = self . uiJoinSBTN . findAction ( QueryCompound . Op [ joiner ] . upper ( ) ) self . uiJoinSBTN . setCurrentAction ( act ) enable = QueryCompound . typecheck ( self . _query ) or self . isChecked ( ) self . uiEnterBTN . setEnabled ( enable ) | Refreshes the buttons for building this sql query . | 235 | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.