Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _updateDisplay(self):
fileName = self._getFileNameDisplayString()
# TODO contentLength seems to slightly under-report how many bytes
# we have to download... hence the min functions
percentage = min(self.bytesWritten / self.contentLength, 1)
numerator = humanize.filesize.naturalsize(
min(self.bytesWritten, self.contentLength))
denominator = humanize.filesize.naturalsize(
self.contentLength)
displayString = "{} {:<6.2%} ({:>9} / {:<9})\r"
self.stream.write(displayString.format(
fileName, percentage, numerator, denominator))
self.stream.flush()
def _updateDisplay(self):
fileName = self._getFileNameDisplayString()
# TODO contentLength seems to slightly under-report how many bytes
# we have to download... hence the min functions
percentage = min(self.bytesWritten / self.contentLength, 1)
numerator = humanize.filesize.naturalsize(
min(self.bytesWritten, self.contentLength))
denominator = humanize.filesize.naturalsize(
self.contentLength)
displayString = "{} {:<6.2%} ({:>9} / {:<9})\r"
self.stream.write(displayString.format(
fileName, percentage, numerator, denominator))
self.stream.flush()
# will be different to the version of OS X.
if 'Darwin' == platform.system():
os_name = 'OS X {0}'.format(platform.mac_ver()[0])
else:
os_name = platform.platform(terse=False, aliased=True)
if platform.machine().endswith('64'):
os_bit_depth = '64 bit'
else:
# TODO Check on win32
os_bit_depth = '32 bit'
os = '{0} ({1})'.format(os_name, os_bit_depth)
# Total RAM
ram = humanize.filesize.naturalsize(psutil.virtual_memory().total, binary=True)
return '{os}, {ram} RAM'.format(os=os, ram=ram)
def get_image_formats(self):
image_files = self.files.filter_by(filetype=u"image")
image_formats = {}
for img_file in image_files:
if img_file.exists:
image_formats[img_file.mimetype] = {
"url": self.image_url_for_mimetype(img_file.mimetype),
"display_size": humanize.filesize.naturalsize(img_file.size)
}
return image_formats
if pympler:
sessions_info["total_size"] = asizeof(sessions)
summarized_all_objects = sorted(summary.summarize(all_objects), key=lambda t: t[2], reverse=True)
memory_info["summary"] = summarized_all_objects[:500]
import os
if "MEDIATUM_EMBED_IPYTHON" in os.environ:
import IPython
IPython.embed()
del all_objects
return render_template("memstats.j2.jade",
sessions=sessions_info,
memory=memory_info,
naturalsize=humanize.filesize.naturalsize)
def _prepareData(self, req):
obj = prepare_node_data(self, req)
if obj["deleted"]:
# no more processing needed if this object version has been deleted
# rendering has been delegated to current version
return obj
obj["naturalsize"] = humanize.filesize.naturalsize
return obj
def file_info_producer(node):
return [u"{} {} {} ({})".format(a.filetype,
a.mimetype,
a.path,
humanize.filesize.naturalsize(a.size) if a.exists else "missing!")
for a in sorted(node.files, key=lambda f: (f.filetype, f.mimetype, f.path))]
if self.displayCounter % modulo != 0:
return
fileName = self._getFileNameDisplayString()
if self.fileSize is None:
displayString = "{} bytes received: {}\r"
bytesReceived = humanize.filesize.naturalsize(
self.bytesReceived)
self.stream.write(displayString.format(
fileName, bytesReceived))
else:
# TODO contentlength seems to slightly under-report how many
# bytes we have to download... hence the min functions
percentage = min(self.bytesReceived / self.fileSize, 1)
numerator = humanize.filesize.naturalsize(
min(self.bytesReceived, self.fileSize))
denominator = humanize.filesize.naturalsize(
self.fileSize)
displayString = "{} {:<6.2%} ({:>9} / {:<9})\r"
self.stream.write(displayString.format(
fileName, percentage, numerator, denominator))
self.stream.flush()