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


Python rffi.charp2str函数代码示例

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


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

示例1: _Py_InitPyPyModule

def _Py_InitPyPyModule(space, name, methods, doc, w_self, apiver):
    """
    Create a new module object based on a name and table of functions, returning
    the new module object. If doc is non-NULL, it will be used to define the
    docstring for the module. If self is non-NULL, it will passed to the
    functions of the module as their (otherwise NULL) first parameter. (This was
    added as an experimental feature, and there are no known uses in the current
    version of Python.) For apiver, the only value which should be passed is
    defined by the constant PYTHON_API_VERSION.

    Note that the name parameter is actually ignored, and the module name is
    taken from the package_context attribute of the cpyext.State in the space
    cache.  CPython includes some extra checking here to make sure the module
    being initialized lines up with what's expected, but we don't.
    """
    from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
    modname = rffi.charp2str(name)
    state = space.fromcache(State)
    f_name, f_path = state.package_context
    w_mod = PyImport_AddModule(space, f_name)

    dict_w = {'__file__': space.wrap(f_path)}
    convert_method_defs(space, dict_w, methods, None, w_self, modname)
    for key, w_value in dict_w.items():
        space.setattr(w_mod, space.wrap(key), w_value)
    if doc:
        space.setattr(w_mod, space.wrap("__doc__"),
                      space.wrap(rffi.charp2str(doc)))
    return borrow_from(None, w_mod)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:29,代码来源:modsupport.py

示例2: dcgettext

    def dcgettext(space, w_domain, msg, category):
        """dcgettext(domain, msg, category) -> string
        Return translation of msg in domain and category."""

        if space.is_w(w_domain, space.w_None):
            domain = None
            msg_c = rffi.str2charp(msg)
            try:
                result = _dcgettext(domain, msg_c, rffi.cast(rffi.INT, category))
                # note that 'result' may be the same pointer as 'msg_c',
                # so it must be converted to an RPython string *before*
                # we free msg_c.
                result = rffi.charp2str(result)
            finally:
                rffi.free_charp(msg_c)
        else:
            domain = space.str_w(w_domain)
            domain_c = rffi.str2charp(domain)
            msg_c = rffi.str2charp(msg)
            try:
                result = _dcgettext(domain_c, msg_c,
                                    rffi.cast(rffi.INT, category))
                # note that 'result' may be the same pointer as 'msg_c',
                # so it must be converted to an RPython string *before*
                # we free msg_c.
                result = rffi.charp2str(result)
            finally:
                rffi.free_charp(domain_c)
                rffi.free_charp(msg_c)

        return space.wrap(result)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:interp_locale.py

示例3: PyCodec_IncrementalEncoder

def PyCodec_IncrementalEncoder(space, encoding, errors):
    w_codec = interp_codecs.lookup_codec(space, rffi.charp2str(encoding))
    if errors:
        w_errors = space.wrap(rffi.charp2str(errors))
        return space.call_method(w_codec, "incrementalencoder", w_errors)
    else:
        return space.call_method(w_codec, "incrementalencoder")
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:codecs.py

示例4: PyFile_FromString

def PyFile_FromString(space, filename, mode):
    """
    On success, return a new file object that is opened on the file given by
    filename, with a file mode given by mode, where mode has the same
    semantics as the standard C routine fopen().  On failure, return NULL."""
    w_filename = space.wrap(rffi.charp2str(filename))
    w_mode = space.wrap(rffi.charp2str(mode))
    return space.call_method(space.builtin, 'file', w_filename, w_mode)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:pyfile.py

示例5: _ssl_seterror

def _ssl_seterror(space, ss, ret):
    assert ret <= 0

    if ss is None:
        errval = libssl_ERR_peek_last_error()
        errstr = rffi.charp2str(libssl_ERR_error_string(errval, None))
        return ssl_error(space, errstr, errval)
    elif ss.ssl:
        err = libssl_SSL_get_error(ss.ssl, ret)
    else:
        err = SSL_ERROR_SSL
    errstr = ""
    errval = 0

    if err == SSL_ERROR_ZERO_RETURN:
        errstr = "TLS/SSL connection has been closed"
        errval = PY_SSL_ERROR_ZERO_RETURN
    elif err == SSL_ERROR_WANT_READ:
        errstr = "The operation did not complete (read)"
        errval = PY_SSL_ERROR_WANT_READ
    elif err == SSL_ERROR_WANT_WRITE:
        errstr = "The operation did not complete (write)"
        errval = PY_SSL_ERROR_WANT_WRITE
    elif err == SSL_ERROR_WANT_X509_LOOKUP:
        errstr = "The operation did not complete (X509 lookup)"
        errval = PY_SSL_ERROR_WANT_X509_LOOKUP
    elif err == SSL_ERROR_WANT_CONNECT:
        errstr = "The operation did not complete (connect)"
        errval = PY_SSL_ERROR_WANT_CONNECT
    elif err == SSL_ERROR_SYSCALL:
        e = libssl_ERR_get_error()
        if e == 0:
            if ret == 0 or space.is_w(ss.w_socket, space.w_None):
                errstr = "EOF occurred in violation of protocol"
                errval = PY_SSL_ERROR_EOF
            elif ret == -1:
                # the underlying BIO reported an I/0 error
                error = rsocket.last_error()
                return interp_socket.converted_error(space, error)
            else:
                errstr = "Some I/O error occurred"
                errval = PY_SSL_ERROR_SYSCALL
        else:
            errstr = rffi.charp2str(libssl_ERR_error_string(e, None))
            errval = PY_SSL_ERROR_SYSCALL
    elif err == SSL_ERROR_SSL:
        e = libssl_ERR_get_error()
        errval = PY_SSL_ERROR_SSL
        if e != 0:
            errstr = rffi.charp2str(libssl_ERR_error_string(e, None))
        else:
            errstr = "A failure in the SSL library occurred"
    else:
        errstr = "Invalid error code"
        errval = PY_SSL_ERROR_INVALID_ERROR_CODE

    return ssl_error(space, errstr, errval)
