cloud-files 4.27.0__py3-none-any.whl → 6.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cloudfiles/lib.py CHANGED
@@ -53,8 +53,11 @@ def mkdir(path):
53
53
  return path
54
54
 
55
55
  def touch(path):
56
- mkdir(os.path.dirname(path))
57
- open(path, 'a').close()
56
+ if os.path.exists(path):
57
+ os.utime(path)
58
+ else:
59
+ mkdir(os.path.dirname(path))
60
+ open(path, 'a').close()
58
61
 
59
62
  def nvl(*args):
60
63
  """Return the leftmost argument that is not None."""
@@ -150,11 +153,18 @@ def decode_crc32c_b64(b64digest):
150
153
  # !I means network order (big endian) and unsigned int
151
154
  return struct.unpack("!I", base64.b64decode(b64digest))[0]
152
155
 
156
+ def encode_crc32c_b64(binary):
157
+ val = crc32c(binary)
158
+ val = val.to_bytes(4, 'big')
159
+ return base64.b64encode(val)
160
+
153
161
  def crc32c(binary):
154
162
  """
155
163
  Computes the crc32c of a binary string
156
164
  and returns it as an integer.
157
165
  """
166
+ if isinstance(binary, str):
167
+ binary = binary.encode('utf8')
158
168
  return crc32clib.crc32c(binary) # an integer
159
169
 
160
170
  def md5(binary, base=64):