Parse a size string (i.e. "200", "200x100", "x200", etc.) into a
        (width, height) tuple.
336206
def parse_size(image, size):
        
        bits = size.split("x")
        if image.size[0] == 0 or image.size[1] == 0:
            ratio = 1.0
        else:
            ratio = float(image.size[0]) / float(image.size[1])

        if len(bits) == 1 or not bits[1]:
            width = int(bits[0])
            height = int(1 / ratio * width)
        elif not bits[0]:
            height = int(bits[1])
            width = int(height * ratio)
        else:
            width, height = map(int, bits)
        return width, height
843552
def bytes_from_string(value):
    
    BYTE_POWER = {
        'K': 1,
        'KB': 1,
        'M': 2,
        'MB': 2,
        'G': 3,
        'GB': 3,
        'T': 4,
        'TB': 4,
        'P': 5,
        'PB': 5,
    }
    if isinstance(value, six.string_types):
        value = six.text_type(value)
    else:
        msg = "Unable to interpret non-string value '%s' as bytes" % (value)
        raise ValueError(msg)
    matches = re.match("([0-9]+)([a-zA-Z]+)", value)
    if matches:
        size = int(matches.group(1)) * (1024 ** BYTE_POWER[matches.group(2)])
    else:
        # Assume that value passed in is bytes
        try:
            size = int(value)
        except ValueError:
            msg = "Unable to interpret string value '%s' as bytes" % (value)
            raise ValueError(msg)
    return size
622566
def parse_fixed_width(types, lines):
    """"""
    values = []
    line = []
    for width, parser in types:
        if not line:
            line = lines.pop(0).replace('\n', '')

        values.append(parser(line[:width]))
        line = line[width:]

    return values
809188
def strsize (b):
    """"""
    if b < 0:
        raise ValueError("Invalid negative byte number")
    if b < 1024:
        return "%dB" % b
    if b < 1024 * 10:
        return "%dKB" % (b // 1024)
    if b < 1024 * 1024:
        return "%.2fKB" % (float(b) / 1024)
    if b < 1024 * 1024 * 10:
        return "%.2fMB" % (float(b) / (1024*1024))
    if b < 1024 * 1024 * 1024:
        return "%.1fMB" % (float(b) / (1024*1024))
    if b < 1024 * 1024 * 1024 * 10:
        return "%.2fGB" % (float(b) / (1024*1024*1024))
    return "%.1fGB" % (float(b) / (1024*1024*1024))
351429
def _pad(string, size):
    
    strlen = len(string)
    if strlen == size:
        return string
    if strlen < size:
        return _padding[0:size-strlen] + string
    return string[-size:]
779705
def split_size(size):
    ''''''
    rem = size % CHUNK_SIZE
    if rem == 0:
        cnt = size // CHUNK_SIZE
    else:
        cnt = size // CHUNK_SIZE + 1

    chunks = []
    for i in range(cnt):
        pos = i * CHUNK_SIZE
        if i == cnt - 1:
            disp = size - pos
        else:
            disp = CHUNK_SIZE
        chunks.append((pos, disp))
    return chunks
221939
private String sizeToString(final long aSizeInBytes) {
        final String size = sizeFromBytes(aSizeInBytes, true).replace(" ", "");
        return size.substring(0, size.length() - 1);
    }
814967
def parse_response(response):
    
    if isinstance(response, tuple):
        if len(response) > 2:
            return response[0], response[1], response[2]
        elif len(response) > 1:
            return response[0], response[1], {}
    try:
        return response.data, response.status_code, response.headers
    except AttributeError:
        return response, 200, {}
243717
function parse(size) {
  var matches = size.match(regexp);

  if (!matches)
    return null;

  var multiplicator = matches[3] ? +matches[3].replace(/x$/, '') : 1;

  return {
    width: +matches[1] * multiplicator,
    height: +matches[2] * multiplicator
  };
}
456455
def get_string_width(self, s):
        ""
        s = self.normalize_text(s)
        cw=self.current_font['cw']
        w=0
        l=len(s)
        if self.unifontsubset:
            for char in s:
                char = ord(char)
                if len(cw) > char:
                    w += cw[char] # ord(cw[2*char])<<8 + ord(cw[2*char+1])
                #elif (char>0 and char<128 and isset($cw[chr($char)])) { $w += $cw[chr($char)]; }
                elif (self.current_font['desc']['MissingWidth']) :
                    w += self.current_font['desc']['MissingWidth']
                #elif (isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
                else:
                    w += 500
        else:
            for i in range(0, l):
                w += cw.get(s[i],0)
        return w*self.font_size/1000.0
1011754
def parse_angular_length_quantity(string_rep, unit=u.deg):
        
        unit_mapping = {
            '"': u.arcsec,
            "'": u.arcmin,
            'd': u.deg,
            'r': u.rad,
            'i': u.dimensionless_unscaled,
            'p': u.dimensionless_unscaled
        }
        has_unit = string_rep[-1] not in string.digits
        if has_unit:
            unit = unit_mapping[string_rep[-1]]
            return u.Quantity(float(string_rep[:-1]), unit=unit)
        else:
            return u.Quantity(float(string_rep), unit=unit)
1048682
def _pretty_size(size):
    '''
    
    '''
    units = [' G', ' M', ' K', ' B']
    while units and size >= 1000:
        size = size / 1024.0
        units.pop()
    return '{0}{1}'.format(round(size, 1), units[-1])
718413
def parse_term(s):
    """"""
    size, s = s.split(b':', 1)
    size = int(size)
    return s[:size], s[size:]
252353
def _parse_vertex_tuple(s):
  """"""
  vt = [0, 0, 0]
  for i, c in enumerate(s.split('/')):
    if c:
      vt[i] = int(c)
  return tuple(vt)
1365362
def convert_raw_tuple(value_tuple, format_string):
     
    values = []
    for v, c in zip(value_tuple, format_string):
        if v is None:
            # append None
            values.append(v)
        elif c == u"s":
            # string
            values.append(v)
        elif c == u"S":
            # string, split using space as delimiter
            values.append([s for s in v.split(u" ") if len(s) > 0])
        elif c == u"i":
            # int
            values.append(int(v))
        elif c == u"U":
            # Unicode
            values.append(convert_unicode_field(v))
        elif c == u"A":
            # ASCII
            values.append(convert_ascii_field(v))
        #elif c == u"x":
        #    # ignore
        #    pass
    return tuple(values)
1274670
def hsize(bytes):
    """"""
    sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
    if bytes == 0:
        return '0 Byte'
    i = int(math.floor(math.log(bytes) / math.log(1024)))
    r = round(bytes / math.pow(1024, i), 2)
    return str(r) + '' + sizes[i]
757707
def _size_map(size):
    '''
    
    '''
    try:
        # I know, I know, EAFP.
        # But everything else is reason for None
        if not isinstance(size, int):
            if re.search(r'[Kk]', size):
                size = 1024 * float(re.sub(r'[Kk]', '', size))
            elif re.search(r'[Mm]', size):
                size = 1024**2 * float(re.sub(r'[Mm]', '', size))
            size = int(size)
        return size
    except Exception:
        return None