def create_name_object(name_str): """ Create a Name object for creators in the resource list and replace string version with Name object. Parameters: name_str (string): String version of a name Returns: name_obj (Name): Name object """ # Split the name string into a list name_str = name_str.split(' ') # The name string has three names if len(name_str) == 3: name_obj = Name(name_str[0], name_str[1], name_str[2]) # The name string has two names and will place in first and last name # attributes elif len(name_str) == 2: name_obj = Name(name_str[0], "", name_str[1]) # The name string has one name else: name_obj = Name(name_str[0]) return name_obj
def getNameAccount(self): name = Name() print("¿Cómo se llama?") inName = input() print(f"Bienvenido, {inName}") name.name = inName return name
def Init(persons=[]): p1 = Person(Name('Alan', 'Turing'), Address('Bletchley Park', 'Bletchley Park')) p2 = Person(Name('Alan', 'Turing'), Address('Cambridge', 'Cambridge')) p3 = Person(Name('Joan', 'Clarke'), Address('Bletchley Park', 'Bletchley Park')) p4 = Person(Name('Joan', 'Clarke'), Address('London', 'London')) p5 = Person(Name('Grace', 'Hopper'), Address('New York', 'New York')) persons.extend((p1, p2, p3, p4, p5)) print('MinRelationLevel:' + str(FindMinRelationLevel(p1, p4, persons)))
def test_get_full_name(self): """ Test that get_full_name method returns a string with the first middle, and last name separated by a space """ # Create a Name object and get the full name name = Name("Iain", "Robert", "Pears") full_name = name.get_full_name() # Assert expected result of the get_full_name function self.assertEqual(full_name, ("Iain Robert Pears"))
def test_comparison(self): A = Name.parse('Neil deGrasse Tyson') B = Name('Neil', 'D', 'Tyson') C = Name('NEIL', None, 'TYSON') D = Name('Neil', 'DEGRASSE', 'Tyson') self.assertEqual(A.compare(C), 3) self.assertEqual(C.compare(A), 2) self.assertEqual(A.compare(B), 1) self.assertEqual(B.compare(B), 1) self.assertEqual(D.compare(A), 0) self.assertEqual(A.compare(D), 0)
def test_get_brief_summary_output(self): """ Test get_brief_summary method's output in Resource class""" # Create a Resource object resource = Resource(1, "White Noise", Name("Don", "", "DeLillo"), "Delillo's White Noise follows narrator Jack "\ "Gladney, a professor at a small Liberal Arts "\ "college and describes an academic year. Jack "\ "teaches at a school called the "\ "College-on-the-Hill, where he serves as the "\ "department chair of Hitler studies. He lives in "\ "Blacksmith, a quiet college town, with his wife, "\ "Babette, and four of their children from earlier "\ "marriages: Heinrich, Steffie, Denise, and "\ "Wilder. Throughout the novel, various "\ "half-siblings and ex-spouses drift in and out "\ "of the family’s home.", "sci-fi", "English", 1985, "US", 326, "book", ["culture", "survival", "life", "society"]) # Assert expected results self.assertEqual(resource.get_brief_summary(), "Delillo's White "\ "Noise follows narrator Jack Gladney, a professor "\ "at a \nsmall Liberal Arts college and describes an "\ "academic year. Jack teaches \nat ...")
def __create_remote_Conc__(Mgr, RemoteEnvId, CallingModule, ConcClass, *args, **kwargs): ''' low-level support for Conc creation in another Env ''' ConcId = _ConcIdMgr.new() NewConcAddr = ConcAddr(my_EnvId(), ConcId, RemoteEnvId) ConcClassProxy = proxy(ConcClass, ConcClass.__name__ + 'Name', CallingModule) NewProxy = ConcClassProxy(NewConcAddr) NewName = Name(NewProxy, ConcClass.__name__, CallingModule.__name__) # create proxy for remote Env EnvConcAddr = ConcAddr(CORPSMGR_ENVID, ENVMGR_CONCID, RemoteEnvId) RemoteEnv = EnvName(EnvConcAddr) # request object creation in remote Env kwargs['ConcAddr'] = NewConcAddr kwargs['Mgr'] = Mgr FutRes = RemoteEnv.rem2loc_create_Conc(NewConcAddr, CallingModule.__name__, ConcClass.__name__, *args, **kwargs) try: Ret = FutRes.Ret except: ei = exc_info() ftb = format_exception(ei[0], ei[1], ei[2]) raise AsyncExecutionError(ei[0].__name__, ei[1], ''.join(ftb)) return NewName
def __init__(self, keyName=None): if isinstance(keyName, Name): self.keyName = keyName else: self.keyName = Name(keyName) self.ndn_data = None
def setInterestFilter(self, name, onInterest, flags=None): if not isinstance(name, Name): name = Name(name) self._setInterestFilter(name, Closure.TrivialFilterClosure(name, onInterest), flags)
def set_up(self): """Set up the router""" self.__node = Node(1, Name(self.__name)) # for testing purpose name1 = Name("/test1") name2 = Name("/test2") data1 = Data(name1, "This is the test data 1") data2 = Data(name2, "This is the test data 2") cs = self.__node.get_content_store() cs.add(name1, data1) cs.add(name2, data2) #add IDS in the node ids = IDS() self.__node.attach_IDS(ids)
class Person(object): """ Person Information """ def __init__( self, name = None, birth_date = None, death_date = None ): self.name = name self.birth_date = birth_date self.death_date = death_date def set_name( self, first_name, last_name ): self.name = Name( first_name, last_name ) def set_birth_date( self, birth_day, birth_month, birth_year ): self.birth_date = Date( birth_date, birth_month, birth_year ) def set_death_date( self, death_day, death_month, death_year ): self.death_date = Date( death_day, death_month, death_year ) def get_name( self ): return self.name def get_birth_date( self ): return self.birth_date def get_death_date( self ): return self.death_date def __str__( self ): return "{}, {}, {}".format( self.name.__str__(), self.birth_date.__str__(), self.death_date.__str__() )
def __init__(self, name=None, minSuffixComponents=None, maxSuffixComponents=None, publisherPublicKeyDigest=None, exclude=None, childSelector=None, answerOriginKind=None, scope=None, interestLifetime=None, nonce=None): if isinstance(name, Name): self.name = name # Start from None to use for templates? else: self.name = Name(name) self.minSuffixComponents = minSuffixComponents # default 0 self.maxSuffixComponents = maxSuffixComponents # default infinity self.publisherPublicKeyDigest = publisherPublicKeyDigest # SHA256 hash self.exclude = exclude self.childSelector = childSelector self.answerOriginKind = answerOriginKind self.scope = scope self.interestLifetime = interestLifetime self.nonce = nonce
def receive_data(self, data, incoming_face): """ Receive data from the networking interfaces or application through face Add the data to the content store If there is any pending interest for the data is remaining then send the data to the face. Todo : Add the incoming face to the fib along with the name prefix. """ """ If the incoming data is safety message, send it to intrusion detection system and forward it to all the faces. """ data_type = data.get_content().get_tlv_type() if data_type in range(128,138): self.process_safety_message(data, incoming_face) name = data.get_name() cs = self.get_content_store() cs.add(name, data) return True pit = self.get_pending_interest_table() pending_interests = pit.get_all_interests() name = data.get_name() if pit.check_name_prefix(name): face_ids = pit.get_faces(name) for id in face_ids: face = self.get_face(id) self.send_data(face, data) pit.remove(name) cs = self.get_content_store() cs.add(Name(name), data)
def test_str(self): """ Test that str method returns a string representation of the object. """ # Create a Resource object resource = Resource(1, "White Noise", Name("Don", "", "DeLillo"), "Delillo's White Noise follows narrator Jack "\ "Gladney, a professor at a small Liberal Arts "\ "college and describes an academic year. Jack "\ "teaches at a school called the "\ "College-on-the-Hill, where he serves as the "\ "department chair of Hitler studies. He lives in "\ "Blacksmith, a quiet college town, with his wife, "\ "Babette, and four of their children from earlier "\ "marriages: Heinrich, Steffie, Denise, and "\ "Wilder. Throughout the novel, various "\ "half-siblings and ex-spouses drift in and out "\ "of the family’s home.", "sci-fi", "English", 1985, "US", 326, "book", ["culture", "survival", "life", "society"]) # Assert expected result of the str function self.assertEqual(str(resource), ("ID: 1 \nTitle: White Noise "\ "\nCreator: Don DeLillo \nSummary: Delillo's White Noise follows "\ "narrator Jack Gladney, a professor at a \nsmall Liberal Arts "\ "college and describes an academic year. Jack teaches \nat ... "\ "\nGenre: sci-fi \nLanguage: English \nYear: 1985 "\ "\nCountry: US \nLength: 326p \nType: book "\ "\nKeywords: culture, life, society, survival"))
def getName(self): if self.name is not None: return self.name else: fn = self.genLambdaName(); self.name = Name(fn, self.start, self.start + len('lambda')) self.addChildren(self.name) return self.name
def getDefaultKeyLocator(): context = ns.core.Simulator.GetContext() keyLocator = ns.ndnSIM.ndn.Name() keyLocator.\ append ("default-key").\ append (str (context)) return Name(keyLocator)
def clearInterestFilter(self, name): if not isinstance(name, Name): name = Name(name) self._acquire_lock("setInterestFilter") try: return _pyndn.clear_interest_filter(self.ndn_data, name.ndn_data) finally: self._release_lock("setInterestFilter")
def my_Name(self): frm = stack()[1] CallingModule = getmodule(frm[0]) SelfClassName = self.__class__.__name__ ConcClassProxy = proxy(self.__class__, SelfClassName + 'Name', CallingModule) NewProxy = ConcClassProxy(self.ConcAddr) NewName = Name(NewProxy, SelfClassName, CallingModule.__name__) return NewName
def get(self, name, template=None, timeoutms=3000): # if not _pyndn.is_upcall_executing(self.ndn_data): # raise Exception, "Get called outside of upcall" if not isinstance(name, Name): name = Name(name) self._acquire_lock("get") try: return _pyndn.get(self, name, template, timeoutms) finally: self._release_lock("get")
def test_repr(self): """ Test that the repr method returns an official representation of the object as a string. """ # Create a Name object and get the full name name = Name("Iain", "Robert", "Pears") # Assert expected result of the repr function self.assertEqual(repr(name), ("Name('Iain', 'Robert', 'Pears')"))
def test_count_characters(self, count_characters): self.assertEqual(Name.count_characters("Hello world"), { 'H': 1, 'e': 1, 'l': 3, 'o': 2, ' ': 1, 'w': 1, 'r': 1, 'd': 1 })
def expressInterestForLatest(self, name, onData, onTimeout=None, timeoutms=1.0): if not isinstance(name, Name): name = Name(name) self.expressInterest( name, Closure.VersionResolverClosure(self, onData, onTimeout), Interest.Interest(interestLifetime=timeoutms, childSelector=Interest.CHILD_SELECTOR_LEFT))
def __init__(self, name=None, content=None, signed_info=None): if isinstance(name, Name): self.name = name else: self.name = Name(name) self.content = content self.signedInfo = signed_info or SignedInfo() # generated self.signature = None
def test_str(self): """ Test that str method returns a string representation of the object. """ # Create a Name object and get the full name name = Name("Iain", "Robert", "Pears") # Assert expected result of the str function self.assertEqual(str(name), ("First Name: Iain\nMiddle Name: Robert"\ "\nLast Name: Pears"))
def match (pattern, name, flags=0): """ If zero or more characters at the beginning of string match the regular expression pattern, return a corresponding matches as a list. Return None if the string does not match the pattern. """ if not isinstance (name, Name): raise TypeError ("name is not ndn.Name type") m = RegexMatcher (pattern) res = m.matchN (Name (name)) if not res: return None return m
def change_contact(string): string = string.split(' ') name = string[1] number = string[2] if name == '' or number == '': return 'Give me name and number, please!' obj_name = Name(name) obj_phone = Phone(number) needed_record = address_book[obj_name.name] needed_record.add_phone(obj_phone) return f'Contact with name {name} changed number to {number}'
def __getattr__ (self, name): if name == "_interest": return object.__getattr__ (self, name) elif name == "name": return Name (self._interest.GetName ()) elif name == "scope": return self._interest.GetScope () elif name == "interestLifetime": return self._interest.GetInterestLifetime ().ToDouble (ns.core.Time.S) else: return self._interest.__getattribute__ (name)
def add_contact(string): string = string.split(' ') name = string[1] number = string[2] if name == '' or number == '': return 'Give me name and number, please!' obj_name = Name(name) obj_phone = Phone(number) obj_record = Record(obj_name) obj_record.add_phone(obj_phone) address_book.add_record(obj_record) return f'Contact with name {name} and number {number} was added'
def my_Name(self): ''' Returns a new Name for the Conc instance ''' SelfClassName = self.__class__.__name__ CallingModuleName = self.__class__.__module__ CallingModule = import_module(CallingModuleName) ConcClassProxy = proxy(self.__class__, SelfClassName + 'Name', CallingModule) NewProxy = ConcClassProxy(self.ConcAddr) NewName = Name(NewProxy, SelfClassName, CallingModuleName) return NewName
def test_str(self): """ Test that str method returns a string representation of the object. """ # Create a movie object movie = Movie("R",[Name("Stanley", "", "Kubrick"), Name("Anthony", "", "Burgess")], [Name("Malcolm", "", "McDowell"), Name("Patrick", "", "Magee"), Name("Michael", "", "Bates")], 2, "A clockwork Orange", Name("Stanley", "Kubrick"), "Protagonist Alex DeLarge is an ultraviolent youth in "\ "futuristic Britain. As with all luck, his eventually runs out "\ "and he's arrested and convicted of murder and rape. While in "\ "prison, Alex learns of an experimental program in which "\ "convicts are programmed to detest violence. If he goes "\ "through the program, his sentence will be reduced and he will "\ "be back on the streets sooner than expected. But Alex's "\ "ordeals are far from over once he hits the mean streets of "\ "Britain that he had a hand in creating.", "sci-fi", "English", 1971, "US", 136, "movie", ["dystopia", "violence", "alternate society"]) # Assert expected result of the str function self.assertEqual(str(movie), ("ID: 2 \nTitle: A clockwork Orange "\ "\nCreator: Stanley \nSummary: Protagonist Alex DeLarge is "\ "an ultraviolent youth in futuristic Britain. \nAs with all "\ "luck, his eventually runs out and he's arrested and "\ "convicted... \nGenre: sci-fi \nLanguage: English "\ "\nYear: 1971 \nCountry: US \nLength: 2h 16m \nType: movie "\ "\nKeywords: alternate society, dystopia, violence"\ "\nRating: R \nWriters: Stanley Kubrick, Anthony Burgess"\ "\nCast: Malcolm McDowell, Patrick Magee, Michael Bates "))
if (type(name) is not str): sys.exit("Name passed to StringName class is not of type " + con.strTypePython) if (len(name) == 0): sys.exit("Name passed to StringName class is of length zero.") self.name = name def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("StringName->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("StringName->setLineNo: line number passed in is less than one.") self.lineNo = lineNo def setDefaultValue(self, defaultValue): if (defaultValue == None): sys.exit("StringName->setDefaultValue: default value passed in is of None type.") self.defaultValue = defaultValue def setGroupType(self, groupType): if ( (groupType == None) or (type(groupType).__name__ != con.stringName) or (groupType.getStringVarName() not in con.groupTypes) ): sys.exit("StringName->setGroupType: problem with group type input parameter passed in.") self.groupType = groupType Name.register(StringName)
def __init__(self, nm, pn): self.name = Name(nm) self.phone = Phone(pn) print "Create a book entry for ",self.name.toString()
class NewAddrBookEntry(object): def __init__(self, nm, pn): self.name = Name(nm) self.phone = Phone(pn) print "Create a book entry for ",self.name.toString()
if (value == None): sys.exit("SubscriptName->setValue: value passed in is of None type.") #if ( (type(value).__name__ != con.stringName) and (type(value).__name__ != con.callValue) ): #sys.exit("SubscriptName->setValue: value passed in is not of type " + con.stringName + " or type " + con.callValue + ".") self.value = value def setSlice(self, slice): if ( (slice == None) or (type(slice).__name__ != con.sliceValue) ): sys.exit("SubscriptName->setSlice: problem with slice parameter passed in.") self.slice = slice def setLineNo(self, lineNo): if (type(lineNo) is not int): sys.exit("SubscriptName->setLineNo: line number passed in is not of type " + con.intTypePython) if (lineNo < 1): sys.exit("SubscriptName->setLineNo: line number passed in is less than one.") self.lineNo = lineNo def setGroupType(self, groupType): if ( (groupType == None) or (type(groupType).__name__ != con.stringName) or (groupType.getStringVarName() not in con.groupTypes) ): sys.exit("SubscriptName->setGroupType: problem with groupType input parameter.") self.groupType = groupType Name.register(SubscriptName)