當前位置: 首頁>>代碼示例>>Python>>正文


Python Repo.extract_from_repo方法代碼示例

本文整理匯總了Python中repo.Repo.extract_from_repo方法的典型用法代碼示例。如果您正苦於以下問題:Python Repo.extract_from_repo方法的具體用法?Python Repo.extract_from_repo怎麽用?Python Repo.extract_from_repo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在repo.Repo的用法示例。


在下文中一共展示了Repo.extract_from_repo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: RepoServer

# 需要導入模塊: from repo import Repo [as 別名]
# 或者: from repo.Repo import extract_from_repo [as 別名]
class RepoServer(object):
    def __init__(self, keyChain, certificateName):
        self._keyChain = keyChain
        self._certificateName = certificateName
        self.repo = Repo()

    def onInterest(self, prefix, interest, transport, registeredPrefixId):
        print 'Interest received: %s' % interest.getName().toUri()

        # Make and sign a Data packet.
        encoded_data = self.repo.extract_from_repo(interest)
        if not encoded_data:
            data = Data(interest.getName())
            content = "No match found"
            data.setContent(content)
            self._keyChain.sign(data, self._certificateName)
            encoded_data = data.wireEncode().toBuffer()
        else:
            dumpData(encoded_data)
            encoded_data = encoded_data.wireEncode().toBuffer()

        transport.send(encoded_data)
        print 'sent'

    def onRegisterFailed(self, prefix):
        dump("Register failed for prefix", prefix.toUri())
開發者ID:remap,項目名稱:BMS-REPO,代碼行數:28,代碼來源:server.py

示例2: BenchmarkRepo

# 需要導入模塊: from repo import Repo [as 別名]
# 或者: from repo.Repo import extract_from_repo [as 別名]
class BenchmarkRepo(object):

    def __init__(self, clear=False):
        self.repo = Repo(clear=clear)

    def benchmark_write(self):
        name = "/ndn/ucla.edu/bms/building:melnitz/room:1451/seg0"
        content = "melnitz.1451.seg0"
        data = self.repo.wrap_content(name, content)
        data_size = getsizeof(data)

        volume = 0
        start_time = datetime.now()
        for i in range(100):
            self.repo.add_content_object_to_repo(name, data)
            volume += data_size
        finish_time = datetime.now()
        duration = finish_time - start_time
        print duration, volume

    def benchmark_read(self):
        # the graph db is queried 2 times per read if does not 
        # apply selectors. otherwise 4 times queries are needed
        name = "/ndn/ucla.edu/bms/building:melnitz/room:1451/seg0"
        content = "melnitz.1451.seg0"
        interest = Interest(Name(name))
        data = self.repo.wrap_content(name, content)
        data_size = getsizeof(data)

        volume = 0
        start_time = datetime.now()
        for i in range(1):
            self.repo.extract_from_repo(interest)
            volume += data_size
        finish_time = datetime.now()
        duration = finish_time - start_time
        print duration, volume

    def run_benchmark(self):
#        self.benchmark_write()
        self.benchmark_read()
開發者ID:remap,項目名稱:BMS-REPO,代碼行數:43,代碼來源:benchmark.py


注:本文中的repo.Repo.extract_from_repo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。