kitir/_libs/byte_utils.py
def human2bytes(s):
    """
    Attempts to guess the string format based on default symbols
    set and return the corresponding bytes as an integer.
    When unable to recognize the format ValueError is raised.
    """
    # Bytes-to-human / human-to-bytes converter.
    # Based on: http://goo.gl/kTQMs
    # Working with Python 2.x and 3.x.
    #
    # Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
    # License: MIT
    # copied from: http://code.activestate.com/recipes/578019-bytes-to-human-human-to-bytes-converter/?in=user-4178764
    init = s
    num = ""
    while s and s[0:1].isdigit() or s[0:1] == '.':
        num += s[0]
        s = s[1:]
    num = float(num)
    letter = s.strip()
    for name, sset in SYMBOLS.items():
        if letter in sset:
            break
    else:
        if letter == 'k':  # treat 'k' as an alias for 'K' as per: http://goo.gl/kTQMs
            sset = SYMBOLS['customary']
            letter = letter.upper()
        else:
            raise ValueError("can't interpret %r" % init)
    prefix = {sset[0]: 1}
    for i, s in enumerate(sset[1:]):
        prefix[s] = 1 << (i + 1) * 10
    return int(num * prefix[letter])

    Attempts to guess the string format based on default symbols
    set and return the corresponding bytes as an integer.
    When unable to recognize the format ValueError is raised.
    
Attempts to guess the string format based on default symbols
set and return the corresponding bytes as an integer.
When unable to recognize the format ValueError is raised.
Attempts to guess the string format based on default symbols set and return the corresponding bytes as an integer . When unable to recognize the format ValueError is raised .
def human2bytes(s):
     Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
     License: MIT
     copied from: http://code.activestate.com/recipes/578019-bytes-to-human-human-to-bytes-converter/?in=user-4178764
    init = s
    num = ""
    while s and s[0:1].isdigit() or s[0:1] == '.':
        num += s[0]
        s = s[1:]
    num = float(num)
    letter = s.strip()
    for name, sset in SYMBOLS.items():
        if letter in sset:
            break
    else:
        if letter == 'k':   treat 'k' as an alias for 'K' as per: http://goo.gl/kTQMs
            sset = SYMBOLS['customary']
            letter = letter.upper()
        else:
            raise ValueError("can't interpret %r" % init)
    prefix = {sset[0]: 1}
    for i, s in enumerate(sset[1:]):
        prefix[s] = 1 << (i + 1) * 10
    return int(num * prefix[letter])
def human2bytes ( s ) : init = s num = "" while s and s [ 0 : 1 ] . isdigit ( ) or s [ 0 : 1 ] == '.' : num += s [ 0 ] s = s [ 1 : ] num = float ( num ) letter = s . strip ( ) for name , sset in SYMBOLS . items ( ) : if letter in sset : break else : if letter == 'k' : sset = SYMBOLS [ 'customary' ] letter = letter . upper ( ) else : raise ValueError ( "can't interpret %r" % init ) prefix = { sset [ 0 ] : 1 } for i , s in enumerate ( sset [ 1 : ] ) : prefix [ s ] = 1 << ( i + 1 ) * 10 return int ( num * prefix [ letter ] )
Attempts to guess the string format based on default symbols
set and return the corresponding bytes as an integer.
Attempts to guess the string format based on default symbols set and return the corresponding bytes as an integer .
"""
    Attempts to guess the string format based on default symbols
    set and return the corresponding bytes as an integer.
    When unable to recognize the format ValueError is raised.
    """ # Bytes-to-human / human-to-bytes converter. # Based on: http://goo.gl/kTQMs # Working with Python 2.x and 3.x. # # Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com> # License: MIT # copied from: http://code.activestate.com/recipes/578019-bytes-to-human-human-to-bytes-converter/?in=user-4178764 # treat 'k' as an alias for 'K' as per: http://goo.gl/kTQMs
s