~ubuntuone-control-tower/ubuntuone-storage-protocol/stable-1-2

« back to all changes in this revision

Viewing changes to ubuntuone/storageprotocol/client.py

  • Committer: Tarmac
  • Author(s): natalia.bidart at canonical
  • Date: 2010-03-15 13:58:53 UTC
  • mfrom: (87.1.1 stop-shadowing-hash)
  • Revision ID: dobey@wayofthemonkey.com-20100315135853-xujvc9nyi1km84ib
Avoiding shadowing builtin hash.

Show diffs side-by-side

added added

removed removed

Lines of Context:
164
164
            elif msg.type == protocol_pb2.Volumes.UDF:
165
165
                vol = volumes.UDFVolume.from_msg(msg.udf)
166
166
            else:
167
 
                raise TypeError("Message.volume_created's type is not valid: %s" %
168
 
                                message.volume_created.type)
 
167
                msg = "Message.volume_created's type is not valid: %s" % \
 
168
                      message.volume_created.type
 
169
                raise TypeError(msg)
169
170
 
170
171
            self._volume_created_callback(vol)
171
172
 
235
236
        p.start()
236
237
        return p.deferred
237
238
 
238
 
    def get_content(self, share, node, hash, offset=0,
 
239
    def get_content(self, share, node, a_hash, offset=0,
239
240
                    callback=None, node_attr_callback=None):
240
 
        """Get the content of node with hash
 
241
        """Get the content of node with 'a_hash'.
241
242
 
242
243
        the content will be on request.content
243
244
        or callback will be called for every piece that arrives.
244
245
 
245
246
        """
246
 
        req = self.get_content_request(share, node, hash, offset,
 
247
        req = self.get_content_request(share, node, a_hash, offset,
247
248
                                       callback, node_attr_callback)
248
249
        return req.deferred
249
250
 
250
 
    def get_content_request(self, share, node, hash, offset=0,
 
251
    def get_content_request(self, share, node, a_hash, offset=0,
251
252
                            callback=None, node_attr_callback=None):
252
 
        """Get the content of node with hash, return the request.
 
253
        """Get the content of node with 'a_hash', return the request.
253
254
 
254
255
        The content will be on request.content, or callback will be
255
256
        called for every piece that arrives.
256
257
 
257
258
        """
258
 
        p = GetContent(self, share, node, hash, offset,
259
 
                                        callback, node_attr_callback)
 
259
        p = GetContent(self, share, node, a_hash, offset,
 
260
                       callback, node_attr_callback)
260
261
        p.start()
261
262
        return p
262
263
 
263
 
    def put_content(self, share, node, previous_hash, hash,
 
264
    def put_content(self, share, node, previous_hash, new_hash,
264
265
                    crc32, size, deflated_size, fd):
265
266
        """Put the content of fd into file node."""
266
 
        req = self.put_content_request(share, node, previous_hash,
267
 
                                       hash, crc32, size, deflated_size, fd)
 
267
        req = self.put_content_request(share, node, previous_hash, new_hash,
 
268
                                       crc32, size, deflated_size, fd)
268
269
        return req.deferred
269
270
 
270
 
    def put_content_request(self, share, node, previous_hash, hash,
 
271
    def put_content_request(self, share, node, previous_hash, new_hash,
271
272
                            crc32, size, deflated_size, fd):
272
273
        """Put the content of fd into file node, return the request."""
273
 
        p = PutContent(self, share, node, previous_hash, hash, crc32, size,
274
 
                                                            deflated_size, fd)
 
274
        p = PutContent(self, share, node, previous_hash, new_hash,
 
275
                       crc32, size, deflated_size, fd)
275
276
        p.start()
276
277
        return p
277
278
 
278
279
    def query(self, items):
279
 
        """Get the current hash for items if changed
 
280
        """Get the current hash for items if changed.
280
281
 
281
 
        items is a list of (node, hash) tuples.
 
282
        'items' is a list of (node, hash) tuples.
282
283
 
283
284
        """
284
285
        r = MultiQuery(self, items)
510
511
 
511
512
    """
512
513
 
513
 
    def __init__(self, protocol, share, node_id, hash,
 
514
    def __init__(self, protocol, share, node_id, a_hash,
514
515
                 offset=0, callback=None, node_attr_callback=None):
515
 
        """Request the content of node with hash.
 
516
        """Request the content of node with 'a_hash'.
516
517
 
517
518
        @param protocol: the request handler
518
519
        @param share: the share node or root
519
520
        @param node_id: the node id of the node we want to read
520
 
        @param hash: the hash of the content of the version we have
 
521
        @param a_hash: the hash of the content of the version we have
521
522
        @param offset: offset for reading
522
523
        @param callback: function to call when data arrives
523
524
 
525
526
        request.Request.__init__(self, protocol)
526
527
        self.share = share
527
528
        self.node_id = node_id
528
 
        self.hash = hash
 
529
        self.hash = a_hash
529
530
        self.offset = offset
530
531
        self.callback = callback
531
532
        self.node_attr_callback = node_attr_callback
981
982
 
982
983
        def add_items(msg, *args):
983
984
            """Add items to query."""
984
 
            for share, node, hash in args:
 
985
            for share, node, content_hash in args:
985
986
                qi = msg.query.add()
986
987
                qi.share = share
987
988
                qi.node = str(node)
988
 
                qi.hash = hash
 
989
                qi.hash = content_hash
989
990
 
990
991
        for item in items:
991
992
            add_items(qm, item)
1073
1074
    """Put content request."""
1074
1075
 
1075
1076
    def __init__(self, protocol, share, node_id,
1076
 
                 previous_hash, hash, crc32, size,
 
1077
                 previous_hash, new_hash, crc32, size,
1077
1078
                 deflated_size, fd):
1078
1079
        """Put content into a node.
1079
1080
 
1081
1082
        @param share: the share node or root
1082
1083
        @param node_id: the node to receive the content
1083
1084
        @param previous_hash: the hash the node has (for conflict checking)
1084
 
        @param hash: the hash hint for the new content
 
1085
        @param new_hash: the hash hint for the new content
1085
1086
        @param crc32: the crc32 hint for the new content
1086
1087
        @param size: the size hint for the new content
1087
1088
        @param fd: a file-like object to read data from
1091
1092
        self.share = share
1092
1093
        self.node_id = node_id
1093
1094
        self.previous_hash = previous_hash
1094
 
        self.hash = hash
 
1095
        self.hash = new_hash
1095
1096
        self.crc32 = crc32
1096
1097
        self.size = size
1097
1098
        self.deflated_size = deflated_size