示例#1
0
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
示例#2
0
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)))
示例#3
0
    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)
示例#4
0
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
示例#5
0
    def test_equality(self):
        A = Name.parse('Neil deGrasse Tyson')
        B = Name('Neil', 'D', 'Tyson')
        C = Name('NEIL', None, 'TYSON')
        D = Name('Neil', 'DEGRASSE', 'Tyson')
        E = Name('Bob', None, 'Ross')

        self.assertTrue(A.equal_primary(B))
        self.assertTrue(C.equal_primary(B))

        self.assertTrue(A.equal_middle_full(D))
        self.assertFalse(B.equal_middle_full(A))
        self.assertTrue(B.equal_middle_initial(A))

        self.assertFalse(D.equal_middle_full(C))
        self.assertFalse(D.equal_middle_initial(C))
示例#6
0
 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"))
示例#7
0
    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
示例#8
0
    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)
示例#9
0
    def setInterestFilter(self, name, onInterest, flags=None):
        if not isinstance(name, Name):
            name = Name(name)

        self._setInterestFilter(name,
                                Closure.TrivialFilterClosure(name, onInterest),
                                flags)
示例#10
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 ...")
示例#11
0
    def __init__(self, keyName=None):
        if isinstance(keyName, Name):
            self.keyName = keyName
        else:
            self.keyName = Name(keyName)

        self.ndn_data = None
示例#12
0
    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)
示例#13
0
    def getDefaultKeyLocator():
        context = ns.core.Simulator.GetContext()
        keyLocator = ns.ndnSIM.ndn.Name()
        keyLocator.\
            append ("default-key").\
            append (str (context))

        return Name(keyLocator)
示例#14
0
 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
示例#15
0
    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 getNameAccount(self):

        name = Name()

        print("¿Cómo se llama?")
        inName = input()
        print(f"Bienvenido, {inName}")
        name.name = inName

        return name
示例#18
0
    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')"))
示例#19
0
    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"))
示例#20
0
    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
示例#21
0
 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))
示例#22
0
    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")
示例#23
0
    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
示例#24
0
    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"))
示例#25
0
    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)
示例#26
0
文件: nre.py 项目: SaadASA/maxmindz
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
示例#27
0
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}'
示例#28
0
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'
示例#29
0
    def test_get_names_string(self):
        """
        Test that get_names_string returns a string that contains a list of 
        names.
        """

        # 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
        self.assertEqual(movie.get_names_string(movie.cast),
                         "Malcolm McDowell, Patrick Magee, Michael Bates")
示例#30
0
    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 "))