PyCatFile 0.13.2__tar.gz → 0.13.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCatFile
3
- Version: 0.13.2
3
+ Version: 0.13.4
4
4
  Summary: A tar like file format name catfile after unix cat command (concatenate files) .
5
5
  Home-page: https://github.com/GameMaker2k/PyCatFile
6
6
  Download-URL: https://github.com/GameMaker2k/PyCatFile/archive/master.tar.gz
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCatFile
3
- Version: 0.13.2
3
+ Version: 0.13.4
4
4
  Summary: A tar like file format name catfile after unix cat command (concatenate files) .
5
5
  Home-page: https://github.com/GameMaker2k/PyCatFile
6
6
  Download-URL: https://github.com/GameMaker2k/PyCatFile/archive/master.tar.gz
@@ -14,7 +14,7 @@
14
14
  Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15
15
  Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16
16
 
17
- $FileInfo: catfile.py - Last Update: 6/14/2024 Ver. 0.13.2 RC 1 - Author: cooldude2k $
17
+ $FileInfo: catfile.py - Last Update: 6/18/2024 Ver. 0.13.4 RC 1 - Author: cooldude2k $
18
18
  '''
19
19
 
20
20
  from __future__ import absolute_import, division, print_function, unicode_literals;
@@ -161,9 +161,9 @@ if active_action:
161
161
  checkcompressfile = pycatfile.CheckCompressionSubType(getargs.input, fnamedict, True);
162
162
  tempout = BytesIO();
163
163
  if(checkcompressfile=="catfile"):
164
- tmpout = pycatfile.RePackArchiveFile(getargs.input, tempout, getargs.compression, getargs.wholefile, getargs.level, False, 0, 0, getargs.checksum, getargs.skipchecksum, [], fnamedict, getargs.verbose, False);
164
+ tmpout = pycatfile.RePackArchiveFile(getargs.input, tempout, getargs.compression, getargs.wholefile, getargs.level, False, 0, 0, getargs.checksum, getargs.skipchecksum, [], fnamedict, False, False);
165
165
  else:
166
- tmpout = pycatfile.PackArchiveFileFromInFile(getargs.input, tempout, getargs.compression, getargs.wholefile, getargs.level, getargs.checksum, [], fnamedict, getargs.verbose, False);
166
+ tmpout = pycatfile.PackArchiveFileFromInFile(getargs.input, tempout, getargs.compression, getargs.wholefile, getargs.level, getargs.checksum, [], fnamedict, False, False);
167
167
  if(not tmpout):
168
168
  sys.exit(1);
169
169
  getargs.input = tempout;
@@ -184,9 +184,9 @@ if active_action:
184
184
  checkcompressfile = pycatfile.CheckCompressionSubType(getargs.input, fnamedict, True);
185
185
  tempout = BytesIO();
186
186
  if(checkcompressfile=="catfile"):
187
- tmpout = pycatfile.RePackArchiveFile(getargs.input, tempout, getargs.compression, getargs.wholefile, getargs.level, False, 0, 0, getargs.checksum, getargs.skipchecksum, [], fnamedict, getargs.verbose, False);
187
+ tmpout = pycatfile.RePackArchiveFile(getargs.input, tempout, getargs.compression, getargs.wholefile, getargs.level, False, 0, 0, getargs.checksum, getargs.skipchecksum, [], fnamedict, False, False);
188
188
  else:
189
- tmpout = pycatfile.PackArchiveFileFromInFile(getargs.input, tempout, getargs.compression, getargs.wholefile, getargs.level, getargs.checksum, [], fnamedict, getargs.verbose, False);
189
+ tmpout = pycatfile.PackArchiveFileFromInFile(getargs.input, tempout, getargs.compression, getargs.wholefile, getargs.level, getargs.checksum, [], fnamedict, False, False);
190
190
  getargs.input = tempout;
191
191
  if(not tmpout):
192
192
  sys.exit(1);
@@ -14,7 +14,7 @@
14
14
  Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15
15
  Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16
16
 
17
- $FileInfo: neocatfile.py - Last Update: 6/14/2024 Ver. 0.13.2 RC 1 - Author: cooldude2k $
17
+ $FileInfo: neocatfile.py - Last Update: 6/18/2024 Ver. 0.13.4 RC 1 - Author: cooldude2k $
18
18
  '''
19
19
 
20
20
  from __future__ import absolute_import, division, print_function, unicode_literals
