idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
61,300 | def build_ontologies ( self , exclude_BNodes = False , return_string = False ) : out = [ ] qres = self . sparqlHelper . getOntology ( ) if qres : for candidate in qres : if isBlankNode ( candidate [ 0 ] ) : if exclude_BNodes : continue else : checkDC_ID = [ x for x in self . rdflib_graph . objects ( candidate [ 0 ] , r... | Extract ontology instances info from the graph then creates python objects for them . |
61,301 | def build_entity_from_uri ( self , uri , ontospyClass = None ) : if not ontospyClass : ontospyClass = RDF_Entity elif not issubclass ( ontospyClass , RDF_Entity ) : click . secho ( "Error: <%s> is not a subclass of ontospy.RDF_Entity" % str ( ontospyClass ) ) return None else : pass qres = self . sparqlHelper . entityT... | Extract RDF statements having a URI as subject then instantiate the RDF_Entity Python object so that it can be queried further . |
61,302 | def printClassTree ( self , element = None , showids = False , labels = False , showtype = False ) : TYPE_MARGIN = 11 if not element : for x in self . toplayer_classes : printGenericTree ( x , 0 , showids , labels , showtype , TYPE_MARGIN ) else : printGenericTree ( element , 0 , showids , labels , showtype , TYPE_MARG... | Print nicely into stdout the class tree of an ontology |
61,303 | def printPropertyTree ( self , element = None , showids = False , labels = False , showtype = False ) : TYPE_MARGIN = 18 if not element : for x in self . toplayer_properties : printGenericTree ( x , 0 , showids , labels , showtype , TYPE_MARGIN ) else : printGenericTree ( element , 0 , showids , labels , showtype , TYP... | Print nicely into stdout the property tree of an ontology |
61,304 | def add ( self , text = "" , default_continuousAdd = True ) : if not text and default_continuousAdd : self . continuousAdd ( ) else : pprefix = "" for x , y in self . rdflib_graph . namespaces ( ) : pprefix += "@prefix %s: <%s> . \n" % ( x , y ) if text and ( not text . strip ( ) . endswith ( "." ) ) : text += " ." tex... | add some turtle text |
61,305 | def rdf_source ( self , aformat = "turtle" ) : if aformat and aformat not in self . SUPPORTED_FORMATS : return "Sorry. Allowed formats are %s" % str ( self . SUPPORTED_FORMATS ) if aformat == "dot" : return self . __serializedDot ( ) else : return self . rdflib_graph . serialize ( format = aformat ) | Serialize graph using the format required |
61,306 | def omnigraffle ( self ) : temp = self . rdf_source ( "dot" ) try : from os . path import expanduser home = expanduser ( "~" ) filename = home + "/tmp/turtle_sketch.dot" f = open ( filename , "w" ) except : filename = "turtle_sketch.dot" f = open ( filename , "w" ) f . write ( temp ) f . close ( ) try : os . system ( "... | tries to open an export directly in omnigraffle |
61,307 | def main ( ) : print ( "Ontospy " + VERSION ) Shell ( ) . _clear_screen ( ) print ( Style . BRIGHT + "** Ontospy Interactive Ontology Browser " + VERSION + " **" + Style . RESET_ALL ) Shell ( ) . cmdloop ( ) raise SystemExit ( 1 ) | standalone line script |
61,308 | def _print ( self , ms , style = "TIP" ) : styles1 = { 'IMPORTANT' : Style . BRIGHT , 'TIP' : Style . DIM , 'URI' : Style . BRIGHT , 'TEXT' : Fore . GREEN , 'MAGENTA' : Fore . MAGENTA , 'BLUE' : Fore . BLUE , 'GREEN' : Fore . GREEN , 'RED' : Fore . RED , 'DEFAULT' : Style . DIM , } try : print ( styles1 [ style ] + ms ... | abstraction for managing color printing |
61,309 | def _printM ( self , messages ) : if len ( messages ) == 2 : print ( Style . BRIGHT + messages [ 0 ] + Style . RESET_ALL + Fore . BLUE + messages [ 1 ] + Style . RESET_ALL ) else : print ( "Not implemented" ) | print a list of strings - for the mom used only by stats printout |
61,310 | def _printDescription ( self , hrlinetop = True ) : if hrlinetop : self . _print ( "----------------" ) NOTFOUND = "[not found]" if self . currentEntity : obj = self . currentEntity [ 'object' ] label = obj . bestLabel ( ) or NOTFOUND description = obj . bestDescription ( ) or NOTFOUND print ( Style . BRIGHT + "OBJECT ... | generic method to print out a description |
61,311 | def _next_ontology ( self ) : currentfile = self . current [ 'file' ] try : idx = self . all_ontologies . index ( currentfile ) return self . all_ontologies [ idx + 1 ] except : return self . all_ontologies [ 0 ] | Dynamically retrieves the next ontology in the list |
61,312 | def _load_ontology ( self , filename , preview_mode = False ) : if not preview_mode : fullpath = self . LOCAL_MODELS + filename g = manager . get_pickled_ontology ( filename ) if not g : g = manager . do_pickle_ontology ( filename ) else : fullpath = filename filename = os . path . basename ( os . path . normpath ( ful... | Loads an ontology |
61,313 | def _select_property ( self , line ) : g = self . current [ 'graph' ] if not line : out = g . all_properties using_pattern = False else : using_pattern = True if line . isdigit ( ) : line = int ( line ) out = g . get_property ( line ) if out : if type ( out ) == type ( [ ] ) : choice = self . _selectFromList ( out , us... | try to match a property and load it |
61,314 | def _select_concept ( self , line ) : g = self . current [ 'graph' ] if not line : out = g . all_skos_concepts using_pattern = False else : using_pattern = True if line . isdigit ( ) : line = int ( line ) out = g . get_skos ( line ) if out : if type ( out ) == type ( [ ] ) : choice = self . _selectFromList ( out , usin... | try to match a class and load it |
61,315 | def do_visualize ( self , line ) : if not self . current : self . _help_noontology ( ) return line = line . split ( ) try : from . . ontodocs . builder import action_visualize except : self . _print ( "This command requires the ontodocs package: `pip install ontodocs`" ) return import webbrowser url = action_visualize ... | Visualize an ontology - ie wrapper for export command |
61,316 | def do_import ( self , line ) : line = line . split ( ) if line and line [ 0 ] == "starter-pack" : actions . action_bootstrap ( ) elif line and line [ 0 ] == "uri" : self . _print ( "------------------\nEnter a valid graph URI: (e.g. http://www.w3.org/2009/08/skos-reference/skos.rdf)" ) var = input ( ) if var : if var ... | Import an ontology |
61,317 | def do_file ( self , line ) : opts = self . FILE_OPTS if not self . all_ontologies : self . _help_nofiles ( ) return line = line . split ( ) if not line or line [ 0 ] not in opts : self . help_file ( ) return if line [ 0 ] == "rename" : self . _rename_file ( ) elif line [ 0 ] == "delete" : self . _delete_file ( ) else ... | PErform some file operation |
61,318 | def do_serialize ( self , line ) : opts = self . SERIALIZE_OPTS if not self . current : self . _help_noontology ( ) return line = line . split ( ) g = self . current [ 'graph' ] if not line : line = [ 'turtle' ] if line [ 0 ] not in opts : self . help_serialize ( ) return elif self . currentEntity : self . currentEntit... | Serialize an entity into an RDF flavour |
61,319 | def do_back ( self , line ) : "Go back one step. From entity => ontology; from ontology => ontospy top level." if self . currentEntity : self . currentEntity = None self . prompt = _get_prompt ( self . current [ 'file' ] ) else : self . current = None self . prompt = _get_prompt ( ) | Go back one step . From entity = > ontology ; from ontology = > ontospy top level . |
61,320 | def do_zen ( self , line ) : _quote = random . choice ( QUOTES ) print ( Style . DIM + unicode ( _quote [ 'text' ] ) ) print ( Style . BRIGHT + unicode ( _quote [ 'source' ] ) + Style . RESET_ALL ) | Inspiring quotes for the working ontologist |
61,321 | def complete_get ( self , text , line , begidx , endidx ) : options = self . GET_OPTS if not text : completions = options else : completions = [ f for f in options if f . startswith ( text ) ] return completions | completion for find command |
61,322 | def complete_info ( self , text , line , begidx , endidx ) : opts = self . INFO_OPTS if not text : completions = opts else : completions = [ f for f in opts if f . startswith ( text ) ] return completions | completion for info command |
61,323 | def build_D3treeStandard ( old , MAX_DEPTH , level = 1 , toplayer = None ) : out = [ ] if not old : old = toplayer for x in old : d = { } d [ 'qname' ] = x . qname d [ 'name' ] = x . bestLabel ( quotes = False ) . replace ( "_" , " " ) d [ 'objid' ] = x . id if x . children ( ) and level < MAX_DEPTH : d [ 'size' ] = le... | For d3s examples all we need is a json with name children and size .. eg |
61,324 | def build_D3bubbleChart ( old , MAX_DEPTH , level = 1 , toplayer = None ) : out = [ ] if not old : old = toplayer for x in old : d = { } d [ 'qname' ] = x . qname d [ 'name' ] = x . bestLabel ( quotes = False ) . replace ( "_" , " " ) d [ 'objid' ] = x . id if x . children ( ) and level < MAX_DEPTH : duplicate_row = { ... | Similar to standar d3 but nodes with children need to be duplicated otherwise they are not depicted explicitly but just color coded |
61,325 | def infer_best_title ( self ) : if self . ontospy_graph . all_ontologies : return self . ontospy_graph . all_ontologies [ 0 ] . uri elif self . ontospy_graph . sources : return self . ontospy_graph . sources [ 0 ] else : return "Untitled" | Selects something usable as a title for an ontospy graph |
61,326 | def build ( self , output_path = "" ) : self . output_path = self . checkOutputPath ( output_path ) self . _buildStaticFiles ( ) self . final_url = self . _buildTemplates ( ) printDebug ( "Done." , "comment" ) printDebug ( "=> %s" % ( self . final_url ) , "comment" ) return self . final_url | method that should be inherited by all vis classes |
61,327 | def _buildTemplates ( self ) : contents = self . _renderTemplate ( self . template_name , extraContext = None ) f = self . main_file_name main_url = self . _save2File ( contents , f , self . output_path ) return main_url | do all the things necessary to build the viz should be adapted to work for single - file viz or multi - files etc . |
61,328 | def _build_basic_context ( self ) : topclasses = self . ontospy_graph . toplayer_classes [ : ] if len ( topclasses ) < 3 : for topclass in self . ontospy_graph . toplayer_classes : for child in topclass . children ( ) : if child not in topclasses : topclasses . append ( child ) if not self . static_url : self . static_... | Return a standard dict used in django as a template context |
61,329 | def checkOutputPath ( self , output_path ) : if not output_path : output_path = os . path . join ( self . output_path_DEFAULT , slugify ( unicode ( self . title ) ) ) if os . path . exists ( output_path ) : shutil . rmtree ( output_path ) os . makedirs ( output_path ) return output_path | Create or clean up output path |
61,330 | def highlight_code ( self , ontospy_entity ) : try : pygments_code = highlight ( ontospy_entity . rdf_source ( ) , TurtleLexer ( ) , HtmlFormatter ( ) ) pygments_code_css = HtmlFormatter ( ) . get_style_defs ( '.highlight' ) return { "pygments_code" : pygments_code , "pygments_code_css" : pygments_code_css } except Exc... | produce an html version of Turtle code with syntax highlighted using Pygments CSS |
61,331 | def query ( self , q , format = "" , convert = True ) : lines = [ "PREFIX %s: <%s>" % ( k , r ) for k , r in self . prefixes . iteritems ( ) ] lines . extend ( q . split ( "\n" ) ) query = "\n" . join ( lines ) if self . verbose : print ( query , "\n\n" ) return self . __doQuery ( query , format , convert ) | Generic SELECT query structure . q is the main body of the query . |
61,332 | def describe ( self , uri , format = "" , convert = True ) : lines = [ "PREFIX %s: <%s>" % ( k , r ) for k , r in self . prefixes . iteritems ( ) ] if uri . startswith ( "http://" ) : lines . extend ( [ "DESCRIBE <%s>" % uri ] ) else : lines . extend ( [ "DESCRIBE %s" % uri ] ) query = "\n" . join ( lines ) if self . v... | A simple DESCRIBE query with no where arguments . uri is the resource you want to describe . |
61,333 | def __doQuery ( self , query , format , convert ) : self . __getFormat ( format ) self . sparql . setQuery ( query ) if convert : results = self . sparql . query ( ) . convert ( ) else : results = self . sparql . query ( ) return results | Inner method that does the actual query |
61,334 | def get_default_preds ( ) : g = ontospy . Ontospy ( rdfsschema , text = True , verbose = False , hide_base_schemas = False ) classes = [ ( x . qname , x . bestDescription ( ) ) for x in g . all_classes ] properties = [ ( x . qname , x . bestDescription ( ) ) for x in g . all_properties ] commands = [ ( 'exit' , 'exits ... | dynamically build autocomplete options based on an external file |
61,335 | def matcher ( graph1 , graph2 , confidence = 0.5 , output_file = "matching_results.csv" , class_or_prop = "classes" , verbose = False ) : printDebug ( "----------\nNow matching..." ) f = open ( output_file , 'wt' ) counter = 0 try : writer = csv . writer ( f , quoting = csv . QUOTE_NONNUMERIC ) writer . writerow ( ( 'n... | takes two graphs and matches its classes based on qname label etc .. |
61,336 | def safe_str ( u , errors = "replace" ) : s = u . encode ( sys . stdout . encoding or "utf-8" , errors ) return s | Safely print the given string . |
61,337 | def OLD_printDebug ( s , style = None ) : if style == "comment" : s = Style . DIM + s + Style . RESET_ALL elif style == "important" : s = Style . BRIGHT + s + Style . RESET_ALL elif style == "normal" : s = Style . RESET_ALL + s + Style . RESET_ALL elif style == "red" : s = Fore . RED + s + Style . RESET_ALL elif style ... | util for printing in colors to sys . stderr stream |
61,338 | def pprint2columns ( llist , max_length = 60 ) : if len ( llist ) == 0 : return None col_width = max ( len ( word ) for word in llist ) + 2 if not len ( llist ) % 2 == 0 : llist += [ ' ' ] if col_width > max_length : for el in llist : print ( el ) else : column1 = llist [ : int ( len ( llist ) / 2 ) ] column2 = llist [... | llist = a list of strings max_length = if a word is longer than that for single col display |
61,339 | def playSound ( folder , name = "" ) : try : if not name : onlyfiles = [ f for f in os . listdir ( folder ) if os . path . isfile ( os . path . join ( folder , f ) ) ] name = random . choice ( onlyfiles ) subprocess . call ( [ "afplay" , folder + name ] ) except : pass | as easy as that |
61,340 | def truncate ( data , l = 20 ) : "truncate a string" info = ( data [ : l ] + '..' ) if len ( data ) > l else data return info | truncate a string |
61,341 | def printGenericTree ( element , level = 0 , showids = True , labels = False , showtype = True , TYPE_MARGIN = 18 ) : ID_MARGIN = 5 SHORT_TYPES = { "rdf:Property" : "rdf:Property" , "owl:AnnotationProperty" : "owl:Annot.Pr." , "owl:DatatypeProperty" : "owl:DatatypePr." , "owl:ObjectProperty" : "owl:ObjectPr." , } if sh... | Print nicely into stdout the taxonomical tree of an ontology . |
61,342 | def firstStringInList ( literalEntities , prefLanguage = "en" ) : match = "" if len ( literalEntities ) == 1 : match = literalEntities [ 0 ] elif len ( literalEntities ) > 1 : for x in literalEntities : if getattr ( x , 'language' ) and getattr ( x , 'language' ) == prefLanguage : match = x if not match : match = liter... | from a list of literals returns the one in prefLanguage if no language specification is available return first element |
61,343 | def joinStringsInList ( literalEntities , prefLanguage = "en" ) : match = [ ] if len ( literalEntities ) == 1 : return literalEntities [ 0 ] elif len ( literalEntities ) > 1 : for x in literalEntities : if getattr ( x , 'language' ) and getattr ( x , 'language' ) == prefLanguage : match . append ( x ) if not match : fo... | from a list of literals returns the ones in prefLanguage joined up . if the desired language specification is not available join all up |
61,344 | def sortByNamespacePrefix ( urisList , nsList ) : exit = [ ] urisList = sort_uri_list_by_name ( urisList ) for ns in nsList : innerexit = [ ] for uri in urisList : if str ( uri ) . startswith ( str ( ns ) ) : innerexit += [ uri ] exit += innerexit for uri in urisList : if uri not in exit : exit += [ uri ] return exit | Given an ordered list of namespaces prefixes order a list of uris based on that . Eg |
61,345 | def sort_uri_list_by_name ( uri_list , bypassNamespace = False ) : def get_last_bit ( uri_string ) : try : x = uri_string . split ( "#" ) [ 1 ] except : x = uri_string . split ( "/" ) [ - 1 ] return x try : if bypassNamespace : return sorted ( uri_list , key = lambda x : get_last_bit ( x . __str__ ( ) ) ) else : return... | Sorts a list of uris |
61,346 | def inferNamespacePrefix ( aUri ) : stringa = aUri . __str__ ( ) try : prefix = stringa . replace ( "#" , "" ) . split ( "/" ) [ - 1 ] except : prefix = "" return prefix | From a URI returns the last bit and simulates a namespace prefix when rendering the ontology . |
61,347 | def niceString2uri ( aUriString , namespaces = None ) : if not namespaces : namespaces = [ ] for aNamespaceTuple in namespaces : if aNamespaceTuple [ 0 ] and aUriString . find ( aNamespaceTuple [ 0 ] . __str__ ( ) + ":" ) == 0 : aUriString_name = aUriString . split ( ":" ) [ 1 ] return rdflib . term . URIRef ( aNamespa... | From a string representing a URI possibly with the namespace qname returns a URI instance . |
61,348 | def shellPrintOverview ( g , opts = { 'labels' : False } ) : ontologies = g . all_ontologies try : labels = opts [ 'labels' ] except : labels = False print ( Style . BRIGHT + "Namespaces\n-----------" + Style . RESET_ALL ) if g . namespaces : for p , u in g . namespaces : row = Fore . GREEN + "%s" % p + Fore . BLACK + ... | overview of graph invoked from command line |
61,349 | def try_sort_fmt_opts ( rdf_format_opts_list , uri ) : filename , file_extension = os . path . splitext ( uri ) if file_extension == ".ttl" or file_extension == ".turtle" : return [ 'turtle' , 'n3' , 'nt' , 'json-ld' , 'rdfa' , 'xml' ] elif file_extension == ".xml" or file_extension == ".rdf" : return [ 'xml' , 'turtle... | reorder fmt options based on uri file type suffix - if available - so to test most likely serialization first when parsing some RDF |
61,350 | def ask_visualization ( ) : printDebug ( "Please choose an output format for the ontology visualization: (q=quit)\n" , "important" ) while True : text = "" for viz in VISUALIZATIONS_LIST : text += "%d) %s\n" % ( VISUALIZATIONS_LIST . index ( viz ) + 1 , viz [ 'Title' ] ) var = input ( text + ">" ) if var == "q" : retur... | ask user which viz output to use |
61,351 | def select_visualization ( n ) : try : n = int ( n ) - 1 test = VISUALIZATIONS_LIST [ n ] return n except : printDebug ( "Invalid viz-type option. Valid options are:" , "red" ) show_types ( ) raise SystemExit ( 1 ) | get viz choice based on numerical index |
61,352 | def action_analyze ( sources , endpoint = None , print_opts = False , verbose = False , extra = False , raw = False ) : for x in sources : click . secho ( "Parsing %s..." % str ( x ) , fg = 'white' ) if extra : hide_base_schemas = False hide_implicit_types = False hide_implicit_preds = False else : hide_base_schemas = ... | Load up a model into ontospy and analyze it |
61,353 | def action_listlocal ( all_details = True ) : " select a file from the local repo " options = get_localontologies ( ) counter = 1 if not options : printDebug ( "Your local library is empty. Use 'ontospy lib --bootstrap' to add some ontologies to it." ) return else : if all_details : _print_table_ontologies ( ) else : _... | select a file from the local repo |
61,354 | def action_import ( location , verbose = True ) : location = str ( location ) ONTOSPY_LOCAL_MODELS = get_home_location ( ) fullpath = "" try : if location . startswith ( "www." ) : location = "http://%s" % str ( location ) if location . startswith ( "http" ) : headers = { 'Accept' : "application/rdf+xml" } try : req = ... | Import files into the local repo |
61,355 | def action_import_folder ( location ) : if os . path . isdir ( location ) : onlyfiles = [ f for f in os . listdir ( location ) if os . path . isfile ( os . path . join ( location , f ) ) ] for file in onlyfiles : if not file . startswith ( "." ) : filepath = os . path . join ( location , file ) click . secho ( "\n-----... | Try to import all files from a local folder |
61,356 | def action_webimport ( hrlinetop = False ) : DIR_OPTIONS = { 1 : "http://lov.okfn.org" , 2 : "http://prefix.cc/popular/" } selection = None while True : if hrlinetop : printDebug ( "----------" ) text = "Please select which online directory to scan: (enter=quit)\n" for x in DIR_OPTIONS : text += "%d) %s\n" % ( x , DIR_... | select from the available online directories for import |
61,357 | def action_bootstrap ( verbose = False ) : printDebug ( "The following ontologies will be imported:" ) printDebug ( "--------------" ) count = 0 for s in BOOTSTRAP_ONTOLOGIES : count += 1 print ( count , "<%s>" % s ) printDebug ( "--------------" ) printDebug ( "Note: this operation may take several minutes." ) printDe... | Bootstrap the local REPO with a few cool ontologies |
61,358 | def action_update_library_location ( _location ) : printDebug ( "Old location: '%s'" % get_home_location ( ) , "comment" ) if os . path . isdir ( _location ) : config = SafeConfigParser ( ) config_filename = ONTOSPY_LOCAL + '/config.ini' config . read ( config_filename ) if not config . has_section ( 'models' ) : confi... | Sets the folder that contains models for the local library |
61,359 | def action_cache_reset ( ) : printDebug ( ) printDebug ( ) ONTOSPY_LOCAL_MODELS = get_home_location ( ) shutil . rmtree ( ONTOSPY_LOCAL_CACHE_TOP ) var = input ( Style . BRIGHT + "=====\nProceed? (y/n) " + Style . RESET_ALL ) if var == "y" : repo_contents = get_localontologies ( ) print ( Style . BRIGHT + "\n=====\n%d ... | Delete all contents from cache folder Then re - generate cached version of all models in the local repo |
61,360 | def compare_ordereddict ( self , X , Y ) : child = self . compare_dicts ( X , Y ) if isinstance ( child , DeepExplanation ) : return child for i , j in zip ( X . items ( ) , Y . items ( ) ) : if i [ 0 ] != j [ 0 ] : c = self . get_context ( ) msg = "X{0} and Y{1} are in a different order" . format ( red ( c . current_X... | Compares two instances of an OrderedDict . |
61,361 | def stub ( base_class = None , ** attributes ) : if base_class is None : base_class = object members = { "__init__" : lambda self : None , "__new__" : lambda * args , ** kw : object . __new__ ( * args , * kw ) , "__metaclass__" : None , } members . update ( attributes ) return type ( f"{base_class.__name__}Stub" , ( ba... | creates a python class on - the - fly with the given keyword - arguments as class - attributes accessible with . attrname . |
61,362 | def assertion ( func ) : func = assertionmethod ( func ) setattr ( AssertionBuilder , func . __name__ , func ) return func | Extend sure with a custom assertion method . |
61,363 | def chainproperty ( func ) : func = assertionproperty ( func ) setattr ( AssertionBuilder , func . fget . __name__ , func ) return func | Extend sure with a custom chain property . |
61,364 | def equal ( self , what , epsilon = None ) : try : comparison = DeepComparison ( self . obj , what , epsilon ) . compare ( ) error = False except AssertionError as e : error = e comparison = None if isinstance ( comparison , DeepExplanation ) : error = comparison . get_assertion ( self . obj , what ) if self . negative... | compares given object X with an expected Y object . |
61,365 | def find_dependencies ( self , dependent_rev , recurse = None ) : if recurse is None : recurse = self . options . recurse try : dependent = self . get_commit ( dependent_rev ) except InvalidCommitish as e : abort ( e . message ( ) ) self . todo . append ( dependent ) self . todo_d [ dependent . hex ] = True first_time ... | Find all dependencies of the given revision recursively traversing the dependency tree if requested . |
61,366 | def find_dependencies_with_parent ( self , dependent , parent ) : self . logger . info ( " Finding dependencies of %s via parent %s" % ( dependent . hex [ : 8 ] , parent . hex [ : 8 ] ) ) diff = self . repo . diff ( parent , dependent , context_lines = self . options . context_lines ) for patch in diff : path = patc... | Find all dependencies of the given revision caused by the given parent commit . This will be called multiple times for merge commits which have multiple parents . |
61,367 | def blame_diff_hunk ( self , dependent , parent , path , hunk ) : line_range_before = "-%d,%d" % ( hunk . old_start , hunk . old_lines ) line_range_after = "+%d,%d" % ( hunk . new_start , hunk . new_lines ) self . logger . info ( " Blaming hunk %s @ %s (listed below)" % ( line_range_before , parent . hex [ : 8 ]... | Run git blame on the parts of the hunk which exist in the older commit in the diff . The commits generated by git blame are the commits which the newer commit in the diff depends on because without the lines from those commits the hunk would not apply correctly . |
61,368 | def tree_lookup ( self , target_path , commit ) : segments = target_path . split ( "/" ) tree_or_blob = commit . tree path = '' while segments : dirent = segments . pop ( 0 ) if isinstance ( tree_or_blob , pygit2 . Tree ) : if dirent in tree_or_blob : tree_or_blob = self . repo [ tree_or_blob [ dirent ] . oid ] if path... | Navigate to the tree or blob object pointed to by the given target path for the given commit . This is necessary because each git tree only contains entries for the directory it refers to not recursively for all subdirectories . |
61,369 | def abbreviate_sha1 ( cls , sha1 ) : cmd = [ 'git' , 'rev-parse' , '--short' , sha1 ] out = subprocess . check_output ( cmd , universal_newlines = True ) . strip ( ) return out | Uniquely abbreviates the given SHA1 . |
61,370 | def describe ( cls , sha1 ) : cmd = [ 'git' , 'describe' , '--all' , '--long' , sha1 ] out = None try : out = subprocess . check_output ( cmd , stderr = subprocess . STDOUT , universal_newlines = True ) except subprocess . CalledProcessError as e : if e . output . find ( 'No tags can describe' ) != - 1 : return '' rais... | Returns a human - readable representation of the given SHA1 . |
61,371 | def refs_to ( cls , sha1 , repo ) : matching = [ ] for refname in repo . listall_references ( ) : symref = repo . lookup_reference ( refname ) dref = symref . resolve ( ) oid = dref . target commit = repo . get ( oid ) if commit . hex == sha1 : matching . append ( symref . shorthand ) return matching | Returns all refs pointing to the given SHA1 . |
61,372 | def add_commit ( self , commit ) : sha1 = commit . hex if sha1 in self . _commits : return self . _commits [ sha1 ] title , separator , body = commit . message . partition ( "\n" ) commit = { 'explored' : False , 'sha1' : sha1 , 'name' : GitUtils . abbreviate_sha1 ( sha1 ) , 'describe' : GitUtils . describe ( sha1 ) , ... | Adds the commit to the commits array if it doesn t already exist and returns the commit s index in the array . |
61,373 | def get ( self , path , params = None , headers = None ) : response = requests . get ( self . _url_for ( path ) , params = params , headers = self . _headers ( headers ) ) self . _handle_errors ( response ) return response | Perform a GET request optionally providing query - string params . |
61,374 | def post ( self , path , body , headers = None ) : response = requests . post ( self . _url_for ( path ) , data = json . dumps ( body ) , headers = self . _headers ( headers ) ) self . _handle_errors ( response ) return response | Perform a POST request providing a body which will be JSON - encoded . |
61,375 | def create ( self , params = None , headers = None ) : path = '/creditor_bank_accounts' if params is not None : params = { self . _envelope_key ( ) : params } try : response = self . _perform_request ( 'POST' , path , params , headers , retry_failures = True ) except errors . IdempotentCreationConflictError as err : re... | Create a creditor bank account . |
61,376 | def list ( self , params = None , headers = None ) : path = '/creditor_bank_accounts' response = self . _perform_request ( 'GET' , path , params , headers , retry_failures = True ) return self . _resource_for ( response ) | List creditor bank accounts . |
61,377 | def get ( self , identity , params = None , headers = None ) : path = self . _sub_url_params ( '/creditor_bank_accounts/:identity' , { 'identity' : identity , } ) response = self . _perform_request ( 'GET' , path , params , headers , retry_failures = True ) return self . _resource_for ( response ) | Get a single creditor bank account . |
61,378 | def disable ( self , identity , params = None , headers = None ) : path = self . _sub_url_params ( '/creditor_bank_accounts/:identity/actions/disable' , { 'identity' : identity , } ) if params is not None : params = { 'data' : params } response = self . _perform_request ( 'POST' , path , params , headers , retry_failur... | Disable a creditor bank account . |
61,379 | def create ( self , params = None , headers = None ) : path = '/mandate_pdfs' if params is not None : params = { self . _envelope_key ( ) : params } response = self . _perform_request ( 'POST' , path , params , headers , retry_failures = True ) return self . _resource_for ( response ) | Create a mandate PDF . |
61,380 | def update ( self , identity , params = None , headers = None ) : path = self . _sub_url_params ( '/payments/:identity' , { 'identity' : identity , } ) if params is not None : params = { self . _envelope_key ( ) : params } response = self . _perform_request ( 'PUT' , path , params , headers , retry_failures = True ) re... | Update a payment . |
61,381 | def resolve_config ( self ) : conf = self . load_config ( self . force_default ) for k in conf [ 'hues' ] : conf [ 'hues' ] [ k ] = getattr ( KEYWORDS , conf [ 'hues' ] [ k ] ) as_tuples = lambda name , obj : namedtuple ( name , obj . keys ( ) ) ( ** obj ) self . hues = as_tuples ( 'Hues' , conf [ 'hues' ] ) self . opt... | Resolve configuration params to native instances |
61,382 | def apply ( funcs , stack ) : return reduce ( lambda x , y : y ( x ) , funcs , stack ) | Apply functions to the stack passing the resulting stack to next state . |
61,383 | def colorize ( string , stack ) : codes = optimize ( stack ) if len ( codes ) : prefix = SEQ % ';' . join ( map ( str , codes ) ) suffix = SEQ % STYLE . reset return prefix + string + suffix else : return string | Apply optimal ANSI escape sequences to the string . |
61,384 | def compute_agreement_score ( num_matches , num1 , num2 ) : denom = num1 + num2 - num_matches if denom == 0 : return 0 return num_matches / denom | Agreement score is used as a criteria to match unit1 and unit2 . |
61,385 | def collect_results ( working_folder ) : results = { } working_folder = Path ( working_folder ) output_folders = working_folder / 'output_folders' for rec_name in os . listdir ( output_folders ) : if not os . path . isdir ( output_folders / rec_name ) : continue results [ rec_name ] = { } for sorter_name in os . listdi... | Collect results in a working_folder . |
61,386 | def run_sorter ( sorter_name_or_class , recording , output_folder = None , delete_output_folder = False , grouping_property = None , parallel = False , debug = False , ** params ) : if isinstance ( sorter_name_or_class , str ) : SorterClass = sorter_dict [ sorter_name_or_class ] elif sorter_name_or_class in sorter_full... | Generic function to run a sorter via function approach . |
61,387 | def compute_performance ( SC , verbose = True , output = 'dict' ) : counts = SC . _counts tp_rate = float ( counts [ 'TP' ] ) / counts [ 'TOT_ST1' ] * 100 cl_rate = float ( counts [ 'CL' ] ) / counts [ 'TOT_ST1' ] * 100 fn_rate = float ( counts [ 'FN' ] ) / counts [ 'TOT_ST1' ] * 100 fp_st1 = float ( counts [ 'FP' ] ) ... | Return some performance value for comparison . |
61,388 | def _complex_response_to_error_adapter ( self , body ) : meta = body . get ( 'meta' ) errors = body . get ( 'errors' ) e = [ ] for error in errors : status = error [ 'status' ] code = error [ 'code' ] title = error [ 'title' ] e . append ( ErrorDetails ( status , code , title ) ) return e , meta | Convert a list of error responses . |
61,389 | def _adapt_response ( self , response ) : errors , meta = super ( ServerError , self ) . _adapt_response ( response ) return errors [ 0 ] , meta | Convert various error responses to standardized ErrorDetails . |
61,390 | def _prepare ( self ) : if self . method not in http . ALLOWED_METHODS : raise UberIllegalState ( 'Unsupported HTTP Method.' ) api_host = self . api_host headers = self . _build_headers ( self . method , self . auth_session ) url = build_url ( api_host , self . path ) data , params = generate_data ( self . method , sel... | Builds a URL and return a PreparedRequest . |
61,391 | def _send ( self , prepared_request ) : session = Session ( ) response = session . send ( prepared_request ) return Response ( response ) | Send a PreparedRequest to the server . |
61,392 | def _build_headers ( self , method , auth_session ) : token_type = auth_session . token_type if auth_session . server_token : token = auth_session . server_token else : token = auth_session . oauth2credential . access_token if not self . _authorization_headers_valid ( token_type , token ) : message = 'Invalid token_typ... | Create headers for the request . |
61,393 | def authorization_code_grant_flow ( credentials , storage_filename ) : auth_flow = AuthorizationCodeGrant ( credentials . get ( 'client_id' ) , credentials . get ( 'scopes' ) , credentials . get ( 'client_secret' ) , credentials . get ( 'redirect_url' ) , ) auth_url = auth_flow . get_authorization_url ( ) login_message... | Get an access token through Authorization Code Grant . |
61,394 | def _request_access_token ( grant_type , client_id = None , client_secret = None , scopes = None , code = None , redirect_url = None , refresh_token = None ) : url = build_url ( auth . AUTH_HOST , auth . ACCESS_TOKEN_PATH ) if isinstance ( scopes , set ) : scopes = ' ' . join ( scopes ) args = { 'grant_type' : grant_ty... | Make an HTTP POST to request an access token . |
61,395 | def refresh_access_token ( credential ) : if credential . grant_type == auth . AUTHORIZATION_CODE_GRANT : response = _request_access_token ( grant_type = auth . REFRESH_TOKEN , client_id = credential . client_id , client_secret = credential . client_secret , redirect_url = credential . redirect_url , refresh_token = cr... | Use a refresh token to request a new access token . |
61,396 | def _build_authorization_request_url ( self , response_type , redirect_url , state = None ) : if response_type not in auth . VALID_RESPONSE_TYPES : message = '{} is not a valid response type.' raise UberIllegalState ( message . format ( response_type ) ) args = OrderedDict ( [ ( 'scope' , ' ' . join ( self . scopes ) )... | Form URL to request an auth code or access token . |
61,397 | def _extract_query ( self , redirect_url ) : qs = urlparse ( redirect_url ) qs = qs . fragment if isinstance ( self , ImplicitGrant ) else qs . query query_params = parse_qs ( qs ) query_params = { qp : query_params [ qp ] [ 0 ] for qp in query_params } return query_params | Extract query parameters from a url . |
61,398 | def _generate_state_token ( self , length = 32 ) : choices = ascii_letters + digits return '' . join ( SystemRandom ( ) . choice ( choices ) for _ in range ( length ) ) | Generate CSRF State Token . |
61,399 | def get_authorization_url ( self ) : return self . _build_authorization_request_url ( response_type = auth . CODE_RESPONSE_TYPE , redirect_url = self . redirect_url , state = self . state_token , ) | Start the Authorization Code Grant process . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.