Ejemplo n.º 1
0
 def fill_blog(self, peer_id, blog, flag_update=True):
     """stores CacheDocument associated with peer"""
     blog = retro_compatibility(blog)
     if not isinstance(blog, Blogs):
         raise TypeError("data expected as AbstractDocument")
     # set peer_desc
     if not self.has_peer(peer_id):
         peer_desc = PeerDescriptor(peer_id, blog=blog)
         self.set_peer(peer_id, peer_desc)
     else:
         peer_desc = self.get_peer(peer_id)
     # set blog
     peer_desc.blog = blog
     self.last_downloaded_desc = flag_update and peer_desc or None
     return peer_desc
Ejemplo n.º 2
0
        return peer_desc

    def fill_data(self, (peer_id, document)):
        """stores CacheDocument associated with peer"""
        if not self.has_peer(peer_id):
            peer_desc = PeerDescriptor(document.pseudo, document=document)
            self.set_peer((peer_id, peer_desc))
        else:
            peer_desc = self.get_peer(peer_id)
        peer_desc.set_document(document)
        self.last_downloaded_desc = peer_desc
        return peer_desc

    def fill_blog(self, (peer_id, blog)):
        """stores CacheDocument associated with peer"""
        blog = retro_compatibility(blog)
        if not isinstance(blog, Blogs):
            raise TypeError("data expected as AbstractDocument")
        if not self.has_peer(peer_id):
            peer_desc = PeerDescriptor(blog.pseudo, blog=blog)
            self.set_peer((peer_id, peer_desc))
        else:
            peer_desc = self.get_peer(peer_id)
        peer_desc.set_blog(blog)
        self.last_downloaded_desc = peer_desc
        return peer_desc
            
    def fill_shared_files(self, (peer_id, files)):
        """connect shared files with shared files"""
        if not isinstance(files, SharedFiles):
            raise TypeError("data expected as SharedFiles")