summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>1999-03-23 23:05:34 +0000
committerJeremy Hylton <jeremy@alum.mit.edu>1999-03-23 23:05:34 +0000
commit4a1f609cc23b00da0aea0de14cab844b380f8e22 (patch)
tree96eb5b6ec80e16ae494fdaed0ea86ecbbcbe4e92
parentd8a3ebaa76b43a75e25e059bdcd47f4bbeb4f353 (diff)
downloadcpython-4a1f609cc23b00da0aea0de14cab844b380f8e22.tar.gz
use struct instead of bit-manipulate in Python
-rw-r--r--Lib/gzip.py24
1 files changed, 3 insertions, 21 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index e25464caf9..e0c7c5bd58 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -1,6 +1,7 @@
import time
import string
import zlib
+import struct
import __builtin__
# implements a python function that reads and writes a gzipped file
@@ -14,29 +15,10 @@ FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT = 1, 2, 4, 8, 16
READ, WRITE = 1, 2
def write32(output, value):
- t = divmod(value, 256)
- b1 = chr(t[1])
-
- t = divmod(t[0], 256)
- b2 = chr(t[1])
-
- t = divmod(t[0], 256)
- b3 = chr(t[1])
-
- t = divmod(t[0], 256)
- b4 = chr(t[1])
-
- buf = b1 + b2 + b3 + b4
- output.write(buf)
-
+ output.write(struct.pack("<l", value))
def read32(input):
- buf = input.read(4)
- v = ord(buf[0])
- v = v + (ord(buf[1]) << 8)
- v = v + (ord(buf[2]) << 16)
- v = v + (ord(buf[3]) << 24)
- return v
+ return struct.unpack("<l", input.read(4))[0]
def open(filename, mode="r", compresslevel=9):
return GzipFile(filename, mode, compresslevel)