Calculate the size of a torrent based on parsed metadata.
429729
def data_size(metadata):
    
    info = metadata['info']

    if 'length' in info:
        # Single file
        total_size = info['length']
    else:
        # Directory structure
        total_size = sum([f['length'] for f in info['files']])

    return total_size
191362
def get_size(cls):
        
        return sum([getattr(cls, name).length
                    for name in cls.get_fields_names()])
727597
def calculate_size(name, index, value):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    data_size += calculate_size_data(value)
    return data_size
1305944
def setSizeMetadata(self, size):
    
    assert((self.needMetadataUpdate(CoverImageMetadata.SIZE)) or
           (self.size == size))
    self.size = size
    self.check_metadata &= ~CoverImageMetadata.SIZE
114979
def calculate_size(name, id):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += calculate_size_str(id)
    return data_size
36461
def calculate_size(name, thread_id):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += LONG_SIZE_IN_BYTES
    return data_size
1207752
def size(self):
        

        size = 0
        try:
            tip = self.get_changeset()
            for topnode, dirs, files in tip.walk('/'):
                for f in files:
                    size += tip.get_file_size(f.path)
                for dir in dirs:
                    for f in files:
                        size += tip.get_file_size(f.path)

        except RepositoryError:
            pass
        return size
793330
function sizeForFileName(fileName, size) {
	const m = fileName.match(/@(\d+)x\./);
	const scale = m ? +m[1] : 1;

	return {
		realWidth: size.width,
		realHeight: size.height,
		width: Math.floor(size.width / scale),
		height: Math.floor(size.height / scale)
	};
}
607210
def _detect_size(self, url):
        

        site = urllib.urlopen(url)
        meta = site.info()
        return float(meta.getheaders("Content-Length")[0]) / 1e6
531868
def calculate_size(name, entries):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    for key, val in six.iteritems(entries):
        data_size += calculate_size_data(key)
        data_size += calculate_size_data(val)
    return data_size
985875
def parse_torrent_buffer(torrent):
    """"""
    md = {}
    try:
        metadata = bencode.bdecode(torrent)
    except bencode.BTL.BTFailure:
        print 'Not a valid encoded torrent'
        return None
    if 'announce-list' in metadata:
        md['trackers'] = []
        for tracker in metadata['announce-list']:
            md['trackers'].append(tracker[0])
    if 'announce' in metadata:
        md['trackers'].append(metadata['announce'])
    md['trackers'] = list(set(md['trackers']))
    if 'name' in metadata['info']:
        md['name'] = metadata['info']['name']
    webseeds = []
    if 'httpseeds' in metadata:
        webseeds = metadata['httpseeds']
    if 'url-list' in metadata:
        webseeds += md['url-list']
    if webseeds:
        md['webseeds'] = webseeds
    if 'created by' in metadata:
        md['creator'] = metadata['created by']
    if 'creation date' in metadata:
        utc_dt = datetime.utcfromtimestamp(metadata['creation date'])
        md['created'] = utc_dt.strftime('%Y-%m-%d %H:%M:%S')
    if 'comment' in metadata:
        md['comment'] = metadata['comment']
    md['piece_size'] = metadata['info']['piece length']
    if 'length' in metadata['info']:
        md['file'] = {'path': metadata['info']['name'],
                      'length': metadata['info']['length']}
    if 'files' in metadata['info']:
        md['files'] = []
        for item in metadata['info']['files']:
            md['files'].append(
                {'path': item['path'][0], 'length': item['length']})
    # TODO check if torrent is private and encoding
    hashcontents = bencode.bencode(metadata['info'])
    digest = hashlib.sha1(hashcontents).digest()
    md['infoHash'] = hashlib.sha1(hashcontents).hexdigest()
    b32hash = base64.b32encode(digest)
    md['infoHash_b32'] = b32hash
    md['pieces'] = _split_pieces(metadata['info']['pieces'])
    md['total_size'] = hsize(sum([x['length'] for x in md['files']]))
    return md
478884
def calculate_size(name, start_sequence, min_count, max_count, filter):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += LONG_SIZE_IN_BYTES
    data_size += INT_SIZE_IN_BYTES
    data_size += INT_SIZE_IN_BYTES
    data_size += BOOLEAN_SIZE_IN_BYTES
    if filter is not None:
        data_size += calculate_size_data(filter)
    return data_size
298396
def calculate_size(name, overflow_policy, value):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    data_size += calculate_size_data(value)
    return data_size
1066092
def size(pathname):
    
    if os.path.isfile(pathname):
        return os.path.getsize(pathname)
    return sum([size('{}/{}'.format(pathname, name)) for name in get_content_list(pathname)])
597034
def filesize(num_bytes):
    """"""
    for prefix in '-KMGTEPZY':
        if num_bytes < 999.9:
            break
        num_bytes /= 1000.0
    if prefix == '-':
        return '{} B'.format(num_bytes)
    return '{:.3n} {}B'.format(num_bytes, prefix)
979842
def calculate_size(name, values):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    for values_item in values:
        data_size += calculate_size_data(values_item)
    return data_size
951810
def data_size(self, live_data=None):
        """"""
        if live_data is not None:
            warnings.warn("The 'live_data' keyword argument is deprecated.",
                          DeprecationWarning)
        output = self.nodetool('info')[0]
        return _get_load_from_info_output(output)