MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / parse_file_size

Function parse_file_size

pywebio/utils.py:348–366  ·  view source on GitHub ↗

Transform file size to byte :param str/int/float size: 1, '30', '20M', '32k', '16G', '15mb' :return int: in byte

(size)

Source from the content-addressed store, hash-verified

346
347
348def parse_file_size(size):
349 """Transform file size to byte
350
351 :param str/int/float size: 1, '30', '20M', '32k', '16G', '15mb'
352 :return int: in byte
353 """
354 if isinstance(size, (int, float)):
355 return int(size)
356 assert isinstance(size, str), '`size` must be int/float/str, got %s' % type(size)
357
358 size = size.lower().replace('b', '')
359
360 for idx, i in enumerate(['k', 'm', 'g', 't', 'p'], 1):
361 if i in size:
362 s = size.replace(i, '')
363 base = 2 ** (idx * 10)
364 return int(float(s) * base)
365
366 return int(size)
367
368
369def strip_space(text, n):

Callers 11

file_uploadFunction · 0.85
wsgi_appFunction · 0.85
start_serverFunction · 0.85
wsgi_appFunction · 0.85
start_serverFunction · 0.85
webio_handlerFunction · 0.85
path_deployFunction · 0.85
path_deploy_httpFunction · 0.85
start_serverFunction · 0.85
start_serverFunction · 0.85
server_threadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…