• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python values_string.W_String类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: num2str

def num2str(a, radix):
    from rpython.rlib.rbigint import BASE8, BASE16
    if radix.value == 10:
        return W_String.fromascii(a.tostring())
    else:
        if isinstance(a, values.W_Fixnum):
            if radix.value == 16:
                res = hex(a.value)
                if a.value >= 0:
                    res = res[2:]
                else:
                    res = "-" + res[3:]
                return W_String.fromascii(res)
            #elif radix.value == 8:
            #    return W_String.fromascii(oct(a.value))
            # elif radix.value == 2:
            #     return W_String.fromascii(bin(a.value))
            else:
                raise SchemeException("number->string: radix unsupported")
        elif isinstance(a, values.W_Bignum):
            if radix.value == 16:
                return W_String.fromascii(a.value.format(BASE16))
            elif radix.value == 8:
                return W_String.fromascii(a.value.format(BASE8))
            elif radix.value == 2:
                return W_String.fromascii(a.value.format("01"))
            else:
                raise SchemeException("number->string: radix unsupported")
        elif isinstance(a, values.W_Flonum):
            raise SchemeException("number->string: flonum only supports radix 10")
        else:
            assert 0 # not reached
开发者ID:8l,项目名称:pycket,代码行数:32,代码来源:string.py


示例2: string

def string(args):
    if len(args) == 0:
        return W_String.fromascii("")
    assert len(args) > 0
    builder = UnicodeBuilder()
    # XXX could do one less copy in the ascii case
    for char in args:
        if not isinstance(char, values.W_Character):
            raise SchemeException("string: expected a character")
        builder.append(char.value)
    return W_String.fromunicode(builder.build())
开发者ID:8l,项目名称:pycket,代码行数:11,代码来源:string.py


示例3: make_string

def make_string(k, char):
    if char is None:
        char = u'\0'
    else:
        char = char.value
    c = ord(char)
    if k.value < 0:
        raise SchemeException("make-string: around negative")
    if c < 128:
        char = chr(c)
        return W_String.fromascii(char * k.value)
    else:
        char = unichr(c)
        return W_String.fromunicode(char * k.value)
开发者ID:8l,项目名称:pycket,代码行数:14,代码来源:string.py


示例4: read_fasl_integer_stream

    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,代码行数:33,代码来源:fasl.py


示例5: fasl_integer_inner

    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,代码行数:27,代码来源:fasl.py


示例6: char_utf_8_length

def char_utf_8_length(char):
    # same as (bytes-length (string->bytes/utf-8 (string char)))
    builder = UnicodeBuilder()
    builder.append(char.value)
    w_str = W_String.fromunicode(builder.build())
    w_bytes = values.W_Bytes.from_charlist(w_str.as_charlist_utf8())
    return values.W_Fixnum(w_bytes.length())
开发者ID:pycket,项目名称:pycket,代码行数:7,代码来源:string.py


示例7: bytes_to_string_latin

def bytes_to_string_latin(w_bytes, err, start, end):
    str = w_bytes.as_str().decode("latin-1")

    # From Racket Docs: The err-char argument is ignored, but present
    # for consistency with the other operations.

    return get_substring(W_String.fromunicode(str), start, end)
开发者ID:pycket,项目名称:pycket,代码行数:7,代码来源:string.py


示例8: actual_entry

    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,代码行数:31,代码来源:entry_point.py


示例9: cms_context

def cms_context(marks):
    from pycket.values_string import W_String
    # TODO: Pycket does not have a mark to denote context. We need to fix that.

    k = marks.cont
    n = 0
    # find out the length
    while isinstance(k, Cont):
        if is_ast_cont_with_surrounding_lambda(k):
            n += 1
        k = k.get_previous_continuation()

    # second traversal saves us from reversing it later
    ls = [None]*n
    k = marks.cont
    i = n-1
    while isinstance(k, Cont):
        if is_ast_cont_with_surrounding_lambda(k):
            surrounding_lam = k.get_ast().surrounding_lambda
            lam_str = W_String.make(surrounding_lam.tostring())
            ls[i] = values.W_Cons.make(lam_str, values.w_false)
            i -= 1
        k = k.get_previous_continuation()

    return values.to_list(ls)
开发者ID:pycket,项目名称:pycket,代码行数:25,代码来源:continuation_marks.py


示例10: actual_entry

    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,代码行数:34,代码来源:entry_point.py


示例11: load_linklet_from_fasl

def load_linklet_from_fasl(file_name, set_version=False):
    from pycket.fasl import Fasl
    from pycket.env import w_version
    from pycket.util import console_log
    from pycket.ast_vs_sexp import deserialize_loop

    debug_start("loading-linklet")
    debug_print("Loading linklet from fasl -- %s" % file_name)
    sexp = Fasl().to_sexp_from_file(file_name)
    version_sexp, linklet_sexp = W_String.make(""), None
    if set_version:
        version_sexp = sexp.car()
        linklet_sexp = sexp.cdr()
    else:
        linklet_sexp = sexp
    linklet = None
    if "zo" in file_name:
        linklet = deserialize_loop(linklet_sexp)
    else:
        console_log("Run pycket with --make-linklet-zos to make the compiled zo files for bootstrap linklets", 1)
        compile_linklet = get_primitive("compile-linklet")
        linklet = compile_linklet.call_interpret([linklet_sexp, W_Symbol.make("linkl"), w_false, w_false, w_false])

    if set_version:
        ver = version_sexp.as_str_ascii()
        console_log("Setting the version to %s" % ver)
        w_version.set_version(ver)

    debug_stop("loading-linklet")
    return linklet, version_sexp
开发者ID:pycket,项目名称:pycket,代码行数:30,代码来源:racket_entry.py


示例12: string_append

def string_append(args):
    if not args:
        return W_String.fromascii("")
    builder = StringBuilder()
    unibuilder = None
    for a in args:
        if not isinstance(a, W_String):
            raise SchemeException("string-append: expected a string")
        if unibuilder is None:
            try:
                builder.append(a.as_str_ascii())
                continue
            except ValueError:
                unibuilder = UnicodeBuilder()
                unibuilder.append(unicode(builder.build()))
        unibuilder.append(a.as_unicode())
    if unibuilder is None:
        return W_String.fromascii(builder.build())
    else:
        return W_String.fromunicode(unibuilder.build())
开发者ID:8l,项目名称:pycket,代码行数:20,代码来源:string.py


示例13: configure_runtime

def configure_runtime(m):
    dynamic_require = get_primitive("dynamic-require")
    module_declared = get_primitive("module-declared?")
    join = get_primitive("module-path-index-join")
    submod = W_WrappedConsProper.make(W_Symbol.make("submod"),
                                      W_WrappedConsProper.make(W_String.make("."),
                                                               W_WrappedConsProper(W_Symbol.make("configure-runtime"), w_null)))

    config_m = join.call_interpret([submod, m])
    if module_declared.call_interpret([config_m, w_true]) is w_true:
        dynamic_require.call_interpret([config_m, w_false])
开发者ID:pycket,项目名称:pycket,代码行数:11,代码来源:racket_entry.py


示例14: namespace_require_plus

def namespace_require_plus(spec):
    namespace_require = get_primitive("namespace-require")
    dynamic_require = get_primitive("dynamic-require")
    module_declared = get_primitive("module-declared?")
    join = get_primitive("module-path-index-join")
    m = join.call_interpret([spec, w_false])
    submod = W_WrappedConsProper.make(W_Symbol.make("submod"),
                                      W_WrappedConsProper.make(W_String.make("."),
                                                               W_WrappedConsProper(W_Symbol.make("main"), w_null)))
    # FIXME: configure-runtime
    if need_runtime_configure[0]:
        configure_runtime(m)
        need_runtime_configure[0] = False
    namespace_require.call_interpret([m])
    main = join.call_interpret([submod, m])
    if module_declared.call_interpret([main, w_true]) is w_true:
        dynamic_require.call_interpret([main, w_false])
开发者ID:pycket,项目名称:pycket,代码行数:17,代码来源:racket_entry.py


示例15: actual_entry

    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,代码行数:23,代码来源:entry_point.py


示例16: symbol_to_string

def symbol_to_string(v):
    if v.asciivalue is not None:
        return W_String.fromascii(v.asciivalue)
    return W_String.fromunicode(v.unicodevalue)
开发者ID:8l,项目名称:pycket,代码行数:4,代码来源:string.py


示例17: string_to_keyword

def string_to_keyword(keyword):
    return W_String.make(keyword.value)
开发者ID:pycket,项目名称:pycket,代码行数:2,代码来源:string.py


示例18: racket_read_str

def racket_read_str(expr_str):
    ois = get_primitive("open-input-string")

    str_port = check_one_val(ois.call_interpret([W_String.make(expr_str)]))

    return racket_read(str_port)
开发者ID:pycket,项目名称:pycket,代码行数:6,代码来源:racket_entry.py


示例19: racket_read_file

def racket_read_file(file_name):
    oif = get_primitive("open-input-file")

    in_port = oif.call_interpret([W_String.make(file_name)])

    return racket_read(in_port)
开发者ID:pycket,项目名称:pycket,代码行数:6,代码来源:racket_entry.py


示例20: symbol_to_string_impl

def symbol_to_string_impl(v):
    asciivalue = v.asciivalue()
    if asciivalue is not None:
        return W_String.fromascii(asciivalue)
    return W_String.fromunicode(v.unicodevalue())
开发者ID:pycket,项目名称:pycket,代码行数:5,代码来源:string.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.run_app_from_main函数代码示例发布时间:2022-05-25
下一篇:
Python values.to_list函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap