Commit 2c439f43 by heffnercj

Fixed compat.py python2.6 bug

parent f930db15
...@@ -517,6 +517,7 @@ void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, siz ...@@ -517,6 +517,7 @@ void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, siz
size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity; size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size, tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size,
(flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF); (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
printf("STATUS: %d\n", status);
if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT)) if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
{ {
MZ_FREE(pBuf); *pOut_len = 0; return NULL; MZ_FREE(pBuf); *pOut_len = 0; return NULL;
...@@ -606,10 +607,11 @@ int is_deflated(char *buf, size_t buf_size, int includes_zlib_header) ...@@ -606,10 +607,11 @@ int is_deflated(char *buf, size_t buf_size, int includes_zlib_header)
return 0; return 0;
} }
#define MAX_READ_SIZE 1*1024*1024
int inflate_raw_file(char *in_file, char *out_file) int inflate_raw_file(char *in_file, char *out_file)
{ {
int retval = 0; int retval = 0, i = 0;
size_t out_size = 0, in_size = 0; size_t out_size = 0, in_size = 0, nbytes = 0;
FILE *fp_in = NULL, *fp_out = NULL; FILE *fp_in = NULL, *fp_out = NULL;
char *compressed_data = NULL, *decompressed_data = NULL; char *compressed_data = NULL, *decompressed_data = NULL;
...@@ -624,20 +626,25 @@ int inflate_raw_file(char *in_file, char *out_file) ...@@ -624,20 +626,25 @@ int inflate_raw_file(char *in_file, char *out_file)
in_size = ftell(fp_in); in_size = ftell(fp_in);
fseek(fp_in, 0L, SEEK_SET); fseek(fp_in, 0L, SEEK_SET);
compressed_data = malloc(in_size); compressed_data = malloc(MAX_READ_SIZE);
if(compressed_data) if(compressed_data)
{ {
memset(compressed_data, 0, in_size);
if(fread(compressed_data, 1, in_size, fp_in) == in_size) for(i=0; i<in_size; i+=MAX_READ_SIZE)
{ {
decompressed_data = (char *) tinfl_decompress_mem_to_heap(compressed_data, in_size, &out_size, 0); memset(compressed_data, 0, MAX_READ_SIZE);
if(decompressed_data && out_size > 0) nbytes = fread(compressed_data, 1, MAX_READ_SIZE, fp_in);
if(nbytes > 0)
{ {
fwrite(decompressed_data, 1, out_size, fp_out); decompressed_data = (char *) tinfl_decompress_mem_to_heap(compressed_data, nbytes, &out_size, 0);
free(decompressed_data);
retval = out_size; if(decompressed_data && out_size > 0)
{
fwrite(decompressed_data, 1, out_size, fp_out);
free(decompressed_data);
retval += out_size;
}
} }
} }
......
...@@ -4,7 +4,9 @@ from __future__ import print_function ...@@ -4,7 +4,9 @@ from __future__ import print_function
import sys import sys
import string import string
if sys.version_info.major > 2: PY_MAJOR_VERSION = sys.version_info[0]
if PY_MAJOR_VERSION > 2:
import urllib.request as urllib2 import urllib.request as urllib2
string.letters = string.ascii_letters string.letters = string.ascii_letters
else: else:
...@@ -14,7 +16,7 @@ def iterator(dictionary): ...@@ -14,7 +16,7 @@ def iterator(dictionary):
''' '''
For cross compatibility between Python 2 and Python 3 dictionaries. For cross compatibility between Python 2 and Python 3 dictionaries.
''' '''
if sys.version_info.major > 2: if PY_MAJOR_VERSION > 2:
return dictionary.items() return dictionary.items()
else: else:
return dictionary.iteritems() return dictionary.iteritems()
...@@ -23,7 +25,7 @@ def has_key(dictionary, key): ...@@ -23,7 +25,7 @@ def has_key(dictionary, key):
''' '''
For cross compatibility between Python 2 and Python 3 dictionaries. For cross compatibility between Python 2 and Python 3 dictionaries.
''' '''
if sys.version_info.major > 2: if PY_MAJOR_VERSION > 2:
return key in dictionary return key in dictionary
else: else:
return dictionary.has_key(key) return dictionary.has_key(key)
...@@ -32,7 +34,7 @@ def str2bytes(string): ...@@ -32,7 +34,7 @@ def str2bytes(string):
''' '''
For cross compatibility between Python 2 and Python 3 strings. For cross compatibility between Python 2 and Python 3 strings.
''' '''
if isinstance(string, type('')) and sys.version_info.major > 2: if isinstance(string, type('')) and PY_MAJOR_VERSION > 2:
return bytes(string, 'latin1') return bytes(string, 'latin1')
else: else:
return string return string
...@@ -41,7 +43,7 @@ def bytes2str(bs): ...@@ -41,7 +43,7 @@ def bytes2str(bs):
''' '''
For cross compatibility between Python 2 and Python 3 strings. For cross compatibility between Python 2 and Python 3 strings.
''' '''
if isinstance(bs, type(b'')) and sys.version_info.major > 2: if isinstance(bs, type(b'')) and PY_MAJOR_VERSION > 2:
return bs.decode('latin1') return bs.decode('latin1')
else: else:
return bs return bs
...@@ -50,7 +52,7 @@ def string_decode(string): ...@@ -50,7 +52,7 @@ def string_decode(string):
''' '''
For cross compatibility between Python 2 and Python 3 strings. For cross compatibility between Python 2 and Python 3 strings.
''' '''
if sys.version_info.major > 2: if PY_MAJOR_VERSION > 2:
return bytes(string, 'utf-8').decode('unicode_escape') return bytes(string, 'utf-8').decode('unicode_escape')
else: else:
return string.decode('string_escape') return string.decode('string_escape')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment