TSVZ 3.23__py3-none-any.whl → 3.24__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.
TSVZ.py CHANGED
@@ -22,7 +22,7 @@ if os.name == 'nt':
22
22
  elif os.name == 'posix':
23
23
  import fcntl
24
24
 
25
- version = '3.23'
25
+ version = '3.24'
26
26
  __version__ = version
27
27
  author = 'pan@zopyr.us'
28
28
 
@@ -128,6 +128,7 @@ def pretty_format_table(data, delimiter = DEFAULT_DELIMITER,header = None):
128
128
  def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False,str_format='.2f'):
129
129
  """
130
130
  Format the size in bytes to a human-readable format or vice versa.
131
+ From hpcp: https://github.com/yufei-pan/hpcp
131
132
 
132
133
  Args:
133
134
  size (int or str): The size in bytes or a string representation of the size.
@@ -140,10 +141,16 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False,str_forma
140
141
  int or str: The formatted size based on the provided arguments.
141
142
 
142
143
  Examples:
143
- >>> format_bytes(1500)
144
- '1.50 KB'
144
+ >>> format_bytes(1500, use_1024_bytes=False)
145
+ '1.50 K'
145
146
  >>> format_bytes('1.5 GiB', to_int=True)
146
147
  1610612736
148
+ >>> format_bytes('1.5 GiB', to_str=True)
149
+ '1.50 Gi'
150
+ >>> format_bytes(1610612736, use_1024_bytes=True, to_str=True)
151
+ '1.50 Gi'
152
+ >>> format_bytes(1610612736, use_1024_bytes=False, to_str=True)
153
+ '1.61 G'
147
154
  """
148
155
  if to_int or isinstance(size, str):
149
156
  if isinstance(size, int):
@@ -152,6 +159,8 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False,str_forma
152
159
  # Use regular expression to split the numeric part from the unit, handling optional whitespace
153
160
  match = re.match(r"(\d+(\.\d+)?)\s*([a-zA-Z]*)", size)
154
161
  if not match:
162
+ if to_str:
163
+ return size
155
164
  print("Invalid size format. Expected format: 'number [unit]', e.g., '1.5 GiB' or '1.5GiB'")
156
165
  print(f"Got: {size}")
157
166
  return 0
@@ -171,8 +180,12 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False,str_forma
171
180
  power = 10**3
172
181
  unit_labels = {'': 0, 'k': 1, 'm': 2, 'g': 3, 't': 4, 'p': 5}
173
182
  if unit not in unit_labels:
183
+ if to_str:
184
+ return size
174
185
  print(f"Invalid unit '{unit}'. Expected one of {list(unit_labels.keys())}")
175
186
  return 0
187
+ if to_str:
188
+ return format_bytes(size=int(number * (power ** unit_labels[unit])), use_1024_bytes=use_1024_bytes, to_str=True, str_format=str_format)
176
189
  # Calculate the bytes
177
190
  return int(number * (power ** unit_labels[unit]))
178
191
  else:
@@ -183,8 +196,8 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False,str_forma
183
196
  elif to_str or isinstance(size, int) or isinstance(size, float):
184
197
  if isinstance(size, str):
185
198
  try:
186
- size = size.lower().strip().rstrip('b')
187
- size = float(size)
199
+ size = size.rstrip('B').rstrip('b')
200
+ size = float(size.lower().strip())
188
201
  except Exception as e:
189
202
  return size
190
203
  # size is in bytes
@@ -195,7 +208,7 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False,str_forma
195
208
  while size > power:
196
209
  size /= power
197
210
  n += 1
198
- return f"{size:{str_format}} {power_labels[n]}"
211
+ return f"{size:{str_format}}{' '}{power_labels[n]}"
199
212
  else:
200
213
  power = 10**3
201
214
  n = 0
@@ -203,7 +216,7 @@ def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False,str_forma
203
216
  while size > power:
204
217
  size /= power
205
218
  n += 1
206
- return f"{size:{str_format}} {power_labels[n]}"
219
+ return f"{size:{str_format}}{' '}{power_labels[n]}"
207
220
  else:
208
221
  try:
209
222
  return format_bytes(float(size), use_1024_bytes)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: TSVZ
3
- Version: 3.23
3
+ Version: 3.24
4
4
  Summary: An simple in memory wrapper around a TSV file to function as a database
5
5
  Home-page: https://github.com/yufei-pan/TSVZ
6
6
  Author: Yufei Pan
@@ -0,0 +1,6 @@
1
+ TSVZ.py,sha256=PPylrxbtSuTUVlyuLj1tfD3DpLasLyrI0oRrCgbyr50,69364
2
+ tsvz-3.24.dist-info/METADATA,sha256=SrxVDXR15_46qKjCRRZIdkEt0HqMAgJIeKjW48y6szk,1826
3
+ tsvz-3.24.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
4
+ tsvz-3.24.dist-info/entry_points.txt,sha256=WeXidyV5yKCRLaVsnAY35xGa08QgytOfvr1CK9aescI,60
5
+ tsvz-3.24.dist-info/top_level.txt,sha256=OPx4LvOpaYykaos7oL_jGaObSWXxLzhHiWLuz-K147g,5
6
+ tsvz-3.24.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (76.1.0)
2
+ Generator: setuptools (78.0.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- TSVZ.py,sha256=PG3VoplnSdmgvm2vuor_nPXLSlwQ-B9ZBN-psDfefK0,68850
2
- tsvz-3.23.dist-info/METADATA,sha256=kK-NSB38DG_p6rzFmiu2qcijSOb1U2xI-SkglShvxDk,1826
3
- tsvz-3.23.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
4
- tsvz-3.23.dist-info/entry_points.txt,sha256=WeXidyV5yKCRLaVsnAY35xGa08QgytOfvr1CK9aescI,60
5
- tsvz-3.23.dist-info/top_level.txt,sha256=OPx4LvOpaYykaos7oL_jGaObSWXxLzhHiWLuz-K147g,5
6
- tsvz-3.23.dist-info/RECORD,,