Esempio n. 1
0
 def get(self, key):
         """ GETs a file from the server """
         sock = self._connect()
         f = sock.makefile()
         f.write(struct.pack("B", BERTHA_GET))
         f.write(from_hex(key))
         f.flush()
         sock.shutdown(socket.SHUT_WR)
         return f
Esempio n. 2
0
 def size(self, key):
         """ Returns the size of the blob on the server.
             When the file does not exist, a KeyError is raised. """
         sock = self._connect()
         f = sock.makefile()
         f.write(struct.pack("B", BERTHA_SIZE))
         f.write(from_hex(key))
         f.flush()
         sock.shutdown(socket.SHUT_WR)
         raw_size = f.read(8)
         if len(raw_size) == 0:
                 raise KeyError
         size = struct.unpack("<Q", raw_size)[0]
         return size
Esempio n. 3
0
 def sget(self, key):
         """ SGETs a file from the server.  That is: a pair (fd, s)
             is returned, where fd is a file object to read from
             and s is the length of fd """
         sock = self._connect()
         f = sock.makefile()
         f.write(struct.pack("B", BERTHA_SGET))
         f.write(from_hex(key))
         f.flush()
         sock.shutdown(socket.SHUT_WR)
         raw_size = f.read(8)
         if len(raw_size) == 0:
                 raise KeyError
         size = struct.unpack("<Q", raw_size)[0]
         return (f, size)