Select a factor set based on a name, used to format compact units. For example,
if compact="bytes" we return a factor set DIGITAL_BYTES. This set is then used
to produce the most compact form for a given value, e.g. "1.2MB", "37TB", etc.
328846
protected static UnitFactorSet selectFactorSet(String compact, UnitConverter converter) {
    if (compact != null) {
      switch (compact) {
        case "angle":
        case "angles":
          return UnitFactorSets.ANGLE;
        case "area":
          return converter.areaFactors();
        case "bit":
        case "bits":
          return UnitFactorSets.DIGITAL_BITS;
        case "byte":
        case "bytes":
          return UnitFactorSets.DIGITAL_BYTES;
        case "duration":
          return UnitFactorSets.DURATION;
        case "duration-large":
          return UnitFactorSets.DURATION_LARGE;
        case "duration-small":
          return UnitFactorSets.DURATION_SMALL;
        case "electric":
          return UnitFactorSets.ELECTRIC;
        case "energy":
          return UnitFactorSets.ENERGY;
        case "frequency":
          return UnitFactorSets.FREQUENCY;
        case "length":
          return converter.lengthFactors();
        case "mass":
          return converter.massFactors();
        case "power":
          return UnitFactorSets.POWER;
        case "volume":
          return converter.volumeFactors();
        case "liquid":
          return converter.volumeLiquidFactors();
        default:
          break;
      }
    }
    return null;
  }
786225
def autosize_fieldname(idfobject):
    """"""
    # undocumented stuff in this code
    return [fname for (fname, dct) in zip(idfobject.objls,
                                          idfobject['objidd'])
            if 'autosizable' in dct]
323250
def sizeof_fmt(num, suffix='B'):
    
    precision = {'': 0, 'Ki': 0, 'Mi': 0, 'Gi': 3, 'Ti': 6, 'Pi': 9, 'Ei': 12, 'Zi': 15}

    for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
        if abs(num) < 1024.0:
            format_string = "{number:.%df} {unit}{suffix}" % precision[unit]
            return format_string.format(number=num, unit=unit, suffix=suffix)
        num /= 1024.0
    return "%.18f %s%s" % (num, 'Yi', suffix)
519551
def _pick_best_fit(self, content):
        
        import math
        
        for version in range(1, 41):
            #Get the maximum possible capacity
            capacity = tables.data_capacity[version][self.error][self.mode_num]
            
            #Check the capacity
            #Kanji's count in the table is "characters" which are two bytes
            if (self.mode_num == tables.modes['kanji'] and
                capacity >= math.ceil(len(content) / 2)):
                return version
            if capacity >= len(content):
                return version

        raise ValueError('The data will not fit in any QR code version '
                         'with the given encoding and error level.')
549488
def scale(self, selections, factor):
        '''

        '''
        if 'atoms' in selections:
            atms = selections['atoms'].mask
            if factor is None:
                    self.scale_factors[atms] = 1.0
            else:
                self.scale_factors[atms] = factor
    
        self.update_scale_factors(self.scale_factors)
13094
def nice_size(size):
    
    unit = 'B'
    if size > 1024:
        size /= 1024.0
        unit = 'KB'
        if size > 1024:
            size /= 1024.0
            unit = 'MB'
            if size > 1024:
                size /= 1024.0
                unit = 'GB'
    return '%s %s' % (nice_number(size, max_ndigits_after_dot=2), unit)