开发者ID:MichaelBlume,项目名称:pypy,代码行数:57,代码来源:interp_ssl.py

示例6: make_struct_passwd

def make_struct_passwd(space, pw):
    w_passwd_struct = space.getattr(space.getbuiltinmodule('pwd'),
                                    space.wrap('struct_passwd'))
    w_tuple = space.newtuple([
        space.wrap(rffi.charp2str(pw.c_pw_name)),
        space.wrap(rffi.charp2str(pw.c_pw_passwd)),
        space.wrap(intmask(pw.c_pw_uid)),
        space.wrap(intmask(pw.c_pw_gid)),
        space.wrap(rffi.charp2str(pw.c_pw_gecos)),
        space.wrap(rffi.charp2str(pw.c_pw_dir)),
        space.wrap(rffi.charp2str(pw.c_pw_shell)),
        ])
    return space.call_function(w_passwd_struct, w_tuple)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:interp_pwd.py

示例7: PyImport_ExecCodeModuleEx

def PyImport_ExecCodeModuleEx(space, name, w_code, pathname):
    """Like PyImport_ExecCodeModule(), but the __file__ attribute of
    the module object is set to pathname if it is non-NULL."""
    code = space.interp_w(PyCode, w_code)
    w_name = space.wrap(rffi.charp2str(name))
    if pathname:
        pathname = rffi.charp2str(pathname)
    else:
        pathname = code.co_filename
    w_mod = importing.add_module(space, w_name)
    space.setattr(w_mod, space.wrap('__file__'), space.wrap(pathname))
    importing.exec_code_module(space, w_mod, code)
    return w_mod
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:import_.py

示例8: _init_timezone

def _init_timezone():
    timezone = daylight = altzone = 0
    tzname = ["", ""]
    
    # pypy cant' use in_dll to access global exported variables
    # so we can't compute these attributes

    # if _WIN:
    #     cdll.msvcrt._tzset()
    # 
    #     timezone = c_long.in_dll(cdll.msvcrt, "_timezone").value
    #     if hasattr(cdll.msvcrt, "altzone"):
    #         altzone = c_long.in_dll(cdll.msvcrt, "altzone").value
    #     else:
    #         altzone = timezone - 3600
    #     daylight = c_long.in_dll(cdll.msvcrt, "_daylight").value
    #     tzname = _tzname_t.in_dll(cdll.msvcrt, "_tzname")
    #     tzname = (tzname.tzname_0, tzname.tzname_1)
    if _POSIX:
        YEAR = (365 * 24 + 6) * 3600

        t = (((c_time(lltype.nullptr(TIME_TP.TO))) / YEAR) * YEAR)
        # we cannot have reference to stack variable, put it on the heap
        t_ref = lltype.malloc(TIME_TP.TO, 1, flavor='raw')
        t_ref[0] = t
        p = c_localtime(t_ref)
        janzone = -p.c_tm_gmtoff
        tm_zone = rffi.charp2str(p.c_tm_zone)
        janname = ["   ", tm_zone][bool(tm_zone)]
        tt = t + YEAR / 2
        t_ref[0] = tt
        p = c_localtime(t_ref)
        lltype.free(t_ref, flavor='raw')
        tm_zone = rffi.charp2str(p.c_tm_zone)
        julyzone = -p.c_tm_gmtoff
        julyname = ["   ", tm_zone][bool(tm_zone)]

        if janzone < julyzone:
            # DST is reversed in the southern hemisphere
            timezone = julyzone
            altzone = janzone
            daylight = int(janzone != julyzone)
            tzname = [julyname, janname]
        else:
            timezone = janzone
            altzone = julyzone
            daylight = int(janzone != julyzone)
            tzname = [janname, julyname]

    return timezone, daylight, tzname, altzone
