idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
25,500
def wrap_exception ( func : Callable ) -> Callable : try : from bluepy . btle import BTLEException except ImportError : return func def _func_wrapper ( * args , ** kwargs ) : error_count = 0 last_error = None while error_count < RETRY_LIMIT : try : return func ( * args , ** kwargs ) except BTLEException as exception : ...
Decorator to wrap BTLEExceptions into BluetoothBackendException .
25,501
def write_handle ( self , handle : int , value : bytes ) : if self . _peripheral is None : raise BluetoothBackendException ( 'not connected to backend' ) return self . _peripheral . writeCharacteristic ( handle , value , True )
Write a handle from the device .
25,502
def check_backend ( ) -> bool : try : import bluepy . btle return True except ImportError as importerror : _LOGGER . error ( 'bluepy not found: %s' , str ( importerror ) ) return False
Check if the backend is available .
25,503
def scan_for_devices ( timeout : float ) -> List [ Tuple [ str , str ] ] : from bluepy . btle import Scanner scanner = Scanner ( ) result = [ ] for device in scanner . scan ( timeout ) : result . append ( ( device . addr , device . getValueText ( 9 ) ) ) return result
Scan for bluetooth low energy devices .
25,504
def wrap_exception ( func : Callable ) -> Callable : def _func_wrapper ( * args , ** kwargs ) : try : return func ( * args , ** kwargs ) except IOError as exception : raise BluetoothBackendException ( ) from exception return _func_wrapper
Wrap all IOErrors to BluetoothBackendException
25,505
def write_handle ( self , handle : int , value : bytes ) : if not self . is_connected ( ) : raise BluetoothBackendException ( 'Not connected to any device.' ) attempt = 0 delay = 10 _LOGGER . debug ( "Enter write_ble (%s)" , current_thread ( ) ) while attempt <= self . retries : cmd = "gatttool --device={} --addr-type=...
Read from a BLE address .
25,506
def wait_for_notification ( self , handle : int , delegate , notification_timeout : float ) : if not self . is_connected ( ) : raise BluetoothBackendException ( 'Not connected to any device.' ) attempt = 0 delay = 10 _LOGGER . debug ( "Enter write_ble (%s)" , current_thread ( ) ) while attempt <= self . retries : cmd =...
Listen for characteristics changes from a BLE address .
25,507
def check_backend ( ) -> bool : try : call ( 'gatttool' , stdout = PIPE , stderr = PIPE ) return True except OSError as os_err : msg = 'gatttool not found: {}' . format ( str ( os_err ) ) _LOGGER . error ( msg ) return False
Check if gatttool is available on the system .
25,508
def bytes_to_string ( raw_data : bytes , prefix : bool = False ) -> str : prefix_string = '' if prefix : prefix_string = '0x' suffix = '' . join ( [ format ( c , "02x" ) for c in raw_data ] ) return prefix_string + suffix . upper ( )
Convert a byte array to a hex string .
25,509
def decode_ast ( registry , ast_json ) : if ast_json . get ( "@type" ) : subclass = registry . get_cls ( ast_json [ "@type" ] , tuple ( ast_json [ "@fields" ] ) ) return subclass ( ast_json [ "children" ] , ast_json [ "field_references" ] , ast_json [ "label_references" ] , position = ast_json [ "@position" ] , ) else ...
JSON decoder for BaseNodes
25,510
def simplify_tree ( tree , unpack_lists = True , in_list = False ) : if isinstance ( tree , BaseNode ) and not isinstance ( tree , Terminal ) : used_fields = [ field for field in tree . _fields if getattr ( tree , field , False ) ] if len ( used_fields ) == 1 : result = getattr ( tree , used_fields [ 0 ] ) else : resul...
Recursively unpack single - item lists and objects where fields and labels only reference a single child
25,511
def get_field ( ctx , field ) : if isinstance ( field , str ) : field = getattr ( ctx , field , None ) if callable ( field ) : field = field ( ) elif isinstance ( field , CommonToken ) : field = next ( filter ( lambda c : getattr ( c , "symbol" , None ) is field , ctx . children ) ) return field
Helper to get the value of a field
25,512
def get_field_names ( ctx ) : fields = [ field for field in type ( ctx ) . __dict__ if not field . startswith ( "__" ) and field not in [ "accept" , "enterRule" , "exitRule" , "getRuleIndex" , "copyFrom" ] ] return fields
Get fields defined in an ANTLR context for a parser rule
25,513
def get_label_names ( ctx ) : labels = [ label for label in ctx . __dict__ if not label . startswith ( "_" ) and label not in [ "children" , "exception" , "invokingState" , "parentCtx" , "parser" , "start" , "stop" , ] ] return labels
Get labels defined in an ANTLR context for a parser rule
25,514
def get_info ( node_cfg ) : node_cfg = node_cfg if isinstance ( node_cfg , dict ) else { "name" : node_cfg } return node_cfg . get ( "name" ) , node_cfg . get ( "fields" , { } )
Return a tuple with the verbal name of a node and a dict of field names .
25,515
def isinstance ( self , instance , class_name ) : if isinstance ( instance , BaseNode ) : klass = self . dynamic_node_classes . get ( class_name , None ) if klass : return isinstance ( instance , klass ) return False else : raise TypeError ( "This function can only be used for BaseNode objects" )
Check if a BaseNode is an instance of a registered dynamic class
25,516
def get_transformer ( cls , method_name ) : transform_function = getattr ( cls , method_name ) assert callable ( transform_function ) def transformer_method ( self , node ) : kwargs = { } if inspect . signature ( transform_function ) . parameters . get ( "helper" ) : kwargs [ "helper" ] = self . helper return transform...
Get method to bind to visitor
25,517
def visitTerminal ( self , ctx ) : text = ctx . getText ( ) return Terminal . from_text ( text , ctx )
Converts case insensitive keywords and identifiers to lowercase
25,518
def run ( self , * args ) : params = self . parser . parse_args ( args ) entry = params . entry if params . add : code = self . add ( entry ) elif params . delete : code = self . delete ( entry ) else : term = entry code = self . blacklist ( term ) return code
List add or delete entries from the blacklist .
25,519
def add ( self , entry ) : if not entry : return CMD_SUCCESS try : api . add_to_matching_blacklist ( self . db , entry ) except InvalidValueError as e : raise RuntimeError ( str ( e ) ) except AlreadyExistsError as e : msg = "%s already exists in the registry" % entry self . error ( msg ) return e . code return CMD_SUC...
Add entries to the blacklist .
25,520
def delete ( self , entry ) : if not entry : return CMD_SUCCESS try : api . delete_from_matching_blacklist ( self . db , entry ) except NotFoundError as e : self . error ( str ( e ) ) return e . code return CMD_SUCCESS
Remove entries from the blacklist .
25,521
def blacklist ( self , term = None ) : try : bl = api . blacklist ( self . db , term ) self . display ( 'blacklist.tmpl' , blacklist = bl ) except NotFoundError as e : self . error ( str ( e ) ) return e . code return CMD_SUCCESS
List blacklisted entries .
25,522
def run ( self , * args ) : params = self . parser . parse_args ( args ) config_file = os . path . expanduser ( '~/.sortinghat' ) if params . action == 'get' : code = self . get ( params . parameter , config_file ) elif params . action == 'set' : code = self . set ( params . parameter , params . value , config_file ) e...
Get and set configuration parameters .
25,523
def get ( self , key , filepath ) : if not filepath : raise RuntimeError ( "Configuration file not given" ) if not self . __check_config_key ( key ) : raise RuntimeError ( "%s parameter does not exists" % key ) if not os . path . isfile ( filepath ) : raise RuntimeError ( "%s config file does not exist" % filepath ) se...
Get configuration parameter .
25,524
def set ( self , key , value , filepath ) : if not filepath : raise RuntimeError ( "Configuration file not given" ) if not self . __check_config_key ( key ) : raise RuntimeError ( "%s parameter does not exists or cannot be set" % key ) config = configparser . SafeConfigParser ( ) if os . path . isfile ( filepath ) : co...
Set configuration parameter .
25,525
def __check_config_key ( self , key ) : try : section , option = key . split ( '.' ) except ( AttributeError , ValueError ) : return False if not section or not option : return False return section in Config . CONFIG_OPTIONS and option in Config . CONFIG_OPTIONS [ section ]
Check whether the key is valid .
25,526
def run ( self , * args ) : params = self . parser . parse_args ( args ) with params . outfile as outfile : if params . identities : code = self . export_identities ( outfile , params . source ) elif params . orgs : code = self . export_organizations ( outfile ) else : raise RuntimeError ( "Unexpected export option" ) ...
Export data from the registry .
25,527
def export_identities ( self , outfile , source = None ) : exporter = SortingHatIdentitiesExporter ( self . db ) dump = exporter . export ( source ) try : outfile . write ( dump ) outfile . write ( '\n' ) except IOError as e : raise RuntimeError ( str ( e ) ) return CMD_SUCCESS
Export identities information to a file .
25,528
def export_organizations ( self , outfile ) : exporter = SortingHatOrganizationsExporter ( self . db ) dump = exporter . export ( ) try : outfile . write ( dump ) outfile . write ( '\n' ) except IOError as e : raise RuntimeError ( str ( e ) ) return CMD_SUCCESS
Export organizations information to a file .
25,529
def export ( self , source = None ) : uidentities = { } uids = api . unique_identities ( self . db , source = source ) for uid in uids : enrollments = [ rol . to_dict ( ) for rol in api . enrollments ( self . db , uuid = uid . uuid ) ] u = uid . to_dict ( ) u [ 'identities' ] . sort ( key = lambda x : x [ 'id' ] ) uide...
Export a set of unique identities .
25,530
def export ( self ) : organizations = { } orgs = api . registry ( self . db ) for org in orgs : domains = [ { 'domain' : dom . domain , 'is_top' : dom . is_top_domain } for dom in org . domains ] domains . sort ( key = lambda x : x [ 'domain' ] ) organizations [ org . name ] = domains obj = { 'time' : str ( datetime . ...
Export a set of organizations .
25,531
def run ( self , * args ) : params = self . parser . parse_args ( args ) sources = params . source code = self . autocomplete ( sources ) return code
Autocomplete profile information .
25,532
def autocomplete ( self , sources ) : email_pattern = re . compile ( EMAIL_ADDRESS_REGEX ) identities = self . __select_autocomplete_identities ( sources ) for uuid , ids in identities . items ( ) : name = None email = None for identity in ids : oldname = name if not name : name = identity . name or identity . username...
Autocomplete unique identities profiles .
25,533
def __select_autocomplete_identities ( self , sources ) : MIN_PRIORITY = 99999999 checked = { } for source in sources : uids = api . unique_identities ( self . db , source = source ) for uid in uids : if uid . uuid in checked : continue max_priority = MIN_PRIORITY selected = [ ] for identity in sorted ( uid . identitie...
Select the identities used for autocompleting
25,534
def run ( self , * args ) : params = self . parser . parse_args ( args ) code = self . show ( params . uuid , params . term ) return code
Show information about unique identities .
25,535
def show ( self , uuid = None , term = None ) : try : if uuid : uidentities = api . unique_identities ( self . db , uuid ) elif term : uidentities = api . search_unique_identities ( self . db , term ) else : uidentities = api . unique_identities ( self . db ) for uid in uidentities : enrollments = api . enrollments ( s...
Show the information related to unique identities .
25,536
def __parse_organizations ( self , json ) : try : for company in json [ 'companies' ] : name = self . __encode ( company [ 'company_name' ] ) org = self . _organizations . get ( name , None ) if not org : org = Organization ( name = name ) self . _organizations [ name ] = org for domain in company [ 'domains' ] : if no...
Parse Stackalytics organizations .
25,537
def __parse_identities ( self , json ) : try : for user in json [ 'users' ] : name = self . __encode ( user [ 'user_name' ] ) uuid = name uid = UniqueIdentity ( uuid = uuid ) identity = Identity ( name = name , email = None , username = None , source = self . source , uuid = uuid ) uid . identities . append ( identity ...
Parse identities using Stackalytics format .
25,538
def __parse_enrollments ( self , user ) : enrollments = [ ] for company in user [ 'companies' ] : name = company [ 'company_name' ] org = self . _organizations . get ( name , None ) if not org : org = Organization ( name = name ) self . _organizations [ name ] = org start_date = MIN_PERIOD_DATE end_date = MAX_PERIOD_DA...
Parse user enrollments
25,539
def __load_json ( self , stream ) : import json try : return json . loads ( stream ) except ValueError as e : cause = "invalid json format. %s" % str ( e ) raise InvalidFormatError ( cause = cause )
Load json stream into a dict object
25,540
def __parse ( self , stream , has_orgs ) : if has_orgs : self . __parse_organizations ( stream ) else : self . __parse_identities ( stream )
Parse identities and organizations using mailmap format .
25,541
def __parse_organizations ( self , stream ) : for aliases in self . __parse_stream ( stream ) : identity = self . __parse_alias ( aliases [ 1 ] ) uuid = identity . email uid = self . _identities . get ( uuid , None ) if not uid : uid = UniqueIdentity ( uuid = uuid ) identity . uuid = uuid uid . identities . append ( id...
Parse organizations stream
25,542
def __parse_identities ( self , stream ) : for aliases in self . __parse_stream ( stream ) : identity = self . __parse_alias ( aliases [ 0 ] ) uuid = identity . email uid = self . _identities . get ( uuid , None ) if not uid : uid = UniqueIdentity ( uuid = uuid ) identity . uuid = uuid uid . identities . append ( ident...
Parse identities stream
25,543
def __parse_stream ( self , stream ) : nline = 0 lines = stream . split ( '\n' ) for line in lines : nline += 1 m = re . match ( self . LINES_TO_IGNORE_REGEX , line , re . UNICODE ) if m : continue line = line . strip ( '\n' ) . strip ( ' ' ) parts = line . split ( '>' ) if len ( parts ) == 0 : cause = "line %s: invali...
Generic method to parse mailmap streams
25,544
def run ( self , * args ) : params = self . parser . parse_args ( args ) from_uuid = params . from_uuid to_uuid = params . to_uuid code = self . merge ( from_uuid , to_uuid ) return code
Merge two identities .
25,545
def create_identity_matcher ( matcher = 'default' , blacklist = None , sources = None , strict = True ) : import sortinghat . matching as matching if matcher not in matching . SORTINGHAT_IDENTITIES_MATCHERS : raise MatcherNotSupportedError ( matcher = str ( matcher ) ) klass = matching . SORTINGHAT_IDENTITIES_MATCHERS ...
Create an identity matcher of the given type .
25,546
def match ( uidentities , matcher , fastmode = False ) : if not isinstance ( matcher , IdentityMatcher ) : raise TypeError ( "matcher is not an instance of IdentityMatcher" ) if fastmode : try : matcher . matching_criteria ( ) except NotImplementedError : name = "'%s (fast mode)'" % matcher . __class__ . __name__ . low...
Find matches in a set of unique identities .
25,547
def _match ( filtered , matcher ) : def match_filtered_identities ( x , ids , matcher ) : for y in ids : if x . uuid == y . uuid : return True if matcher . match_filtered_identities ( x , y ) : return True return False matched = [ ] while filtered : candidates = [ ] no_match = [ ] x = filtered . pop ( 0 ) while matched...
Old method to find matches in a set of filtered identities .
25,548
def _match_with_pandas ( filtered , matcher ) : import pandas data = [ fl . to_dict ( ) for fl in filtered ] if not data : return [ ] df = pandas . DataFrame ( data ) df = df . sort_values ( [ 'uuid' ] ) cdfs = [ ] criteria = matcher . matching_criteria ( ) for c in criteria : cdf = df [ [ 'id' , 'uuid' , c ] ] cdf = c...
Find matches in a set using Pandas library .
25,549
def _filter_unique_identities ( uidentities , matcher ) : filtered = [ ] no_filtered = [ ] uuids = { } for uidentity in uidentities : n = len ( filtered ) filtered += matcher . filter ( uidentity ) if len ( filtered ) > n : uuids [ uidentity . uuid ] = uidentity else : no_filtered . append ( [ uidentity ] ) return filt...
Filter a set of unique identities .
25,550
def _build_matches ( matches , uuids , no_filtered , fastmode = False ) : result = [ ] for m in matches : mk = m [ 0 ] . uuid if not fastmode else m [ 0 ] subset = [ uuids [ mk ] ] for id_ in m [ 1 : ] : uk = id_ . uuid if not fastmode else id_ u = uuids [ uk ] if u not in subset : subset . append ( u ) result . append...
Build a list with matching subsets
25,551
def _calculate_matches_closures ( groups ) : matches = [ ] ns = sorted ( groups . groups . keys ( ) ) while ns : n = ns . pop ( 0 ) visited = [ n ] vs = [ v for v in groups . get_group ( n ) [ 'uuid_y' ] ] while vs : v = vs . pop ( 0 ) if v in visited : continue nvs = [ nv for nv in groups . get_group ( v ) [ 'uuid_y' ...
Find the transitive closure of each unique identity .
25,552
def match ( self , a , b ) : if not isinstance ( a , UniqueIdentity ) : raise ValueError ( "<a> is not an instance of UniqueIdentity" ) if not isinstance ( b , UniqueIdentity ) : raise ValueError ( "<b> is not an instance of UniqueIdentity" ) if a . uuid and b . uuid and a . uuid == b . uuid : return True filtered_a = ...
Determine if two unique identities are the same .
25,553
def find_unique_identity ( session , uuid ) : uidentity = session . query ( UniqueIdentity ) . filter ( UniqueIdentity . uuid == uuid ) . first ( ) return uidentity
Find a unique identity .
25,554
def find_identity ( session , id_ ) : identity = session . query ( Identity ) . filter ( Identity . id == id_ ) . first ( ) return identity
Find an identity .
25,555
def find_organization ( session , name ) : organization = session . query ( Organization ) . filter ( Organization . name == name ) . first ( ) return organization
Find an organization .
25,556
def find_domain ( session , name ) : domain = session . query ( Domain ) . filter ( Domain . domain == name ) . first ( ) return domain
Find a domain .
25,557
def find_country ( session , code ) : country = session . query ( Country ) . filter ( Country . code == code ) . first ( ) return country
Find a country .
25,558
def add_unique_identity ( session , uuid ) : if uuid is None : raise ValueError ( "'uuid' cannot be None" ) if uuid == '' : raise ValueError ( "'uuid' cannot be an empty string" ) uidentity = UniqueIdentity ( uuid = uuid ) uidentity . profile = Profile ( ) uidentity . last_modified = datetime . datetime . utcnow ( ) se...
Add a unique identity to the session .
25,559
def add_identity ( session , uidentity , identity_id , source , name = None , email = None , username = None ) : if identity_id is None : raise ValueError ( "'identity_id' cannot be None" ) if identity_id == '' : raise ValueError ( "'identity_id' cannot be an empty string" ) if source is None : raise ValueError ( "'sou...
Add an identity to the session .
25,560
def delete_identity ( session , identity ) : uidentity = identity . uidentity uidentity . last_modified = datetime . datetime . utcnow ( ) session . delete ( identity ) session . flush ( )
Remove an identity from the session .
25,561
def add_organization ( session , name ) : if name is None : raise ValueError ( "'name' cannot be None" ) if name == '' : raise ValueError ( "'name' cannot be an empty string" ) organization = Organization ( name = name ) session . add ( organization ) return organization
Add an organization to the session .
25,562
def delete_organization ( session , organization ) : last_modified = datetime . datetime . utcnow ( ) for enrollment in organization . enrollments : enrollment . uidentity . last_modified = last_modified session . delete ( organization ) session . flush ( )
Remove an organization from the session .
25,563
def add_domain ( session , organization , domain_name , is_top_domain = False ) : if domain_name is None : raise ValueError ( "'domain_name' cannot be None" ) if domain_name == '' : raise ValueError ( "'domain_name' cannot be an empty string" ) if not isinstance ( is_top_domain , bool ) : raise ValueError ( "'is_top_do...
Add a domain to the session .
25,564
def delete_enrollment ( session , enrollment ) : uidentity = enrollment . uidentity uidentity . last_modified = datetime . datetime . utcnow ( ) session . delete ( enrollment ) session . flush ( )
Remove an enrollment from the session .
25,565
def move_enrollment ( session , enrollment , uidentity ) : if enrollment . uuid == uidentity . uuid : return False old_uidentity = enrollment . uidentity enrollment . uidentity = uidentity last_modified = datetime . datetime . utcnow ( ) old_uidentity . last_modified = last_modified uidentity . last_modified = last_mod...
Move an enrollment to a unique identity .
25,566
def add_to_matching_blacklist ( session , term ) : if term is None : raise ValueError ( "'term' to blacklist cannot be None" ) if term == '' : raise ValueError ( "'term' to blacklist cannot be an empty string" ) mb = MatchingBlacklist ( excluded = term ) session . add ( mb ) return mb
Add term to the matching blacklist .
25,567
def genderize ( name , api_token = None ) : GENDERIZE_API_URL = "https://api.genderize.io/" TOTAL_RETRIES = 10 MAX_RETRIES = 5 SLEEP_TIME = 0.25 STATUS_FORCELIST = [ 502 ] params = { 'name' : name } if api_token : params [ 'apikey' ] = api_token session = requests . Session ( ) retries = urllib3 . util . Retry ( total ...
Fetch gender from genderize . io
25,568
def run ( self , * args ) : params = self . parser . parse_args ( args ) api_token = params . api_token genderize_all = params . genderize_all code = self . autogender ( api_token = api_token , genderize_all = genderize_all ) return code
Autocomplete gender information .
25,569
def autogender ( self , api_token = None , genderize_all = False ) : name_cache = { } no_gender = not genderize_all pattern = re . compile ( r"(^\w+)\s\w+" ) profiles = api . search_profiles ( self . db , no_gender = no_gender ) for profile in profiles : if not profile . name : continue name = profile . name . strip ( ...
Autocomplete gender information of unique identities .
25,570
def __parse_identities ( self , json ) : try : for mozillian in json [ 'results' ] : name = self . __encode ( mozillian [ 'full_name' ] [ 'value' ] ) email = self . __encode ( mozillian [ 'email' ] [ 'value' ] ) username = self . __encode ( mozillian [ 'username' ] ) uuid = username uid = UniqueIdentity ( uuid = uuid )...
Parse identities using Mozillians format .
25,571
def run ( self , * args ) : params = self . parser . parse_args ( args ) organization = params . organization domain = params . domain is_top_domain = params . top_domain overwrite = params . overwrite if params . add : code = self . add ( organization , domain , is_top_domain , overwrite ) elif params . delete : code ...
List add or delete organizations and domains from the registry .
25,572
def add ( self , organization , domain = None , is_top_domain = False , overwrite = False ) : if not organization : return CMD_SUCCESS if not domain : try : api . add_organization ( self . db , organization ) except InvalidValueError as e : raise RuntimeError ( str ( e ) ) except AlreadyExistsError as e : msg = "organi...
Add organizations and domains to the registry .
25,573
def delete ( self , organization , domain = None ) : if not organization : return CMD_SUCCESS if not domain : try : api . delete_organization ( self . db , organization ) except NotFoundError as e : self . error ( str ( e ) ) return e . code else : try : api . delete_domain ( self . db , organization , domain ) except ...
Remove organizations and domains from the registry .
25,574
def registry ( self , term = None ) : try : orgs = api . registry ( self . db , term ) self . display ( 'organizations.tmpl' , organizations = orgs ) except NotFoundError as e : self . error ( str ( e ) ) return e . code return CMD_SUCCESS
List organizations and domains .
25,575
def create_organizations_parser ( stream ) : import sortinghat . parsing as parsing for p in parsing . SORTINGHAT_ORGS_PARSERS : klass = parsing . SORTINGHAT_ORGS_PARSERS [ p ] parser = klass ( ) if parser . check ( stream ) : return parser raise InvalidFormatError ( cause = INVALID_FORMAT_MSG )
Create an organizations parser for the given stream .
25,576
def enroll ( self , uuid , organization , from_date = MIN_PERIOD_DATE , to_date = MAX_PERIOD_DATE , merge = False ) : if not uuid or not organization : return CMD_SUCCESS try : api . add_enrollment ( self . db , uuid , organization , from_date , to_date ) code = CMD_SUCCESS except ( NotFoundError , InvalidValueError ) ...
Enroll a unique identity in an organization .
25,577
def __parse_identities ( self , json ) : try : for committer in json [ 'committers' ] . values ( ) : name = self . __encode ( committer [ 'first' ] + ' ' + committer [ 'last' ] ) email = self . __encode ( committer [ 'primary' ] ) username = self . __encode ( committer [ 'id' ] ) uuid = username uid = UniqueIdentity ( ...
Parse identities using Eclipse format .
25,578
def __parse_organizations ( self , json ) : try : for organization in json [ 'organizations' ] . values ( ) : name = self . __encode ( organization [ 'name' ] ) try : active = str_to_datetime ( organization [ 'active' ] ) inactive = str_to_datetime ( organization [ 'inactive' ] ) if not active and not inactive : contin...
Parse Eclipse organizations .
25,579
def __parse_affiliations_json ( self , affiliations , uuid ) : enrollments = [ ] for affiliation in affiliations . values ( ) : name = self . __encode ( affiliation [ 'name' ] ) try : start_date = str_to_datetime ( affiliation [ 'active' ] ) end_date = str_to_datetime ( affiliation [ 'inactive' ] ) except InvalidDateEr...
Parse identity s affiliations from a json dict
25,580
def add_unique_identity ( db , uuid ) : with db . connect ( ) as session : try : add_unique_identity_db ( session , uuid ) except ValueError as e : raise InvalidValueError ( e )
Add a unique identity to the registry .
25,581
def add_organization ( db , organization ) : with db . connect ( ) as session : try : add_organization_db ( session , organization ) except ValueError as e : raise InvalidValueError ( e )
Add an organization to the registry .
25,582
def add_domain ( db , organization , domain , is_top_domain = False , overwrite = False ) : with db . connect ( ) as session : org = find_organization ( session , organization ) if not org : raise NotFoundError ( entity = organization ) dom = find_domain ( session , domain ) if dom and not overwrite : raise AlreadyExis...
Add a domain to the registry .
25,583
def add_to_matching_blacklist ( db , entity ) : with db . connect ( ) as session : try : add_to_matching_blacklist_db ( session , entity ) except ValueError as e : raise InvalidValueError ( e )
Add entity to the matching blacklist .
25,584
def delete_unique_identity ( db , uuid ) : with db . connect ( ) as session : uidentity = find_unique_identity ( session , uuid ) if not uidentity : raise NotFoundError ( entity = uuid ) delete_unique_identity_db ( session , uidentity )
Remove a unique identity from the registry .
25,585
def delete_from_matching_blacklist ( db , entity ) : with db . connect ( ) as session : mb = session . query ( MatchingBlacklist ) . filter ( MatchingBlacklist . excluded == entity ) . first ( ) if not mb : raise NotFoundError ( entity = entity ) delete_from_matching_blacklist_db ( session , mb )
Remove an blacklisted entity from the registry .
25,586
def merge_enrollments ( db , uuid , organization ) : with db . connect ( ) as session : uidentity = find_unique_identity ( session , uuid ) if not uidentity : raise NotFoundError ( entity = uuid ) org = find_organization ( session , organization ) if not org : raise NotFoundError ( entity = organization ) disjoint = se...
Merge overlapping enrollments .
25,587
def match_identities ( db , uuid , matcher ) : uidentities = [ ] with db . connect ( ) as session : uidentity = find_unique_identity ( session , uuid ) if not uidentity : raise NotFoundError ( entity = uuid ) candidates = session . query ( UniqueIdentity ) . filter ( UniqueIdentity . uuid != uuid ) . order_by ( UniqueI...
Search for similar unique identities .
25,588
def unique_identities ( db , uuid = None , source = None ) : uidentities = [ ] with db . connect ( ) as session : query = session . query ( UniqueIdentity ) if source : query = query . join ( Identity ) . filter ( UniqueIdentity . uuid == Identity . uuid , Identity . source == source ) if uuid : uidentity = query . fil...
List the unique identities available in the registry .
25,589
def search_unique_identities ( db , term , source = None ) : uidentities = [ ] pattern = '%' + term + '%' if term else None with db . connect ( ) as session : query = session . query ( UniqueIdentity ) . join ( Identity ) . filter ( UniqueIdentity . uuid == Identity . uuid ) if source : query = query . filter ( Identit...
Look for unique identities .
25,590
def search_unique_identities_slice ( db , term , offset , limit ) : uidentities = [ ] pattern = '%' + term + '%' if term else None if offset < 0 : raise InvalidValueError ( 'offset must be greater than 0 - %s given' % str ( offset ) ) if limit < 0 : raise InvalidValueError ( 'limit must be greater than 0 - %s given' % ...
Look for unique identities using slicing .
25,591
def search_last_modified_identities ( db , after ) : with db . connect ( ) as session : query = session . query ( Identity . id ) . filter ( Identity . last_modified >= after ) ids = [ id_ . id for id_ in query . order_by ( Identity . id ) . all ( ) ] return ids
Look for the uuids of identities modified on or after a given date .
25,592
def search_last_modified_unique_identities ( db , after ) : with db . connect ( ) as session : query = session . query ( UniqueIdentity . uuid ) . filter ( UniqueIdentity . last_modified >= after ) uids = [ uid . uuid for uid in query . order_by ( UniqueIdentity . uuid ) . all ( ) ] return uids
Look for the uuids of unique identities modified on or after a given date .
25,593
def search_profiles ( db , no_gender = False ) : profiles = [ ] with db . connect ( ) as session : query = session . query ( Profile ) if no_gender : query = query . filter ( Profile . gender == None ) profiles = query . order_by ( Profile . uuid ) . all ( ) session . expunge_all ( ) return profiles
List unique identities profiles .
25,594
def registry ( db , term = None ) : orgs = [ ] with db . connect ( ) as session : if term : orgs = session . query ( Organization ) . filter ( Organization . name . like ( '%' + term + '%' ) ) . order_by ( Organization . name ) . all ( ) if not orgs : raise NotFoundError ( entity = term ) else : orgs = session . query ...
List the organizations available in the registry .
25,595
def domains ( db , domain = None , top = False ) : doms = [ ] with db . connect ( ) as session : if domain : dom = find_domain ( session , domain ) if not dom : if not top : raise NotFoundError ( entity = domain ) else : add_dot = lambda d : '.' + d if not d . startswith ( '.' ) else d d = add_dot ( domain ) tops = ses...
List the domains available in the registry .
25,596
def countries ( db , code = None , term = None ) : def _is_code_valid ( code ) : return type ( code ) == str and len ( code ) == 2 and code . isalpha ( ) if code is not None and not _is_code_valid ( code ) : raise InvalidValueError ( 'country code must be a 2 length alpha string - %s given' % str ( code ) ) cs = [ ] wi...
List the countries available in the registry .
25,597
def enrollments ( db , uuid = None , organization = None , from_date = None , to_date = None ) : if not from_date : from_date = MIN_PERIOD_DATE if not to_date : to_date = MAX_PERIOD_DATE if from_date < MIN_PERIOD_DATE or from_date > MAX_PERIOD_DATE : raise InvalidValueError ( "'from_date' %s is out of bounds" % str ( f...
List the enrollment information available in the registry .
25,598
def blacklist ( db , term = None ) : mbs = [ ] with db . connect ( ) as session : if term : mbs = session . query ( MatchingBlacklist ) . filter ( MatchingBlacklist . excluded . like ( '%' + term + '%' ) ) . order_by ( MatchingBlacklist . excluded ) . all ( ) if not mbs : raise NotFoundError ( entity = term ) else : mb...
List the blacklisted entities available in the registry .
25,599
def run ( self , * args ) : uuid , kwargs = self . __parse_arguments ( * args ) code = self . edit_profile ( uuid , ** kwargs ) return code
Endit profile information .