788325
def calculate_size(name, reduction):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    return data_size
718030
def size(value: int, suffixes: list = None) -> str:
    
    suffixes = suffixes or [
        'bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
    order = int(log2(value) / 10) if value else 0
    return '{:.4g} {}'.format(value / (1 << (order * 10)), suffixes[order])
974960
def convert_size(size_bytes):
    
    if size_bytes == 0:
        return "0B"
    size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
    i = int(math.floor(math.log(size_bytes, 1024)))
    p = math.pow(1024, i)
    s = round(size_bytes / p, 2)
    return "%s %s" % (s, size_name[i])
101102
def do_filesizeformat(value, binary=False):
    
    bytes = float(value)
    base = binary and 1024 or 1000
    prefixes = [
        (binary and 'KiB' or 'kB'),
        (binary and 'MiB' or 'MB'),
        (binary and 'GiB' or 'GB'),
        (binary and 'TiB' or 'TB'),
        (binary and 'PiB' or 'PB'),
        (binary and 'EiB' or 'EB'),
        (binary and 'ZiB' or 'ZB'),
        (binary and 'YiB' or 'YB')
    ]
    if bytes == 1:
        return '1 Byte'
    elif bytes < base:
        return '%d Bytes' % bytes
    else:
        for i, prefix in enumerate(prefixes):
            unit = base ** (i + 2)
            if bytes < unit:
                return '%.1f %s' % ((base * bytes / unit), prefix)
        return '%.1f %s' % ((base * bytes / unit), prefix)
1275684
def pretty_bytes(num):
    
    for unit in ['', 'KB', 'MB', 'GB']:
        if num < 1024.0:
            if unit == '':
                return "%d" % (num)
            else:
                return "%3.1f%s" % (num, unit)
        num /= 1024.0
    return "%3.1f%s" % (num, 'TB')
1282273
def _unit_info(self) -> Tuple[str, int]:
        
        abs_bytes = abs(self.size)
        if abs_bytes < 1024:
            unit = 'B'
            unit_divider = 1
        elif abs_bytes < (1024 ** 2):
            unit = 'KB'
            unit_divider = 1024
        elif abs_bytes < (1024 ** 3):
            unit = 'MB'
            unit_divider = (1024 ** 2)
        elif abs_bytes < (1024 ** 4):
            unit = 'GB'
            unit_divider = (1024 ** 3)
        else:
            unit = 'TB'
            unit_divider = (1024 ** 4)

        return unit, unit_divider
754170
def format_size(self, bytes):
        
        # b
        if bytes < 1024:
            return "{}{}".format(colorize(round(
                bytes, 2), "purple"),
                bold("bytes"))
        # kb
        elif bytes < (1024*1000):
            return "{}{}".format(colorize(round(
                bytes/1024, 2), "purple"),
                bold("kB"))
        # mb
        elif bytes < (1024*1024):
            return "{}{}".format(colorize(round(
                bytes/1024, 2), "purple"),
                bold("MB"))
504815
def get_unit_name(self, surf, name, radius):
    """"""
    key = (name, radius)
    if key not in self._name_lengths:
      max_len = surf.world_to_surf.fwd_dist(radius * 1.6)
      for i in range(len(name)):
        if self._font_small.size(name[:i + 1])[0] > max_len:
          self._name_lengths[key] = name[:i]
          break
      else:
        self._name_lengths[key] = name
    return self._name_lengths[key]
257565
public UnitValue convert(UnitValue value, UnitFactorSet factorSet) {
    value = convert(value, factorSet.base());
    BigDecimal n = value.amount();
    
    // Use absolute value to simplify comparisons with divisors
    boolean negative = false;
    if (n.signum() == -1) {
      negative = true;
      n = n.abs();
    }
    
    List<UnitValue> factors = factorSet.factors();
    int size = factors.size();
    int last = size - 1;
    for (int i = 0; i < size; i++) {
      UnitValue factor = factors.get(i);
      BigDecimal divisor = factor.amount();
      if (divisor == null) {
        continue;
      }
      
      // Use this divisor if it is <= the number or if we've run out of
      // factors to try.
      if (divisor.compareTo(n) <= 0 || i == last) {
        int scale = n.precision() + divisor.precision();
        n = n.divide(divisor, scale, RoundingMode.HALF_EVEN);
        if (negative) {
          n = n.negate();
        }
        return new UnitValue(n.stripTrailingZeros(), factor.unit());
      }
    }

    // Should only be reached if list of factors is empty.
    return value;
  }
295296
def unit_string
      use_dimension
      a = []
      a << Utils.num_inspect(@factor) if @factor!=1
      a += @dim.map do |k,d|
        if d==1
          k
        else
          "#{k}^#{d}"
        end
      end
      a.join(" ")
    end
1115401
def calculate_size(name, items):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    for items_item in items:
        data_size += calculate_size_data(items_item)
    return data_size