当前位置: 首页>>代码示例>>Python>>正文


Python Name.appendSegment方法代码示例

本文整理汇总了Python中pyndn.Name.appendSegment方法的典型用法代码示例。如果您正苦于以下问题:Python Name.appendSegment方法的具体用法?Python Name.appendSegment怎么用?Python Name.appendSegment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyndn.Name的用法示例。


在下文中一共展示了Name.appendSegment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generateData

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import appendSegment [as 别名]
def generateData(baseName):
    '''
       This appends the segment number to the data name
    '''
    # just make up some data and return it
    ts = (time.time())
    segmentId = 0 # compatible with repo-ng test: may change to test segmented data

    versionComponent = baseName.get(-1) # should have a ts
    dataName = Name(baseName)
    dataName.appendSegment(segmentId)

    d = Data(dataName)
    content = "(" + str(ts) +  ") Data named " + dataName.toUri()
    d.setContent(content)
    d.getMetaInfo().setFinalBlockID(segmentId)
    d.getMetaInfo().setFreshnessPeriod(-1)
    if shouldSign:
        keychain.sign(d, certName)
    else:
        d.setSignature(fakeSignature)

    if shouldCollectStats:
        info = getInfoForVersion(versionComponent.toEscapedString())
        if info is not None:
            info['publish_time'] = ts

    return d
开发者ID:thecodemaiden,项目名称:nfd-timing,代码行数:30,代码来源:mcc-publisher.py

示例2: generateData

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import appendSegment [as 别名]
    def generateData(self, baseName):
        '''
           This appends the segment number to the data name, since repo-ng tends to expect it
        '''
        # just make up some data and return it
        ts = (time.time())
        segmentId = 0 # compatible with repo-ng test: may change to test segmented data

        versionStr = baseName.get(-1).toEscapedString()
        dataName = Name(baseName)
        dataName.appendSegment(segmentId)

        d = Data(dataName)
        content = "(" + str(ts) +  ") Data named " + dataName.toUri()
        d.setContent(content)
        d.getMetaInfo().setFinalBlockID(segmentId)
        d.getMetaInfo().setFreshnessPeriod(-1)
        if shouldSign:
            self.keychain.sign(d, self.certificateName)
        else:
            d.setSignature(self.fakeSignature)

        stats.insertDataForVersion(versionStr, {'publish_time':time.time()})
        logger.debug('Publishing: '+d.getName().toUri())
        return d
开发者ID:thecodemaiden,项目名称:nfd-timing,代码行数:27,代码来源:mcc-event-publisher.py

示例3: onDataInterest

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import appendSegment [as 别名]
def onDataInterest(prefix, interest, transport, pxID):
    '''
       For publishing face
    '''
    # just make up some data and return it
    interestName = interest.getName()
    logger.info("Interest for " + interestName.toUri())

    ## CURRENTLY ASSUMES THERE'S A VERSION/SEGMENT SUFFIX!
    dataName = Name(interestName.getPrefix(-1))
    ts = (time.time())
    segmentId = 0
    try:
       segmentId = interestName().get(-1).toSegment()
    except:
        logger.debug("Could not find segment id!")
    dataName.appendSegment(segmentId)

    versionStr = interestName.get(-2).getValue().toRawStr()
    logger.debug('publishing ' + versionStr)
    info = getInfoForVersion(versionStr)

    d = Data(dataName)
    content = "(" + str(ts) +  ") Data named " + dataName.toUri()
    d.setContent(content)
    d.getMetaInfo().setFinalBlockID(segmentId)
    keychain.sign(d, certName)

    encodedData = d.wireEncode()
    now = time.time()

    if info is not None:
        info['publish_time'] = now
    transport.send(encodedData.toBuffer())
开发者ID:thecodemaiden,项目名称:nfd-timing,代码行数:36,代码来源:repo-publisher.py

示例4: main

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import appendSegment [as 别名]
def main():
    seg = 0
    if len(sys.argv) < 3:
        print("argv error: please input capture or capture with #seg")
        exit(1)
    elif len(sys.argv) == 2:
        cmd = sys.argv[1]
    else:
        cmd = sys.argv[1]
        seg = sys.argv[2]

    loop = asyncio.get_event_loop()
    #face = ThreadsafeFace(loop, "localhost")
    face = Face("localhost")
    # Counter will stop the ioService after callbacks for all expressInterest.
    counter = Counter(loop, 3)

    seed = HMACKey(0,0,"seed","seedName")

    # Try to fetch anything.
    import time
    r = time.time()

    name1 = Name("/home/security/camera/0/"+cmd)
    name1.appendTimestamp(int(r))
    name1.appendSegment(int(seg))

    
    interest = Interest(name1)
    interest.setInterestLifetimeMilliseconds(3000)
    dump("Express name ", interest.toUri())
    face.expressInterest(interest, counter.onData, counter.onTimeout)
    
    """
    name2 = Name("/home/sensor/LED/T0829374723/turnOff")
    dump("Express name ", name2.toUri())
    face.expressInterest(name2, counter.onData, counter.onTimeout)
    """


    while counter._callbackCount < 1:
        face.processEvents()
        # We need to sleep for a few milliseconds so we don't use 100% of the CPU.
        time.sleep(2)

    face.shutdown()
开发者ID:philoL,项目名称:NDN-HOME,代码行数:48,代码来源:test_camera.py

示例5: test_append

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import appendSegment [as 别名]
    def test_append(self):
        # could possibly split this into different tests
        uri = "/localhost/user/folders/files/%00%0F"
        name = Name(uri)
        name2 = Name("/localhost").append(Name("/user/folders/"))
        self.assertEqual(len(name2), 3, 'Name constructed by appending names has ' + str(len(name2)) + ' components instead of 3')
        self.assertTrue(name2[2].getValue() == Blob("folders"), 'Name constructed with append has wrong suffix')
        name2 = name2.append("files")
        self.assertEqual(len(name2), 4, 'Name constructed by appending string has ' + str(len(name2)) + ' components instead of 4')
        name2 = name2.appendSegment(15)
        self.assertTrue(name2[4].getValue() == Blob(bytearray([0x00, 0x0F])), 'Name constructed by appending segment has wrong segment value')

        self.assertTrue(name2 == name, 'Name constructed with append is not equal to URI constructed name')
        self.assertEqual(name2.toUri(), name.toUri(), 'Name constructed with append has wrong URI')
开发者ID:MAHIS,项目名称:PyNDN2,代码行数:16,代码来源:test_name_methods.py

示例6: AssertionError

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import appendSegment [as 别名]
		raise AssertionError("Got a different output: '%s' != '%s'" % (comp1, comp2))

n = Name(['hello', 'world'])

print(str(n))
if str(n) != "/hello/world":
	raise AssertionError("expected /hello/world")

n = Name("ndn:///testing/1/2/3/")
print(str(n))
if str(n) != "/testing/1/2/3":
	raise AssertionError("expected /testing/1/2/3 got: " + str(n))

if len(n) != 4:
	raise AssertionError("expected 4 components, got: " + len(n))

print(n.components)
assert(n.components == [b'testing', b'1', b'2', b'3'])

n = Name([1, '2', bytearray(b'3'), bytes(b'4')])
print(str(n))
assert(str(n) == "/1/2/3/4")

n = Name()
print(str(n))
n = n.appendSegment(5)
print(str(n))

assert(str(n) == "/%00%05")

开发者ID:MAHIS,项目名称:PyNDN,代码行数:31,代码来源:names.py


注:本文中的pyndn.Name.appendSegment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。