Example #1
0
def to_s1(integer, base):
    if base == 2:
        format_char = 'b'
    elif base == 8:
        format_char = 'o'
    elif base == 16:
        format_char = 'x'
    else:
        raise Rb2PyValueError(
            'to_s1() can convert only to base 2, 8 or 16. Unsupported base: ' +
            str(base))
    return String(('{:' + format_char + '}').format(integer))
Example #2
0
def pack1(sequence, format):
    string = String()
    string.pack(sequence, format)
    return string
Example #3
0
def name0(cls):
    return String(cls.__qualname__.replace('.', '::'))
Example #4
0
def join0(array):
    return String('').join(array)
Example #5
0
def inspect0(object):
    return String(repr(object))
Example #6
0
def s(string):
    return String(string)
Example #7
0
def file_foreach(path):
    with open(str(path)) as f:
        for line in f:
            yield String(line)
Example #8
0
def chr0(integer):
    return String(chr(integer))
Example #9
0
def unpack1(string, format):
    if isinstance(string, ArrayABC):
        return String.from_byte_list(string).unpack(format)
    raise Rb2PyNotImplementedError('unpack')
Example #10
0
def to_s0(object):
    return String(str(object))
Example #11
0
def String1(object):
    method = responds_to(object, 'to_str')
    return method() if method else String(object)
Example #12
0
# Aliases
SEEK_CUR = io.SEEK_CUR
SEEK_END = io.SEEK_END
SEEK_SET = io.SEEK_SET

# Abstract Base Classes

ArrayABC = abc.MutableSequence
HashABC = abc.MutableMapping
NumberABC = numbers.Number

# Globals

env = OrderedDict()
for name, value in os.environ.items():
    env[String(name)] = String(value)


class NoBlock(object):
    def __bool__(self):
        return False


NO_BLOCK = NoBlock()

# Helpers


def s(string):
    return String(string)