Show More
@@ -1268,7 +1268,18 b' def ellipsis(text, maxlength=400):' | |||
|
1268 | 1268 | except (UnicodeDecodeError, UnicodeEncodeError): |
|
1269 | 1269 | return _ellipsis(text, maxlength)[0] |
|
1270 | 1270 | |
|
1271 | _byteunits = ( | |
|
1271 | def unitcountfn(*unittable): | |
|
1272 | '''return a function that renders a readable count of some quantity''' | |
|
1273 | ||
|
1274 | def go(count): | |
|
1275 | for multiplier, divisor, format in unittable: | |
|
1276 | if count >= divisor * multiplier: | |
|
1277 | return format % (count / float(divisor)) | |
|
1278 | return unittable[-1][2] % count | |
|
1279 | ||
|
1280 | return go | |
|
1281 | ||
|
1282 | bytecount = unitcountfn( | |
|
1272 | 1283 | (100, 1 << 30, _('%.0f GB')), |
|
1273 | 1284 | (10, 1 << 30, _('%.1f GB')), |
|
1274 | 1285 | (1, 1 << 30, _('%.2f GB')), |
@@ -1281,14 +1292,6 b' def ellipsis(text, maxlength=400):' | |||
|
1281 | 1292 | (1, 1, _('%.0f bytes')), |
|
1282 | 1293 | ) |
|
1283 | 1294 | |
|
1284 | def bytecount(nbytes): | |
|
1285 | '''return byte count formatted as readable string, with units''' | |
|
1286 | ||
|
1287 | for multiplier, divisor, format in _byteunits: | |
|
1288 | if nbytes >= divisor * multiplier: | |
|
1289 | return format % (nbytes / float(divisor)) | |
|
1290 | return _byteunits[-1][2] % nbytes | |
|
1291 | ||
|
1292 | 1295 | def uirepr(s): |
|
1293 | 1296 | # Avoid double backslash in Windows path repr() |
|
1294 | 1297 | return repr(s).replace('\\\\', '\\') |
General Comments 0
You need to be logged in to leave comments.
Login now