| 135 | |
| 136 | |
| 137 | def 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 | |
| 164 | def lock(func): |