示例#1
0
 def test_set_links_all_links(self):
     bucket = self.client.bucket("bucket")
     foo1 = bucket.new("foo", 1)
     foo2 = bucket.new("foo2", 2).store()
     links = [RiakLink("bucket", "foo2")]
     foo1.set_links(links, True)
     links = foo1.get_links()
     self.assertEqual(len(links), 1)
     self.assertEqual(links[0].get_key(), "foo2")
示例#2
0
    def test_too_many_link_headers_shouldnt_break_http(self):
        bucket = self.client.bucket("bucket")
        o = bucket.new("lots_of_links", "My god, it's full of links!")
        for i in range(0, 400):
            link = RiakLink("other", "key%d" % i, "next")
            o.add_link(link)

        o.store()
        stored_object = bucket.get("lots_of_links")
        self.assertEqual(len(stored_object.get_links()), 400)
示例#3
0
 def parse_links(self, links, linkHeaders) :
     """
     Private.
     @return self
     """
     for linkHeader in linkHeaders.strip().split(','):
         linkHeader = linkHeader.strip()
         matches = re.match("\<\/([^\/]+)\/([^\/]+)\/([^\/]+)\>; ?riaktag=\"([^\']+)\"", linkHeader)
         if (matches is not None):
             link = RiakLink(matches.group(2), matches.group(3), matches.group(4))
             links.append(link)
     return self
示例#4
0
    def links(self, riakLinks=False):
        """Gets all the links.

    Args:
      riakLinks: Defaults to False. If True, it will return a list of RiakLinks

    Returns:
      A set of (document, tag) or [RiakLink, RiakLink]"""
        if riakLinks:
            return [
                RiakLink(self.bucket_name[0], d.key, t) for d, t in self._links
            ]
        return copy(self._links)
示例#5
0
    def links(self, bucket=None):
        """Gets all the links.

    Args:
      bucket: Defaults to None. If it is a RiakBucket, this will return a list of RiakLinks instead of (document, tag) in a set

    Returns:
      A set of (document, tag) or [RiakLink, RiakLink]"""
        if bucket is not None:
            return [
                RiakLink(bucket.get_name(), d.key, t) for d, t in self._links
            ]
        return copy(self._links)
示例#6
0
 def test_set_links(self):
     # Create the object
     bucket = self.client.bucket("bucket")
     bucket.new("foo", 2).set_links([
         bucket.new("foo1"), (bucket.new("foo2"), "tag"),
         RiakLink("bucket", "foo2", "tag2")
     ]).store()
     obj = bucket.get("foo")
     links = sorted(obj.get_links(), key=lambda x: x.get_key())
     self.assertEqual(len(links), 3)
     self.assertEqual(links[0].get_key(), "foo1")
     self.assertEqual(links[1].get_key(), "foo2")
     self.assertEqual(links[1].get_tag(), "tag")
     self.assertEqual(links[2].get_key(), "foo2")
     self.assertEqual(links[2].get_tag(), "tag2")
示例#7
0
 def parse_links(self, links, linkHeaders):
     """
     Private.
     @return self
     """
     for linkHeader in linkHeaders.strip().split(','):
         linkHeader = linkHeader.strip()
         matches = re.match("</([^/]+)/([^/]+)/([^/]+)>; ?riaktag=\"([^\']+)\"", linkHeader) or \
             re.match("</(buckets)/([^/]+)/keys/([^/]+)>; ?riaktag=\"([^\']+)\"", linkHeader)
         if matches is not None:
             link = RiakLink(urllib.unquote_plus(matches.group(2)),
                             urllib.unquote_plus(matches.group(3)),
                             urllib.unquote_plus(matches.group(4)))
             links.append(link)
     return self
示例#8
0
 def decode_content(self, rpb_content):
     metadata = {}
     if rpb_content.HasField("deleted"):
         metadata[MD_DELETED] = True
     if rpb_content.HasField("content_type"):
         metadata[MD_CTYPE] = rpb_content.content_type
     if rpb_content.HasField("charset"):
         metadata[MD_CHARSET] = rpb_content.charset
     if rpb_content.HasField("content_encoding"):
         metadata[MD_ENCODING] = rpb_content.content_encoding
     if rpb_content.HasField("vtag"):
         metadata[MD_VTAG] = rpb_content.vtag
     links = []
     for link in rpb_content.links:
         if link.HasField("bucket"):
             bucket = link.bucket
         else:
             bucket = None
         if link.HasField("key"):
             key = link.key
         else:
             key = None
         if link.HasField("tag"):
             tag = link.tag
         else:
             tag = None
         links.append(RiakLink(bucket, key, tag))
     if links:
         metadata[MD_LINKS] = links
     if rpb_content.HasField("last_mod"):
         metadata[MD_LASTMOD] = rpb_content.last_mod
     if rpb_content.HasField("last_mod_usecs"):
         metadata[MD_LASTMOD_USECS] = rpb_content.last_mod_usecs
     usermeta = {}
     for usermd in rpb_content.usermeta:
         usermeta[usermd.key] = usermd.value
     if len(usermeta) > 0:
         metadata[MD_USERMETA] = usermeta
     indexes = []
     for index in rpb_content.indexes:
         rie = RiakIndexEntry(index.key, index.value)
         indexes.append(rie)
     if len(indexes) > 0:
         metadata[MD_INDEX] = indexes
     return metadata, rpb_content.value
示例#9
0
 def decode_content(self, rpb_content):
     metadata = {}
     if rpb_content.HasField("content_type"):
         metadata[MD_CTYPE] = rpb_content.content_type
     if rpb_content.HasField("charset"):
         metadata[MD_CHARSET] = rpb_content.charset
     if rpb_content.HasField("content_encoding"):
         metadata[MD_ENCODING] = rpb_content.content_encoding
     if rpb_content.HasField("vtag"):
         metadata[MD_VTAG] = rpb_content.vtag
     links = []
     for link in rpb_content.links:
         if link.HasField("bucket"):
             bucket = link.bucket
         else:
             bucket = None
         if link.HasField("key"):
             key = link.key
         else:
             key = None
         if link.HasField("tag"):
             tag = link.tag
         else:
             tag = None
         links.append(RiakLink(bucket, key, tag))
     if links != []:
         metadata[MD_LINKS] = links
     if rpb_content.HasField("last_mod"):
         metadata[MD_LASTMOD] = rpb_content.last_mod
     if rpb_content.HasField("last_mod_usecs"):
         metadata[MD_LASTMOD_USECS] = rpb_content.last_mod_usecs
     usermeta = {}
     for usermd in rpb_content.usermeta:
         usermeta[usermd.key] = usermd.value
     if len(usermeta) > 0:
         metadata[MD_USERMETA] = usermeta
     return (metadata, rpb_content.value)