MCPcopy Index your code
hub / github.com/pyload/pyload / parseFileSize

Function parseFileSize

module/utils.py:137–161  ·  view source on GitHub ↗
(string, unit=None)

Source from the content-addressed store, hash-verified

135
136
137def parseFileSize(string, unit=None): #returns bytes
138 if not unit:
139 m = re.match(r"(\d*[\.,]?\d+)(.*)", string.strip().lower())
140 if m:
141 traffic = float(m.group(1).replace(",", "."))
142 unit = m.group(2)
143 else:
144 return 0
145 else:
146 if isinstance(string, basestring):
147 traffic = float(string.replace(",", "."))
148 else:
149 traffic = string
150
151 #ignore case
152 unit = unit.lower().strip()
153
154 if unit in ("gb", "gig", "gbyte", "gigabyte", "gib", "g"):
155 traffic *= 1 << 30
156 elif unit in ("mb", "mbyte", "megabyte", "mib", "m"):
157 traffic *= 1 << 20
158 elif unit in ("kb", "kib", "kilobyte", "kbyte", "k"):
159 traffic *= 1 << 10
160
161 return traffic
162
163
164def lock(func):

Callers

nothing calls this directly

Calls 2

matchMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected