Пример #1
0
 def testDecodeDecompressedSizeLimit(self):
     import zlib
     from ZTUtils.Tree import b2a
     big = b2a(zlib.compress(b'x' * (1024 * 1100)))
     self.assertTrue(len(big) < 8192)  # Must be under the input size limit
     with self.assertRaises(ValueError):
         Tree.decodeExpansion(b':' + big)
Пример #2
0
 def afterSetUp(self):
     environ = {"SERVER_NAME": "", "SERVER_PORT": "0"}
     response = HTTPResponse(stdout=BytesIO())
     request = HTTPRequest(BytesIO(), environ, response)
     self.varname = "tree-expansion"
     # emulate a cookie
     tree_expansion = ":".join(expanded_nodes).encode("utf-8")
     request.other[self.varname] = b2a(zlib.compress(tree_expansion))
     self.request = request
     self.items = {}
     self.root_obj = make_item_from_tuple(tree, self.items)
     self.tree = ZopeTree(self.root_obj, "id", "children", request,
                          self.varname)
Пример #3
0
 def encodeTreeExpansion(self, expanded_nodes):
     tree_expansion = ":".join(expanded_nodes)
     if not isinstance(tree_expansion, bytes):
         tree_expansion = tree_expansion.encode("utf-8")
     tree_expansion = zlib.compress(tree_expansion)
     return b2a(tree_expansion)
Пример #4
0
 def _callFUT(self, value):
     from ZTUtils.Tree import b2a
     return b2a(value)
Пример #5
0
 def testDecodeDecompressedSizeLimit(self):
     import zlib
     from ZTUtils.Tree import b2a, a2b, encodeExpansion, decodeExpansion
     big = b2a(zlib.compress('x' * (1024*1100)))
     self.assert_(len(big) < 8192) # Must be under the input size limit
     self.assertRaises(ValueError, Tree.decodeExpansion, ':' + big)
Пример #6
0
 def encodeTreeExpansion(self, expanded_nodes):
     string1 = expanded_nodes
     string1 = zlib.compress(string1)
     return b2a(string1)