当前位置: 首页>>代码示例>>Python>>正文


Python W_String.fromstr_utf8方法代码示例

本文整理汇总了Python中pycket.values_string.W_String.fromstr_utf8方法的典型用法代码示例。如果您正苦于以下问题:Python W_String.fromstr_utf8方法的具体用法?Python W_String.fromstr_utf8怎么用?Python W_String.fromstr_utf8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycket.values_string.W_String的用法示例。


在下文中一共展示了W_String.fromstr_utf8方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: actual_entry

# 需要导入模块: from pycket.values_string import W_String [as 别名]
# 或者: from pycket.values_string.W_String import fromstr_utf8 [as 别名]
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)

        entry_flag = 'byte-expand' in names
        reader = JsonLoader(bytecode_expand=entry_flag)
        if json_ast is None:
            ast = reader.expand_to_ast(module_name)
        else:
            ast = reader.load_json_ast_rpython(module_name, json_ast)

        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown
            if config.get('save-callgraph', False):
                with open('callgraph.dot', 'w') as outfile:
                    env.callgraph.write_dot_file(outfile)
            shutdown(env)
        return 0
开发者ID:rjnw,项目名称:pycket,代码行数:33,代码来源:entry_point.py

示例2: actual_entry

# 需要导入模块: from pycket.values_string import W_String [as 别名]
# 或者: from pycket.values_string.W_String import fromstr_utf8 [as 别名]
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)

        if NonConstant(False):
            # Hack to give os.open() the correct annotation
            os.open("foo", 1, 1)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)

        modtable = ModTable()
        modtable.enter_module(module_name)
        if json_ast is None:
            ast = expand_to_ast(module_name, modtable)
        else:
            ast = load_json_ast_rpython(json_ast, modtable)
        modtable.exit_module(module_name, ast)

        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown

            shutdown(env)
        return 0
开发者ID:uternet,项目名称:pycket,代码行数:36,代码来源:entry_point.py

示例3: read_fasl_integer_stream

# 需要导入模块: from pycket.values_string import W_String [as 别名]
# 或者: from pycket.values_string.W_String import fromstr_utf8 [as 别名]
    def read_fasl_integer_stream(self, stream):
        from pycket import values as v
        from pycket.prims.numeric import _integer_bytes_to_integer
        from pycket.prims.string import _str2num
        from pycket.values_string import W_String
        _b = stream.read(1)[0]
        if not _b:
            raise Exception("truncated stream - got eof")

        b = ord(_b)

        if b <= 127:
            return b
        elif b >= 132:
            return b-256
        elif b == 128:
            num_str = self.read_bytes_exactly_stream(stream, 2)
            return _integer_bytes_to_integer(list(num_str), v.w_true, v.w_false).toint()
        elif b == 129:
            num_str = self.read_bytes_exactly_stream(stream, 4)
            return _integer_bytes_to_integer(list(num_str), v.w_true, v.w_false).toint()
        elif b == 130:
            num_str = self.read_bytes_exactly_stream(stream, 8)
            return _integer_bytes_to_integer(list(num_str), v.w_true, v.w_false).toint()
        elif b == 131:
            length = self.read_fasl_integer_stream(stream)
            assert isinstance(length, int)
            num_str = self.read_bytes_exactly_stream(stream, length)
            if len(num_str) != length:
                raise Exception("fasl: truncated stream at number")
            return _str2num(W_String.fromstr_utf8(num_str).as_str_utf8(), 16).toint()
        else:
            raise Exception("fasl: internal error on integer mode")
开发者ID:pycket,项目名称:pycket,代码行数:35,代码来源:fasl.py

示例4: fasl_integer_inner

