Merge lp:~ubuntuone-control-tower/ubuntu/lucid/ubuntuone-storage-protocol/trunk into lp:ubuntu/lucid/ubuntuone-storage-protocol
- Lucid (10.04)
- trunk
- Merge into lucid
Proposed by
dobey
on 2010-03-31
| Status: | Merged |
|---|---|
| Merged at revision: | not available |
| Proposed branch: | lp:~ubuntuone-control-tower/ubuntu/lucid/ubuntuone-storage-protocol/trunk |
| Merge into: | lp:ubuntu/lucid/ubuntuone-storage-protocol |
| Diff against target: |
492 lines (+125/-83) 10 files modified
PKG-INFO (+1/-1) debian/changelog (+13/-0) debian/control (+5/-4) debian/source/format (+2/-0) setup.py (+12/-9) ubuntuone/__init__.py (+5/-4) ubuntuone/storageprotocol/client.py (+27/-26) ubuntuone/storageprotocol/context.py (+21/-8) ubuntuone/storageprotocol/hash.py (+26/-24) ubuntuone/storageprotocol/validators.py (+13/-7) |
| To merge this branch: | bzr merge lp:~ubuntuone-control-tower/ubuntu/lucid/ubuntuone-storage-protocol/trunk |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Ubuntu branches | 2010-03-31 | Pending | |
|
Review via email:
|
|||
Commit Message
Description of the Change
To post a comment you must log in.
lp:~ubuntuone-control-tower/ubuntu/lucid/ubuntuone-storage-protocol/trunk
updated
on 2010-03-31
- 14. By Luke Yelavich on 2010-03-31
-
* New upstream release.
* Added debian/source/ format.
* Add Build-Depened on python-openssl (LP: #539809) - 15. By Luke Yelavich on 2010-03-31
-
releasing version 1.1.90-0ubuntu1
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === modified file 'PKG-INFO' |
| 2 | --- PKG-INFO 2010-03-04 16:16:33 +0000 |
| 3 | +++ PKG-INFO 2010-03-31 23:47:26 +0000 |
| 4 | @@ -1,6 +1,6 @@ |
| 5 | Metadata-Version: 1.0 |
| 6 | Name: ubuntuone-storage-protocol |
| 7 | -Version: 1.1.3 |
| 8 | +Version: 1.1.90 |
| 9 | Summary: UNKNOWN |
| 10 | Home-page: UNKNOWN |
| 11 | Author: UNKNOWN |
| 12 | |
| 13 | === modified file 'debian/changelog' |
| 14 | --- debian/changelog 2010-03-05 14:14:58 +0000 |
| 15 | +++ debian/changelog 2010-03-31 23:47:26 +0000 |
| 16 | @@ -1,3 +1,16 @@ |
| 17 | +ubuntuone-storage-protocol (1.1.90-0ubuntu1) UNRELEASED; urgency=low |
| 18 | + |
| 19 | + * New upstream release. |
| 20 | + * Added debian/source/format. |
| 21 | + |
| 22 | + -- Rodney Dawes <rodney.dawes@canonical.com> Wed, 31 Mar 2010 19:40:44 -0400 |
| 23 | + |
| 24 | +ubuntuone-storage-protocol (1.1.3-0ubuntu2) lucid; urgency=low |
| 25 | + |
| 26 | + * Add Build-Depened on python-openssl (LP: #539809) |
| 27 | + |
| 28 | + -- Rodney Dawes <rodney.dawes@canonical.com> Tue, 16 Mar 2010 16:12:50 -0400 |
| 29 | + |
| 30 | ubuntuone-storage-protocol (1.1.3-0ubuntu1) lucid; urgency=low |
| 31 | |
| 32 | * New upstream release. |
| 33 | |
| 34 | === modified file 'debian/control' |
| 35 | --- debian/control 2010-03-04 16:27:48 +0000 |
| 36 | +++ debian/control 2010-03-31 23:47:26 +0000 |
| 37 | @@ -6,12 +6,13 @@ |
| 38 | XSBC-Original-Maintainer: Rick McBride <rick.mcbride@canonical.com> |
| 39 | Build-Depends: debhelper (>= 5), |
| 40 | cdbs, |
| 41 | - python-all-dev (>= 2.5) |
| 42 | -Build-Depends-Indep: protobuf-compiler (> 2.0.3-0ubuntu1), |
| 43 | + python-all (>= 2.5) |
| 44 | +Build-Depends-Indep: protobuf-compiler (>> 2.0.3-0ubuntu1), |
| 45 | python-central, |
| 46 | python-twisted-core, |
| 47 | - python-oauth (>= 1.0~svn1092) |
| 48 | -Standards-Version: 3.8.3 |
| 49 | + python-oauth (>= 1.0~svn1092), |
| 50 | + python-openssl |
| 51 | +Standards-Version: 3.8.4 |
| 52 | Homepage: https://one.ubuntu.com |
| 53 | |
| 54 | Package: python-ubuntuone-storageprotocol |
| 55 | |
| 56 | === added directory 'debian/source' |
| 57 | === added file 'debian/source/format' |
| 58 | --- debian/source/format 1970-01-01 00:00:00 +0000 |
| 59 | +++ debian/source/format 2010-03-31 23:47:26 +0000 |
| 60 | @@ -0,0 +1,2 @@ |
| 61 | +3.0 (quilt) |
| 62 | + |
| 63 | |
| 64 | === modified file 'setup.py' |
| 65 | --- setup.py 2010-03-04 16:16:33 +0000 |
| 66 | +++ setup.py 2010-03-31 23:47:26 +0000 |
| 67 | @@ -3,13 +3,13 @@ |
| 68 | # |
| 69 | # Copyright 2009 Canonical Ltd. |
| 70 | # |
| 71 | -# This program is free software: you can redistribute it and/or modify it |
| 72 | +# This program is free software: you can redistribute it and/or modify it |
| 73 | # under the terms of the GNU Affero General Public License version 3, |
| 74 | # as published by the Free Software Foundation. |
| 75 | # |
| 76 | -# This program is distributed in the hope that it will be useful, but |
| 77 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 78 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 79 | +# This program is distributed in the hope that it will be useful, but |
| 80 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 81 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 82 | # PURPOSE. See the GNU Affero General Public License for more details. |
| 83 | # |
| 84 | # You should have received a copy of the GNU Affero General Public License |
| 85 | @@ -33,6 +33,8 @@ |
| 86 | except ImportError: |
| 87 | from contrib import check |
| 88 | |
| 89 | +from ubuntuone.storageprotocol.context import ssl_cert_location |
| 90 | + |
| 91 | class StorageProtocolBuild(build.build): |
| 92 | """Class to build the protobuf files.""" |
| 93 | |
| 94 | @@ -45,7 +47,7 @@ |
| 95 | sys.stderr.write("*** Cannot find protoc; is the protobuf-compiler " |
| 96 | "package installed?\n") |
| 97 | sys.exit(-1) |
| 98 | - |
| 99 | + |
| 100 | for source in glob.glob("ubuntuone/storageprotocol/*.proto"): |
| 101 | protoc_command = protoc + " --python_out=. " + source |
| 102 | if os.system(protoc_command) != 0: |
| 103 | @@ -119,16 +121,17 @@ |
| 104 | |
| 105 | |
| 106 | setup(name='ubuntuone-storage-protocol', |
| 107 | - version='1.1.3', |
| 108 | + version='1.1.90', |
| 109 | packages=['ubuntuone', |
| 110 | 'ubuntuone.storageprotocol'], |
| 111 | - data_files=[('/etc/ssl/certs', |
| 112 | - ['data/UbuntuOne-Go_Daddy_CA.pem', |
| 113 | + data_files=[(ssl_cert_location, |
| 114 | + ['data/UbuntuOne-Go_Daddy_CA.pem', |
| 115 | 'data/UbuntuOne-Go_Daddy_Class_2_CA.pem'])], |
| 116 | |
| 117 | cmdclass = { |
| 118 | 'build' : StorageProtocolBuild, |
| 119 | 'clean' : StorageProtocolClean, |
| 120 | 'check' : StorageProtocolCheck |
| 121 | - } |
| 122 | + }, |
| 123 | + namespace_packages = ['ubuntuone'], |
| 124 | ) |
| 125 | |
| 126 | === modified file 'ubuntuone/__init__.py' |
| 127 | --- ubuntuone/__init__.py 2009-06-30 12:00:00 +0000 |
| 128 | +++ ubuntuone/__init__.py 2010-03-31 23:47:26 +0000 |
| 129 | @@ -2,15 +2,16 @@ |
| 130 | # |
| 131 | # Copyright 2009 Canonical Ltd. |
| 132 | # |
| 133 | -# This program is free software: you can redistribute it and/or modify it |
| 134 | +# This program is free software: you can redistribute it and/or modify it |
| 135 | # under the terms of the GNU Affero General Public License version 3, |
| 136 | # as published by the Free Software Foundation. |
| 137 | # |
| 138 | -# This program is distributed in the hope that it will be useful, but |
| 139 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 140 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 141 | +# This program is distributed in the hope that it will be useful, but |
| 142 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 143 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 144 | # PURPOSE. See the GNU Affero General Public License for more details. |
| 145 | # |
| 146 | # You should have received a copy of the GNU Affero General Public License |
| 147 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 148 | """ubuntuone package""" |
| 149 | +__import__('pkg_resources').declare_namespace(__name__) |
| 150 | |
| 151 | === modified file 'ubuntuone/storageprotocol/client.py' |
| 152 | --- ubuntuone/storageprotocol/client.py 2010-03-04 16:16:33 +0000 |
| 153 | +++ ubuntuone/storageprotocol/client.py 2010-03-31 23:47:26 +0000 |
| 154 | @@ -164,8 +164,9 @@ |
| 155 | elif msg.type == protocol_pb2.Volumes.UDF: |
| 156 | vol = volumes.UDFVolume.from_msg(msg.udf) |
| 157 | else: |
| 158 | - raise TypeError("Message.volume_created's type is not valid: %s" % |
| 159 | - message.volume_created.type) |
| 160 | + msg = "Message.volume_created's type is not valid: %s" % \ |
| 161 | + message.volume_created.type |
| 162 | + raise TypeError(msg) |
| 163 | |
| 164 | self._volume_created_callback(vol) |
| 165 | |
| 166 | @@ -235,50 +236,50 @@ |
| 167 | p.start() |
| 168 | return p.deferred |
| 169 | |
| 170 | - def get_content(self, share, node, hash, offset=0, |
| 171 | + def get_content(self, share, node, a_hash, offset=0, |
| 172 | callback=None, node_attr_callback=None): |
| 173 | - """Get the content of node with hash |
| 174 | + """Get the content of node with 'a_hash'. |
| 175 | |
| 176 | the content will be on request.content |
| 177 | or callback will be called for every piece that arrives. |
| 178 | |
| 179 | """ |
| 180 | - req = self.get_content_request(share, node, hash, offset, |
| 181 | + req = self.get_content_request(share, node, a_hash, offset, |
| 182 | callback, node_attr_callback) |
| 183 | return req.deferred |
| 184 | |
| 185 | - def get_content_request(self, share, node, hash, offset=0, |
| 186 | + def get_content_request(self, share, node, a_hash, offset=0, |
| 187 | callback=None, node_attr_callback=None): |
| 188 | - """Get the content of node with hash, return the request. |
| 189 | + """Get the content of node with 'a_hash', return the request. |
| 190 | |
| 191 | The content will be on request.content, or callback will be |
| 192 | called for every piece that arrives. |
| 193 | |
| 194 | """ |
| 195 | - p = GetContent(self, share, node, hash, offset, |
| 196 | - callback, node_attr_callback) |
| 197 | + p = GetContent(self, share, node, a_hash, offset, |
| 198 | + callback, node_attr_callback) |
| 199 | p.start() |
| 200 | return p |
| 201 | |
| 202 | - def put_content(self, share, node, previous_hash, hash, |
| 203 | + def put_content(self, share, node, previous_hash, new_hash, |
| 204 | crc32, size, deflated_size, fd): |
| 205 | """Put the content of fd into file node.""" |
| 206 | - req = self.put_content_request(share, node, previous_hash, |
| 207 | - hash, crc32, size, deflated_size, fd) |
| 208 | + req = self.put_content_request(share, node, previous_hash, new_hash, |
| 209 | + crc32, size, deflated_size, fd) |
| 210 | return req.deferred |
| 211 | |
| 212 | - def put_content_request(self, share, node, previous_hash, hash, |
| 213 | + def put_content_request(self, share, node, previous_hash, new_hash, |
| 214 | crc32, size, deflated_size, fd): |
| 215 | """Put the content of fd into file node, return the request.""" |
| 216 | - p = PutContent(self, share, node, previous_hash, hash, crc32, size, |
| 217 | - deflated_size, fd) |
| 218 | + p = PutContent(self, share, node, previous_hash, new_hash, |
| 219 | + crc32, size, deflated_size, fd) |
| 220 | p.start() |
| 221 | return p |
| 222 | |
| 223 | def query(self, items): |
| 224 | - """Get the current hash for items if changed |
| 225 | + """Get the current hash for items if changed. |
| 226 | |
| 227 | - items is a list of (node, hash) tuples. |
| 228 | + 'items' is a list of (node, hash) tuples. |
| 229 | |
| 230 | """ |
| 231 | r = MultiQuery(self, items) |
| 232 | @@ -510,14 +511,14 @@ |
| 233 | |
| 234 | """ |
| 235 | |
| 236 | - def __init__(self, protocol, share, node_id, hash, |
| 237 | + def __init__(self, protocol, share, node_id, a_hash, |
| 238 | offset=0, callback=None, node_attr_callback=None): |
| 239 | - """Request the content of node with hash. |
| 240 | + """Request the content of node with 'a_hash'. |
| 241 | |
| 242 | @param protocol: the request handler |
| 243 | @param share: the share node or root |
| 244 | @param node_id: the node id of the node we want to read |
| 245 | - @param hash: the hash of the content of the version we have |
| 246 | + @param a_hash: the hash of the content of the version we have |
| 247 | @param offset: offset for reading |
| 248 | @param callback: function to call when data arrives |
| 249 | |
| 250 | @@ -525,7 +526,7 @@ |
| 251 | request.Request.__init__(self, protocol) |
| 252 | self.share = share |
| 253 | self.node_id = node_id |
| 254 | - self.hash = hash |
| 255 | + self.hash = a_hash |
| 256 | self.offset = offset |
| 257 | self.callback = callback |
| 258 | self.node_attr_callback = node_attr_callback |
| 259 | @@ -981,11 +982,11 @@ |
| 260 | |
| 261 | def add_items(msg, *args): |
| 262 | """Add items to query.""" |
| 263 | - for share, node, hash in args: |
| 264 | + for share, node, content_hash in args: |
| 265 | qi = msg.query.add() |
| 266 | qi.share = share |
| 267 | qi.node = str(node) |
| 268 | - qi.hash = hash |
| 269 | + qi.hash = content_hash |
| 270 | |
| 271 | for item in items: |
| 272 | add_items(qm, item) |
| 273 | @@ -1073,7 +1074,7 @@ |
| 274 | """Put content request.""" |
| 275 | |
| 276 | def __init__(self, protocol, share, node_id, |
| 277 | - previous_hash, hash, crc32, size, |
| 278 | + previous_hash, new_hash, crc32, size, |
| 279 | deflated_size, fd): |
| 280 | """Put content into a node. |
| 281 | |
| 282 | @@ -1081,7 +1082,7 @@ |
| 283 | @param share: the share node or root |
| 284 | @param node_id: the node to receive the content |
| 285 | @param previous_hash: the hash the node has (for conflict checking) |
| 286 | - @param hash: the hash hint for the new content |
| 287 | + @param new_hash: the hash hint for the new content |
| 288 | @param crc32: the crc32 hint for the new content |
| 289 | @param size: the size hint for the new content |
| 290 | @param fd: a file-like object to read data from |
| 291 | @@ -1091,7 +1092,7 @@ |
| 292 | self.share = share |
| 293 | self.node_id = node_id |
| 294 | self.previous_hash = previous_hash |
| 295 | - self.hash = hash |
| 296 | + self.hash = new_hash |
| 297 | self.crc32 = crc32 |
| 298 | self.size = size |
| 299 | self.deflated_size = deflated_size |
| 300 | |
| 301 | === modified file 'ubuntuone/storageprotocol/context.py' |
| 302 | --- ubuntuone/storageprotocol/context.py 2009-07-16 16:30:00 +0000 |
| 303 | +++ ubuntuone/storageprotocol/context.py 2010-03-31 23:47:26 +0000 |
| 304 | @@ -2,34 +2,47 @@ |
| 305 | # |
| 306 | # Copyright 2009 Canonical Ltd. |
| 307 | # |
| 308 | -# This program is free software: you can redistribute it and/or modify it |
| 309 | +# This program is free software: you can redistribute it and/or modify it |
| 310 | # under the terms of the GNU Affero General Public License version 3, |
| 311 | # as published by the Free Software Foundation. |
| 312 | # |
| 313 | -# This program is distributed in the hope that it will be useful, but |
| 314 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 315 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 316 | +# This program is distributed in the hope that it will be useful, but |
| 317 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 318 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 319 | # PURPOSE. See the GNU Affero General Public License for more details. |
| 320 | # |
| 321 | # You should have received a copy of the GNU Affero General Public License |
| 322 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 323 | -""" |
| 324 | +""" |
| 325 | Standard Routines for working with ssl context creation |
| 326 | """ |
| 327 | +import os |
| 328 | +import sys |
| 329 | |
| 330 | from OpenSSL import SSL |
| 331 | from twisted.internet import ssl |
| 332 | |
| 333 | +if sys.platform == "win32": |
| 334 | + from bzrlib import win32utils as win |
| 335 | + ssl_cert_location = os.path.join( |
| 336 | + win.get_appdata_location_unicode(), |
| 337 | + "ubuntuone-storageprotocol") |
| 338 | +else: |
| 339 | + ssl_cert_location = '/etc/ssl/certs' |
| 340 | + |
| 341 | + |
| 342 | def get_ssl_context(no_verify): |
| 343 | """ Get the ssl context """ |
| 344 | if no_verify: |
| 345 | ctx = ssl.ClientContextFactory() |
| 346 | else: |
| 347 | ca_file = ssl.Certificate.loadPEM(file( |
| 348 | - '/etc/ssl/certs/UbuntuOne-Go_Daddy_Class_2_CA.pem', 'r').read()) |
| 349 | + os.path.join(ssl_cert_location, |
| 350 | + 'UbuntuOne-Go_Daddy_Class_2_CA.pem'), 'r').read()) |
| 351 | ca_file_2 = ssl.Certificate.loadPEM(file( |
| 352 | - '/etc/ssl/certs/UbuntuOne-Go_Daddy_CA.pem', 'r').read()) |
| 353 | - ctx = ssl.CertificateOptions(verify=True, |
| 354 | + os.path.join(ssl_cert_location, |
| 355 | + 'UbuntuOne-Go_Daddy_CA.pem'), 'r').read()) |
| 356 | + ctx = ssl.CertificateOptions(verify=True, |
| 357 | caCerts=[ca_file.original, ca_file_2.original], |
| 358 | method=SSL.SSLv23_METHOD) |
| 359 | return ctx |
| 360 | |
| 361 | === modified file 'ubuntuone/storageprotocol/hash.py' |
| 362 | --- ubuntuone/storageprotocol/hash.py 2009-06-30 12:00:00 +0000 |
| 363 | +++ ubuntuone/storageprotocol/hash.py 2010-03-31 23:47:26 +0000 |
| 364 | @@ -1,35 +1,35 @@ |
| 365 | -# ubuntuone.storageprotocol.hash - hash handling |
| 366 | +# ubuntuone.storageprotocol.hash - content hash handling |
| 367 | # |
| 368 | # Author: Lucio Torre <lucio.torre@canonical.com> |
| 369 | # |
| 370 | # Copyright 2009 Canonical Ltd. |
| 371 | # |
| 372 | -# This program is free software: you can redistribute it and/or modify it |
| 373 | +# This program is free software: you can redistribute it and/or modify it |
| 374 | # under the terms of the GNU Affero General Public License version 3, |
| 375 | # as published by the Free Software Foundation. |
| 376 | # |
| 377 | -# This program is distributed in the hope that it will be useful, but |
| 378 | -# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 379 | -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 380 | +# This program is distributed in the hope that it will be useful, but |
| 381 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 382 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 383 | # PURPOSE. See the GNU Affero General Public License for more details. |
| 384 | # |
| 385 | # You should have received a copy of the GNU Affero General Public License |
| 386 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 387 | -""" Hash Handling Stuffs |
| 388 | -""" |
| 389 | +"""Hash Handling Stuffs.""" |
| 390 | + |
| 391 | +import copy |
| 392 | import hashlib |
| 393 | -import copy |
| 394 | import zlib |
| 395 | |
| 396 | -# XXX: |
| 397 | -# lucio.torre |
| 398 | -# rename this module so it doesnt shadow builtin hash |
| 399 | +# XXX: (lucio.torre) Rename this module so it doesnt shadow builtin hash |
| 400 | +# see Bug #384153 for updates |
| 401 | |
| 402 | class ContentHash(object): |
| 403 | - """ encapsulates the generation of content hashes |
| 404 | - |
| 405 | - we cant subclass openssl hash classes, so we do some |
| 406 | - composition to get similar methods |
| 407 | + """Encapsulates the generation of content hashes. |
| 408 | + |
| 409 | + We cant subclass openssl hash classes, so we do some |
| 410 | + composition to get similar methods. |
| 411 | + |
| 412 | """ |
| 413 | method = None |
| 414 | method_name = "" |
| 415 | @@ -41,20 +41,20 @@ |
| 416 | update = property(lambda self: self.hash_object.update) |
| 417 | digest = property(lambda self: self.hash_object.digest) |
| 418 | hexdigest = property(lambda self: self.hash_object.hexdigest) |
| 419 | + |
| 420 | def copy(self): |
| 421 | - """ Copies generated hash |
| 422 | - """ |
| 423 | + """Copies the generated hash.""" |
| 424 | cp = copy.copy(self) |
| 425 | cp.hash_object = self.hash_object.copy() |
| 426 | return cp |
| 427 | + |
| 428 | def content_hash(self): |
| 429 | - """ adds hex digest to content hash |
| 430 | - """ |
| 431 | + """Adds hex digest to content hash.""" |
| 432 | return self.method_name +":"+ self.hash_object.hexdigest() |
| 433 | |
| 434 | class SHA1ContentHash(ContentHash): |
| 435 | - """ Generates SHA1 of ConentHash? |
| 436 | - """ |
| 437 | + """Generates SHA1 of ConentHash.""" |
| 438 | + |
| 439 | method = hashlib.sha1 |
| 440 | method_name = "sha1" |
| 441 | |
| 442 | @@ -62,8 +62,10 @@ |
| 443 | content_hash_factory = SHA1ContentHash |
| 444 | |
| 445 | def crc32(data, previous_crc32=0): |
| 446 | - """ a correct crc32 function |
| 447 | - |
| 448 | - always returns positive values |
| 449 | + """A correct crc32 function. |
| 450 | + |
| 451 | + Always returns positive values. |
| 452 | + |
| 453 | """ |
| 454 | return zlib.crc32(data, previous_crc32) & 0xFFFFFFFFL |
| 455 | + |
| 456 | |
| 457 | === modified file 'ubuntuone/storageprotocol/validators.py' |
| 458 | --- ubuntuone/storageprotocol/validators.py 2009-08-11 16:00:00 +0000 |
| 459 | +++ ubuntuone/storageprotocol/validators.py 2010-03-31 23:47:26 +0000 |
| 460 | @@ -33,19 +33,25 @@ |
| 461 | is_valid_share_id = is_valid_share |
| 462 | |
| 463 | def is_valid_sha1(sha1): |
| 464 | - """ |
| 465 | - A valid sha1 hash says "sha1:", and then a 40 hex characters |
| 466 | + """Validate 'sha1'. |
| 467 | + |
| 468 | + A valid sha1 hash reads "sha1:", and then a 40 hex characters. |
| 469 | + |
| 470 | """ |
| 471 | return bool(re.match(r'sha1:[0-9a-z]{40}$', sha1)) |
| 472 | |
| 473 | -def is_valid_hash(hash): |
| 474 | - """ |
| 475 | - A valid hash is either the empty string, request.UNKNOWN_HASH, or |
| 476 | - one of the other known hash types. |
| 477 | +def is_valid_hash(a_hash): |
| 478 | + """Validate 'a_hash'. |
| 479 | + |
| 480 | + A valid hash is either the empty string, request.UNKNOWN_HASH, or one of |
| 481 | + the other known hash types. |
| 482 | + |
| 483 | """ |
| 484 | # circular import |
| 485 | from ubuntuone.storageprotocol import request |
| 486 | - return hash == '' or hash == request.UNKNOWN_HASH or is_valid_sha1(hash) |
| 487 | + is_valid = a_hash == '' or a_hash == request.UNKNOWN_HASH or \ |
| 488 | + is_valid_sha1(a_hash) |
| 489 | + return is_valid |
| 490 | |
| 491 | def validate_message(message): |
| 492 | """ |

