def EvaluationEnvironment(code, session_data={}, constants=None, **extra):

    session_data["__loader__"] = Settings(get_source=lambda module, code=code: code)
    session_data["__traceback_hidden_variables__"] = HIDDEN_VARIABLES
    if constants:
        session_data.update(constants)

    return session_data
Пример #2
0

WXF_VERSION = b'8'
WXF_HEADER_SEPARATOR = b':'
WXF_HEADER_COMPRESS = b'C'

#The list of all the WXF tokens.
WXF_CONSTANTS = Settings(
    Function=b'f',
    Symbol=b's',
    String=b'S',
    BinaryString=b'B',
    Integer8=b'C',
    Integer16=b'j',
    Integer32=b'i',
    Integer64=b'L',
    Real64=b'r',
    BigInteger=b'I',
    BigReal=b'R',
    PackedArray=_bytes(0xC1),
    NumericArray=_bytes(0xC2),
    Association=b'A',
    Rule=b'-',
    RuleDelayed=b':',
)

#The list of all array value type tokens.
ARRAY_TYPES = Settings(
    Integer8=_bytes(0x00),
    Integer16=_bytes(0x01),
    Integer32=_bytes(0x02),
    Integer64=_bytes(0x03),
def packed_array_to_wxf(data, dimensions, wl_type):
    array_type_token = ARRAY_TYPES[wl_type]
    if array_type_token not in VALID_PACKED_ARRAY_TYPES:
        raise ValueError("Invalid PackedArray type %s" % array_type_token)
    return array_to_wxf(WXF_CONSTANTS.PackedArray, data, dimensions,
                        array_type_token)


def array_to_list(data, dimensions, wl_type):
    for dimension in dimensions:
        valid_dimension_or_fail(dimension)
    return _array_to_list(data, dimensions, wl_type)


if hasattr(memoryview, "cast"):
    unpack_mapping = Settings(
        (k, last(v.format)) for k, v in STRUCT_MAPPING.items())

    def _to_complex(array, max_depth, curr_depth):
        # recursivelly traverse the array until the last (real) dimension is reached
        # it correspond to an array of (fake) array of two elements (real and im parts).
        if curr_depth < max_depth - 1:
            for sub in array:
                _to_complex(sub, max_depth, curr_depth + 1)
            return
        # iterate over the pairs
        for index, complex_pair in enumerate(array):
            array[index] = complex(*complex_pair)

    def _array_to_list(data, shape, array_type):
        view = memoryview(data)
        if array_type == "ComplexReal32" or array_type == "ComplexReal64":

WXF_VERSION = b"8"
WXF_HEADER_SEPARATOR = b":"
WXF_HEADER_COMPRESS = b"C"

# The list of all the WXF tokens.
WXF_CONSTANTS = Settings(
    Function=b"f",
    Symbol=b"s",
    String=b"S",
    BinaryString=b"B",
    Integer8=b"C",
    Integer16=b"j",
    Integer32=b"i",
    Integer64=b"L",
    Real64=b"r",
    BigInteger=b"I",
    BigReal=b"R",
    PackedArray=_bytes(0xC1),
    NumericArray=_bytes(0xC2),
    Association=b"A",
    Rule=b"-",
    RuleDelayed=b":",
)

# The list of all array value type tokens.
ARRAY_TYPES = Settings(
    Integer8=_bytes(0x00),
    Integer16=_bytes(0x01),
    Integer32=_bytes(0x02),
    Integer64=_bytes(0x03),
Пример #5
0

def array_to_list(data, dimensions, wl_type):
    for dimension in dimensions:
        valid_dimension_or_fail(dimension)
    return _array_to_list(data, dimensions, wl_type)


if hasattr(memoryview, "cast"):
    unpack_mapping = Settings(
        Integer8="b",
        UnsignedInteger8="B",
        Integer16="h",
        UnsignedInteger16="H",
        Integer32="i",
        UnsignedInteger32="I",
        Integer64="q",
        UnsignedInteger64="Q",
        Real32="f",
        Real64="d",
        ComplexReal32="f",
        ComplexReal64="d",
    )

    def _to_complex(array, max_depth, curr_depth):
        # recursivelly traverse the array until the last (real) dimension is reached
        # it correspond to an array of (fake) array of two elements (real and im parts).
        if curr_depth < max_depth - 1:
            for sub in array:
                _to_complex(sub, max_depth, curr_depth + 1)
            return
        # iterate over the pairs