# 需要导入模块: from pycket.values_string import W_String [as 别名]
# 或者: from pycket.values_string.W_String import fromstr_utf8 [as 别名]
    def fasl_integer_inner(self, fasl_string, pos, b):
        from pycket import values as v
        from pycket.prims.numeric import _integer_bytes_to_integer
        from pycket.prims.string import _str2num
        from pycket.values_string import W_String

        if b <= 127:
            return b, pos
        elif b >= 132:
            return b-256, pos
        elif b == 128:
            num_str, pos = self.read_bytes_exactly(fasl_string, pos, 2)
            return _integer_bytes_to_integer(list(num_str), v.w_true, v.w_false).toint(), pos
        elif b == 129:
            num_str, pos = self.read_bytes_exactly(fasl_string, pos, 4)
            return _integer_bytes_to_integer(list(num_str), v.w_true, v.w_false).toint(), pos
        elif b == 130:
            num_str, pos = self.read_bytes_exactly(fasl_string, pos, 8)
            return _integer_bytes_to_integer(list(num_str), v.w_true, v.w_false).toint(), pos
        elif b == 131:
            length, pos = self.read_fasl_integer(fasl_string, pos)
            num_str, pos = self.read_fasl_string(fasl_string, pos, length)
            if len(num_str) != length:
                raise Exception("fasl: truncated stream at number")
            return _str2num(W_String.fromstr_utf8(num_str).as_str_utf8(), 16).toint(), pos
        else:
            raise Exception("fasl: internal error on integer mode")
开发者ID:pycket,项目名称:pycket,代码行数:29,代码来源:fasl.py

示例5: actual_entry

# 需要导入模块: from pycket.values_string import W_String [as 别名]
# 或者: from pycket.values_string.W_String import fromstr_utf8 [as 别名]
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)
        modtable = ModTable()
        if json_ast is None:
            ast = expand_to_ast(module_name, modtable)
        else:
            ast = load_json_ast_rpython(json_ast, modtable)
        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown
            shutdown(env)
        return 0
开发者ID:rrnewton,项目名称:pycket,代码行数:25,代码来源:entry_point.py

示例6: string_to_bytes_locale

# 需要导入模块: from pycket.values_string import W_String [as 别名]
# 或者: from pycket.values_string.W_String import fromstr_utf8 [as 别名]
def string_to_bytes_locale(bytes, errbyte, start, end):
    # FIXME: This ignores the locale
    return W_String.fromstr_utf8(bytes.as_str())
开发者ID:8l,项目名称:pycket,代码行数:5,代码来源:string.py

示例7: fasl_to_sexp_recursive