@@ -14,7 +14,7 @@
14
14
  Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15
15
  Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16
16
 
17
- $FileInfo: pycatfile.py - Last Update: 6/14/2024 Ver. 0.13.2 RC 1 - Author: cooldude2k $
17
+ $FileInfo: pycatfile.py - Last Update: 6/18/2024 Ver. 0.13.4 RC 1 - Author: cooldude2k $
18
18
  '''
19
19
 
20
20
  from __future__ import absolute_import, division, print_function, unicode_literals;
@@ -36,6 +36,11 @@ try:
36
36
  except ImportError:
37
37
  import json;
38
38
 
39
+ try:
40
+ basestring;
41
+ except NameError:
42
+ basestring = str;
43
+
39
44
  # URL Parsing
40
45
  try:
41
46
  from urllib.parse import urlparse, urlunparse;
@@ -137,6 +142,15 @@ try:
137
142
  except ImportError:
138
143
  pass;
139
144
 
145
+ # HTTPX support
146
+ havehttpx = False;
147
+ try:
148
+ import httpx;
149
+ havehttpx = True;
150
+ logging.getLogger("httpx").setLevel(logging.WARNING);
151
+ except ImportError:
152
+ pass;
153
+
140
154
  # HTTP and URL parsing
141
155
  try:
142
156
  from urllib.request import Request, build_opener, HTTPBasicAuthHandler;
@@ -160,6 +174,13 @@ __use_pysftp__ = False;
160
174
  __use_alt_format__ = False;
161
175
  if(not havepysftp):
162
176
  __use_pysftp__ = False;
177
+ __use_http_lib__ = "httpx";
178
+ if(__use_http_lib__=="httpx" haverequests and not havehttpx):
179
+ __use_http_lib__ = "requests";
180
+ if(__use_http_lib__=="requests" havehttpx and not haverequests):
181
+ __use_http_lib__ = "httpx";
182
+ if((__use_http_lib__=="httpx" or __use_http_lib__=="requests") and not havehttpx and not haverequests):
183
+ __use_http_lib__ = "urllib";
163
184
  if(not __use_alt_format__):
164
185
  ''' Format Info by Kazuki Przyborowski '''
165
186
  __file_format_name__ = "CatFile";
@@ -192,11 +213,11 @@ __file_format_list__ = [__file_format_name__, __file_format_magic__, __file_form
192
213
  __file_format_dict__ = {'format_name': __file_format_name__, 'format_magic': __file_format_magic__, 'format_lower': __file_format_lower__, 'format_len': __file_format_len__, 'format_hex': __file_format_hex__, 'format_delimiter': __file_format_delimiter__, 'format_ver': __file_format_ver__, 'new_style': __use_new_style__, 'use_advanced_list': __use_advanced_list__, 'use_alt_inode': __use_alt_inode__};
193
214
  __project__ = __program_name__;
194
215
  __project_url__ = "https://github.com/GameMaker2k/PyCatFile";
195
- __version_info__ = (0, 13, 2, "RC 1", 1);
196
- __version_date_info__ = (2024, 6, 14, "RC 1", 1);
216
+ __version_info__ = (0, 13, 4, "RC 1", 1);
217
+ __version_date_info__ = (2024, 6, 18, "RC 1", 1);
197
218
  __version_date__ = str(__version_date_info__[0]) + "." + str(__version_date_info__[1]).zfill(2) + "." + str(__version_date_info__[2]).zfill(2);
198
219
  __revision__ = __version_info__[3];
199
- __revision_id__ = "$Id: 4fa12ed6c9a98672ea7ca68f9bff7b0f13f625d1 $";
220
+ __revision_id__ = "$Id: 0c3bc3acf2863566af9a19f45254762656cc7ce7 $";
200
221
  if(__version_info__[4] is not None):
201
222
  __version_date_plusrc__ = __version_date__ + "-" + str(__version_date_info__[4]);
202
223
  if(__version_info__[4] is None):
@@ -982,6 +1003,97 @@ def TarFileCheck(infile):
982
1003
  except tarfile.TarError:
983
1004
  return False;
984
1005
 
1006
+ def TarFileCheckAlt(infile):
1007
+ try:
1008
+ if is_tarfile(infile):
1009
+ return True;
1010
+ except TypeError:
1011
+ pass;
1012
+ try:
1013
+ # Check if the input is a file-like object
1014
+ if hasattr(infile, 'read'):
1015
+ # Save the current file position
1016
+ current_position = infile.tell();
1017
+ # Attempt to open the file object as a tar file
1018
+ with tarfile.open(fileobj=infile) as tar:
1019
+ pass;
1020
+ # Restore the file position
1021
+ infile.seek(current_position);
1022
+ else:
1023
+ # Assume it's a filename and attempt to open it as a tar file
1024
+ with tarfile.open(name=infile) as tar:
1025
+ pass;
1026
+ return True;
1027
+ except (tarfile.TarError, AttributeError, IOError):
1028
+ return False;
1029
+
1030
+ def ZipFileCheck(infile):
1031
+ try:
1032
+ if zipfile.is_zipfile(infile):
1033
+ return True;
1034
+ except TypeError:
1035
+ pass;
1036
+ try:
1037
+ # Check if the input is a file-like object
1038
+ if hasattr(infile, 'read'):
1039
+ # Save the current file position
1040
+ current_position = infile.tell();
1041
+ # Attempt to open the file object as a zip file
1042
+ with zipfile.ZipFile(infile) as zipf:
1043
+ pass;
1044
+ # Restore the file position
1045
+ infile.seek(current_position);
1046
+ else:
1047
+ # Assume it's a filename and attempt to open it as a zip file
1048
+ with zipfile.ZipFile(infile) as zipf:
1049
+ pass;
1050
+ return True;
1051
+ except (zipfile.BadZipFile, AttributeError, IOError):
1052
+ return False;
1053
+
1054
+ def RarFileCheck(infile):
1055
+ try:
1056
+ if rarfile.is_rarfile(infile):
1057
+ return True;
1058
+ except TypeError:
1059
+ pass;
1060
+ try:
1061
+ # Check if the input is a file-like object
1062
+ if hasattr(infile, 'read'):
1063
+ # Save the current file position
1064
+ current_position = infile.tell();
1065
+ # Attempt to open the file object as a rar file
1066
+ with rarfile.RarFile(infile) as rarf:
1067
+ pass;
1068
+ # Restore the file position
1069
+ infile.seek(current_position);
1070
+ else:
1071
+ # Assume it's a filename and attempt to open it as a rar file
1072
+ with rarfile.RarFile(infile) as rarf:
1073
+ pass;
1074
+ return True;
1075
+ except (rarfile.Error, AttributeError, IOError):
1076
+ return False;
1077
+
1078
+ def SevenZipFileCheck(infile):
1079
+ try:
1080
+ # Check if the input is a file-like object
1081
+ if hasattr(infile, 'read'):
1082
+ # Save the current file position
1083
+ current_position = infile.tell();
1084
+ # Attempt to open the file object as a 7z file
1085
+ with py7zr.SevenZipFile(infile, 'r') as archive:
1086
+ pass;
1087
+ # Restore the file position
1088
+ infile.seek(current_position);
1089
+ else:
1090
+ # Assume it's a filename and attempt to open it as a 7z file
1091
+ with py7zr.SevenZipFile(infile, 'r') as archive:
1092
+ pass;
1093
+ return True;
1094
+ except (py7zr.Bad7zFile, AttributeError, IOError):
1095
+ return False;
1096
+
985
1097
  # initial_value can be 0xFFFF or 0x0000
986
1098
  def crc16_ansi(msg, initial_value=0xFFFF):
987
1099
  # CRC-16-IBM / CRC-16-ANSI polynomial and initial value
@@ -2961,7 +3073,7 @@ def CompressArchiveFile(fp, compression="auto", compressionlevel=None, formatspe
2961
3073
  compressionlevel = 9;
2962
3074
  else:
2963
3075
  compressionlevel = int(compressionlevel);
2964
- catfp.write(lzma.compress(fp.read(), level=compressionlevel));
3076
+ catfp.write(zlib.compress(fp.read(), level=compressionlevel));
2965
3077
  if(compression=="auto" or compression is None):
2966
3078
  catfp = fp;
2967
3079
  catfp.seek(0, 0);
@@ -4986,7 +5098,13 @@ def ArchiveFileValidate(infile, formatspecs=__file_format_dict__, verbose=False,
4986
5098
  valid_archive = True;
4987
5099
  invalid_archive = False;
4988
5100
  if(verbose):
4989
- VerbosePrintOut(infile);
5101
+ if(hasattr(infile, "read") or hasattr(infile, "write")):
5102
+ try:
5103
+ VerbosePrintOut(infile.name);
5104
+ except AttributeError:
5105
+ VerbosePrintOut(infile);
5106
+ else:
5107
+ VerbosePrintOut(infile);
4990
5108
  VerbosePrintOut("Number of Records " + str(fnumfiles));
4991
5109
  if(fprechecksum==catfileheadercshex):
4992
5110
  if(verbose):
@@ -7745,34 +7863,46 @@ def upload_file_to_ftp_string(ftpstring, url):
7745
7863
  ftpfileo.close();
7746
7864
  return ftpfile;
7747
7865
 
7748
- def download_file_from_http_file(url, headers=geturls_headers_pycatfile_python_alt):
7866
+ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
7867
+ if headers is None:
7868
+ headers = {};
7749
7869
  # Parse the URL to extract username and password if present
7750
7870
  urlparts = urlparse(url);
7751
7871
  username = urlparts.username;
7752
7872
  password = urlparts.password;
7753
7873
  # Rebuild the URL without the username and password
7754
7874
  netloc = urlparts.hostname;
7755
- if(urlparts.scheme=="sftp"):
7756
- if(__use_pysftp__):
7875
+ if urlparts.scheme == "sftp":
7876
+ if __use_pysftp__:
7757
7877
  return download_file_from_pysftp_file(url);
7758
7878
  else:
7759
7879
  return download_file_from_sftp_file(url);
7760
- elif(urlparts.scheme=="ftp" or urlparts.scheme=="ftps"):
7880
+ elif urlparts.scheme == "ftp" or urlparts.scheme == "ftps":
7761
7881
  return download_file_from_ftp_file(url);
7762
7882
  if urlparts.port:
7763
- netloc += ':' + str(urlparts.port);
7883
+ netloc += ':' + str(urlparts.port)
7764
7884
  rebuilt_url = urlunparse((urlparts.scheme, netloc, urlparts.path, urlparts.params, urlparts.query, urlparts.fragment));
7765
7885
  # Create a temporary file object
7766
7886
  httpfile = BytesIO();
7767
- if haverequests:
7768
- # Use the requests library if available
7887
+ if usehttp == 'requests' and haverequests:
7888
+ # Use the requests library if selected and available
7769
7889
  if username and password:
7770
7890
  response = requests.get(rebuilt_url, headers=headers, auth=(username, password), stream=True);
7771
7891
  else:
7772
7892
  response = requests.get(rebuilt_url, headers=headers, stream=True);
7773
- response.raw.decode_content = True
7893
+ response.raw.decode_content = True;
7774
7894
  shutil.copyfileobj(response.raw, httpfile);
7895
+ elif usehttp == 'httpx' and havehttpx:
7896
+ # Use httpx if selected and available
7897
+ with httpx.Client() as client:
7898
+ if username and password:
7899
+ response = client.get(rebuilt_url, headers=headers, auth=(username, password), stream=True);
7900
+ else:
7901
+ response = client.get(rebuilt_url, headers=headers, stream=True);
7902
+ for chunk in response.iter_bytes():
7903
+ httpfile.write(chunk);
7775
7904
  else:
7905
+ # Use urllib as a fallback
7776
7906
  # Build a Request object for urllib
7777
7907
  request = Request(rebuilt_url, headers=headers);
7778
7908
  # Create an opener object for handling URLs
@@ -7786,7 +7916,7 @@ def download_file_from_http_file(url, headers=geturls_headers_pycatfile_python_a
7786
7916
  # Build the opener with the authentication handler
7787
7917
  opener = build_opener(auth_handler);
7788
7918
  else:
7789
- opener = build_opener();
7919
+ opener = build_opener();
7790
7920
  with opener.open(request) as response:
7791
7921
  shutil.copyfileobj(response, httpfile);
7792
7922
  # Reset file pointer to the start
@@ -13,7 +13,7 @@
13
13
  Copyright 2016-2024 Game Maker 2k - http://intdb.sourceforge.net/
14
14
  Copyright 2016-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
15
15
 
16
- $FileInfo: setup.py - Last Update: 6/14/2024 Ver. 0.13.2 RC 1 - Author: cooldude2k $
16
+ $FileInfo: setup.py - Last Update: 6/18/2024 Ver. 0.13.4 RC 1 - Author: cooldude2k $
17
17
  '''
18
18
 
19
19
  import os, re, sys, pkg_resources;
File without changes
File without changes
File without changes