开发者ID:antoine1fr,项目名称:pygirl,代码行数:50,代码来源:interp_time.py

示例9: __init__

 def __init__(self, getset, w_type):
     self.getset = getset
     self.name = rffi.charp2str(getset.c_name)
     self.w_type = w_type
     doc = set = get = None
     if doc:
         doc = rffi.charp2str(getset.c_doc)
     if getset.c_get:
         get = GettersAndSetters.getter.im_func
     if getset.c_set:
         set = GettersAndSetters.setter.im_func
     GetSetProperty.__init__(self, get, set, None, doc,
                             cls=None, use_closure=True,
                             tag="cpyext_1")
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:14,代码来源:typeobject.py

示例10: uname_llimpl

 def uname_llimpl():
     l_utsbuf = lltype.malloc(UTSNAMEP.TO, flavor='raw')
     result = os_uname(l_utsbuf)
     if result == -1:
         raise OSError(rposix.get_errno(), "os_uname failed")
     retval = (
         rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_sysname)),
         rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_nodename)),
         rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_release)),
         rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_version)),
         rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_machine)),
         )
     lltype.free(l_utsbuf, flavor='raw')
     return retval
开发者ID:antoine1fr,项目名称:pygirl,代码行数:14,代码来源:ll_os.py

示例11: Py_CompileStringFlags

def Py_CompileStringFlags(space, source, filename, start, flags):
    """Parse and compile the Python source code in str, returning the
    resulting code object.  The start token is given by start; this
    can be used to constrain the code which can be compiled and should
    be Py_eval_input, Py_file_input, or Py_single_input.  The filename
    specified by filename is used to construct the code object and may
    appear in tracebacks or SyntaxError exception messages.  This
    returns NULL if the code cannot be parsed or compiled."""
    source = rffi.charp2str(source)
    filename = rffi.charp2str(filename)
    if flags:
        raise OperationError(space.w_NotImplementedError, space.wrap(
                "cpyext Py_CompileStringFlags does not accept flags"))
    return compile_string(space, source, filename, start)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:14,代码来源:eval.py

示例12: Py_CompileStringFlags

def Py_CompileStringFlags(space, source, filename, start, flagsptr):
    """Parse and compile the Python source code in str, returning the
    resulting code object.  The start token is given by start; this
    can be used to constrain the code which can be compiled and should
    be Py_eval_input, Py_file_input, or Py_single_input.  The filename
    specified by filename is used to construct the code object and may
    appear in tracebacks or SyntaxError exception messages.  This
    returns NULL if the code cannot be parsed or compiled."""
    source = rffi.charp2str(source)
    filename = rffi.charp2str(filename)
    if flagsptr:
        flags = rffi.cast(lltype.Signed, flagsptr.c_cf_flags)
    else:
        flags = 0
    return compile_string(space, source, filename, start, flags)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:15,代码来源:eval.py

示例13: g

 def g():
     l = rffi.liststr2charpp(["a", "b", "c"])
     try:
         set_z(l)
         return rffi.charp2str(get_z()[2])
     finally:
         rffi.free_charpp(l)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:test_ll2ctypes.py

示例14: PyObject_HasAttrString

def PyObject_HasAttrString(space, w_obj, name_ptr):
    try:
        name = rffi.charp2str(name_ptr)
        w_res = operation.hasattr(space, w_obj, space.wrap(name))
        return space.is_true(w_res)
    except OperationError:
        return 0
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:7,代码来源:object.py

示例15: peer_certificate

    def peer_certificate(self, der=False):
        """peer_certificate([der=False]) -> certificate

        Returns the certificate for the peer.  If no certificate was provided,
        returns None.  If a certificate was provided, but not validated, returns
        an empty dictionary.  Otherwise returns a dict containing information
        about the peer certificate.

        If the optional argument is True, returns a DER-encoded copy of the
        peer certificate, or None if no certificate was provided.  This will
        return the certificate even if it wasn't validated."""
        if not self.peer_cert:
            return self.space.w_None

        if der:
            # return cert in DER-encoded format
            with lltype.scoped_alloc(rffi.CCHARPP.TO, 1) as buf_ptr:
                buf_ptr[0] = lltype.nullptr(rffi.CCHARP.TO)
                length = libssl_i2d_X509(self.peer_cert, buf_ptr)
                if length < 0:
                    raise _ssl_seterror(self.space, self, length)
                try:
                    # this is actually an immutable bytes sequence
                    return self.space.wrap(rffi.charp2str(buf_ptr[0]))
                finally:
                    libssl_OPENSSL_free(buf_ptr[0])
        else:
            verification = libssl_SSL_CTX_get_verify_mode(
                libssl_SSL_get_SSL_CTX(self.ssl))
            if not verification & SSL_VERIFY_PEER:
                return self.space.newdict()
            else:
                return _decode_certificate(self.space, self.peer_cert)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:33,代码来源:interp_ssl.py


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