# 需要导入模块: from pycket.values_string import W_String [as 别名]
# 或者: from pycket.values_string.W_String import fromstr_utf8 [as 别名]
    def fasl_to_sexp_recursive(self, fasl_string, pos):
        from pycket import values as v
        from pycket.values_string import W_String
        from pycket.values_regex import W_Regexp, W_PRegexp, W_ByteRegexp, W_BytePRegexp
        from pycket.vector import W_Vector
        from pycket.values_struct import W_Struct
        from pycket.hash import simple as hash_simple
        from pycket.hash.equal import W_EqualHashTable
        from pycket.prims.numeric import float_bytes_to_real
        from pycket.prims.string import _str2num
        from rpython.rlib.rbigint import rbigint
        from pycket.prims.input_output import build_path, bytes_to_path_element
        from pycket.ast_vs_sexp import to_rpython_list

        typ, pos = self.read_byte_no_eof(fasl_string, pos)

        if typ == FASL_GRAPH_DEF_TYPE:
            position, pos = self.read_fasl_integer(fasl_string, pos)
            val, pos = self.fasl_to_sexp_recursive(fasl_string, pos)
            if position >= self.GLOBAL_SHARED_COUNT:
                raise Exception("fasl: bad graph index")
            self.SHARED[position] = val
            return val, pos
        elif typ == FASL_GRAPH_REF_TYPE:
            position, pos = self.read_fasl_integer(fasl_string, pos)
            if position >= self.GLOBAL_SHARED_COUNT:
                raise Exception("fasl: bad graph index")
            return self.SHARED[position], pos
        elif typ == FASL_FALSE_TYPE:
            return v.w_false, pos
        elif typ == FASL_TRUE_TYPE:
            return v.w_true, pos
        elif typ == FASL_NULL_TYPE:
            return v.w_null, pos
        elif typ == FASL_VOID_TYPE:
            return v.w_void, pos
        elif typ == FASL_EOF_TYPE:
            return v.eof_object, pos
        elif typ == FASL_INTEGER_TYPE:
            num, pos = self.read_fasl_integer(fasl_string, pos)
            if isinstance(num, rbigint):
                return v.W_Bignum(num), pos
            return v.W_Fixnum(num), pos
        elif typ == FASL_FLONUM_TYPE:
            num_str, pos = self.read_bytes_exactly(fasl_string, pos, 8)
            return float_bytes_to_real(list(num_str), v.w_false), pos
        elif typ == FASL_SINGLE_FLONUM_TYPE:
            num_str, pos = self.read_bytes_exactly(fasl_string, pos, 4)
            real = float_bytes_to_real(list(num_str), v.w_false)
            return real.arith_exact_inexact(), pos
        elif typ == FASL_EXTFLONUM_TYPE:
            bstr_len, pos = self.read_fasl_integer(fasl_string, pos)
            num_str, pos = self.read_bytes_exactly(fasl_string, pos, bstr_len)
            return _str2num(W_String.fromstr_utf8(num_str).as_str_utf8(), 10), pos
        elif typ == FASL_RATIONAL_TYPE:
            num, pos = self.fasl_to_sexp_recursive(fasl_string, pos)
            den, pos = self.fasl_to_sexp_recursive(fasl_string, pos)
            return v.W_Rational.make(num, den), pos
        elif typ == FASL_COMPLEX_TYPE:
            re, pos = self.fasl_to_sexp_recursive(fasl_string, pos)
            im, pos = self.fasl_to_sexp_recursive(fasl_string, pos)
            return v.W_Complex.from_real_pair(re, im), pos
        elif typ == FASL_CHAR_TYPE:
            _chr, pos = self.read_fasl_integer(fasl_string, pos)
            return v.W_Character(unichr(_chr)), pos
        elif typ == FASL_SYMBOL_TYPE:
            sym_str, pos = self.read_fasl_string(fasl_string, pos)
            return v.W_Symbol.make(sym_str), pos
        elif typ == FASL_UNREADABLE_SYMBOL_TYPE:
            sym_str, pos = self.read_fasl_string(fasl_string, pos)
            return v.W_Symbol.make_unreadable(sym_str), pos
        elif typ == FASL_UNINTERNED_SYMBOL_TYPE:
            sym_str, pos = self.read_fasl_string(fasl_string, pos)
            return v.W_Symbol(sym_str), pos
        elif typ == FASL_KEYWORD_TYPE:
            key_str, pos = self.read_fasl_string(fasl_string, pos)
            return v.W_Keyword.make(key_str), pos
        elif typ == FASL_STRING_TYPE:
            str_str, pos = self.read_fasl_string(fasl_string, pos)
            return W_String.make(str_str), pos
        elif typ == FASL_IMMUTABLE_STRING_TYPE:
            str_str, pos = self.read_fasl_string(fasl_string, pos)
            return W_String.make(str_str).make_immutable(), pos
        elif typ == FASL_BYTES_TYPE:
            byts, pos = self.read_fasl_bytes(fasl_string, pos)
            return v.W_Bytes.from_string(byts, immutable=False), pos
        elif typ == FASL_IMMUTABLE_BYTES_TYPE:
            byts, pos = self.read_fasl_bytes(fasl_string, pos)
            return v.W_Bytes.from_string(byts), pos
        elif typ == FASL_PATH_TYPE:
            byts, pos = self.read_fasl_bytes(fasl_string, pos)
            return v.W_Path(byts), pos
        elif typ == FASL_RELATIVE_PATH_TYPE:
            wrt_dir = self.current_relative_dir
            p_w_lst, pos = self.fasl_to_sexp_recursive(fasl_string, pos)
            p_r_lst, _ = to_rpython_list(p_w_lst)
            rel_elems = [bytes_to_path_element(p) if isinstance(p, v.W_Bytes) else p for p in p_r_lst]
            if wrt_dir:
                return build_path([wrt_dir] + rel_elems), pos
            elif rel_elems == []:
#.........这里部分代码省略.........
开发者ID:pycket,项目名称:pycket,代码行数:103,代码来源:fasl.py


注:本文中的pycket.values_string.W_String.fromstr_utf8方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。