mirror of https://github.com/ecmwf/eccodes.git
Python3 support
This commit is contained in:
parent
2be1ab2e58
commit
cd734a87c6
11
memfs.py
11
memfs.py
|
@ -39,8 +39,10 @@ CHUNK = 16 * 1024 * 1024 # chunk size in bytes
|
|||
try:
|
||||
str(b"\x23\x20", "ascii")
|
||||
ascii = lambda x: str(x, "ascii") # Python 3
|
||||
encode = lambda x: x.encode()
|
||||
except:
|
||||
ascii = lambda x: str(x) # Python 2
|
||||
encode = lambda x: x
|
||||
|
||||
|
||||
def get_outfile_name(base, count):
|
||||
|
@ -90,7 +92,7 @@ for directory in dirs:
|
|||
FILES[name] = fname
|
||||
SIZES[name] = os.path.getsize(full)
|
||||
|
||||
buffer.write(b"const unsigned char %s[] = {" % (name,))
|
||||
buffer.write(encode("const unsigned char %s[] = {" % (name,)))
|
||||
|
||||
with open(full, "rb") as f:
|
||||
i = 0
|
||||
|
@ -104,12 +106,12 @@ for directory in dirs:
|
|||
# e.g. 23 -> 0x23
|
||||
for n in range(0, len(contents_hex), 2):
|
||||
twoChars = ascii(contents_hex[n : n + 2])
|
||||
buffer.write(b"0x%s," % (twoChars,))
|
||||
buffer.write(encode("0x%s," % (twoChars,)))
|
||||
i += 1
|
||||
if (i % 20) == 0:
|
||||
buffer.write(b"\n")
|
||||
buffer.write(encode("\n"))
|
||||
|
||||
buffer.write(b"};\n")
|
||||
buffer.write(encode("};\n"))
|
||||
if buffer.tell() >= CHUNK:
|
||||
buffer.close()
|
||||
buffer = None
|
||||
|
@ -317,4 +319,3 @@ FILE* codes_memfs_open(const char* path) {
|
|||
print("Finished")
|
||||
|
||||
print("MEMFS: done", time.time() - start)
|
||||
|
||||
|
|
Loading…
Reference in New Issue