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

C++ PyOS_snprintf函数代码示例

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

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



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

示例1: _asctime

static PyObject *
_asctime(struct tm *timeptr)
{
    /* Inspired by Open Group reference implementation available at
     * http://pubs.opengroup.org/onlinepubs/009695399/functions/asctime.html */
    static char wday_name[7][3] = {
        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
    };
    static char mon_name[12][3] = {
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    };
    char buf[20]; /* 'Sun Sep 16 01:03:52\0' */
    int n;

    n = PyOS_snprintf(buf, sizeof(buf), "%.3s %.3s%3d %.2d:%.2d:%.2d",
                      wday_name[timeptr->tm_wday],
                      mon_name[timeptr->tm_mon],
                      timeptr->tm_mday, timeptr->tm_hour,
                      timeptr->tm_min, timeptr->tm_sec);
    /* XXX: since the fields used by snprintf above are validated in checktm,
     * the following condition should never trigger. We keep the check because
     * historically fixed size buffer used in asctime was the source of
     * crashes. */
    if (n + 1 != sizeof(buf)) {
        PyErr_SetString(PyExc_ValueError, "unconvertible time");
        return NULL;
    }

    return PyUnicode_FromFormat("%s %d", buf, 1900 + timeptr->tm_year);
}
开发者ID:469306621,项目名称:Languages,代码行数:31,代码来源:timemodule.c


示例2: argCountToString

PyObject *
argCountToString(PyObject *self, PyObject *args)
{
	char str[6];
	PyOS_snprintf(str, 5, "(%u)", PyTuple_GET_SIZE(args));
	return PyString_FromString(str);
}
开发者ID:lokuz,项目名称:JyNI,代码行数:7,代码来源:DemoExtensionmodule.c


示例3: PySwigObject_hex

SWIGRUNTIME PyObject *
PySwigObject_hex(PySwigObject *v)
{
  char buf[100];
  PyOS_snprintf(buf, sizeof(buf), "0x%lx", (unsigned long)v->ptr);
  return PyString_FromString(buf);
}
开发者ID:Complex501,项目名称:visionegg,代码行数:7,代码来源:win32_getrefresh_wrap.c


示例4: strop_atof

static PyObject *
strop_atof(PyObject *self, PyObject *args)
{
    char *s, *end;
    double x;
    char buffer[256]; /* For errors */

    WARN;
    if (!PyArg_ParseTuple(args, "s:atof", &s))
        return NULL;
    while (*s && isspace(Py_CHARMASK(*s)))
        s++;
    if (s[0] == '\0') {
        PyErr_SetString(PyExc_ValueError, "empty string for atof()");
        return NULL;
    }

    PyFPE_START_PROTECT("strop_atof", return 0)
    x = PyOS_string_to_double(s, &end, PyExc_OverflowError);
    PyFPE_END_PROTECT(x)
    if (x == -1 && PyErr_Occurred())
        return NULL;
    while (*end && isspace(Py_CHARMASK(*end)))
        end++;
    if (*end != '\0') {
        PyOS_snprintf(buffer, sizeof(buffer),
                      "invalid literal for atof(): %.200s", s);
        PyErr_SetString(PyExc_ValueError, buffer);
        return NULL;
    }
    return PyFloat_FromDouble(x);
}
开发者ID:756613351,项目名称:python-source-code,代码行数:32,代码来源:stropmodule.c


示例5: tp_str

static PyObject *
tp_str(PyObject *self)
{
  char buf[20];
  PyOS_snprintf(buf, sizeof(buf), "%p", ((AddressObject *) self)->ptr);
  return PyString_FromString(buf);
}
开发者ID:animeshinvinci,项目名称:pycopia,代码行数:7,代码来源:Address.c


示例6: PyLocale_getdefaultlocale

static PyObject*
PyLocale_getdefaultlocale(PyObject* self)
{
    char encoding[100];
    char locale[100];

    PyOS_snprintf(encoding, sizeof(encoding), "cp%d", GetACP());

    if (GetLocaleInfo(LOCALE_USER_DEFAULT,
                      LOCALE_SISO639LANGNAME,
                      locale, sizeof(locale))) {
        int i = strlen(locale);
        locale[i++] = '_';
        if (GetLocaleInfo(LOCALE_USER_DEFAULT,
                          LOCALE_SISO3166CTRYNAME,
                          locale+i, sizeof(locale)-i))
            return Py_BuildValue("ss", locale, encoding);
    }

    /* If we end up here, this windows version didn't know about
       ISO639/ISO3166 names (it's probably Windows 95).  Return the
       Windows language identifier instead (a hexadecimal number) */

    locale[0] = '0';
    locale[1] = 'x';
    if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE,
                      locale+2, sizeof(locale)-2)) {
        return Py_BuildValue("ss", locale, encoding);
    }

    /* cannot determine the language code (very unlikely) */
    Py_INCREF(Py_None);
    return Py_BuildValue("Os", Py_None, encoding);
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:34,代码来源:_localemodule.c


示例7: set_hook

static PyObject *
set_hook(const char *funcname, PyObject **hook_var, PyObject *args)
{
    PyObject *function = Py_None;
    char buf[80];
    PyOS_snprintf(buf, sizeof(buf), "|O:set_%.50s", funcname);
    if (!PyArg_ParseTuple(args, buf, &function))
        return NULL;
    if (function == Py_None) {
        Py_CLEAR(*hook_var);
    }
    else if (PyCallable_Check(function)) {
        PyObject *tmp = *hook_var;
        Py_INCREF(function);
        *hook_var = function;
        Py_XDECREF(tmp);
    }
    else {
        PyErr_Format(PyExc_TypeError,
                     "set_%.50s(func): argument not callable",
                     funcname);
        return NULL;
    }
    Py_RETURN_NONE;
}
开发者ID:1564143452,项目名称:kbengine,代码行数:25,代码来源:readline.c


示例8: Py_GetVersion

const char *
Py_GetVersion(void)
{
	static char version[250];
	PyOS_snprintf(version, sizeof(version), "%.80s", PY_VERSION);
	return version;
}
开发者ID:carriercomm,项目名称:anaconda,代码行数:7,代码来源:getversion.c


示例9: supports_code_page

static int supports_code_page(UINT cp) {
  if (cp == 0) {
    cp = GetACP();
  }

  /* Shortcut, because we know that these encodings are bundled by default--
   * see FreezeTool.py and Python's encodings/aliases.py */
  if (cp != 0 && cp != 1252 && cp != 367 && cp != 437 && cp != 850 && cp != 819) {
    const struct _frozen *moddef;
    char codec[100];

    /* Check if the codec was frozen into the program.  We can't check this
     * using _PyCodec_Lookup, since Python hasn't been initialized yet. */
    PyOS_snprintf(codec, sizeof(codec), "encodings.cp%u", (unsigned int)cp);

    moddef = PyImport_FrozenModules;
    while (moddef->name) {
      if (strcmp(moddef->name, codec) == 0) {
        return 1;
      }
      ++moddef;
    }
    return 0;
  }

  return 1;
}
开发者ID:rdb,项目名称:panda3d,代码行数:27,代码来源:deploy-stub.c


示例10: buffer_repr

	static PyObject *
		buffer_repr(PyIOCPBufferObject *s)
	{
		char buf[512];
		PyOS_snprintf( buf, sizeof(buf), "<iocp buffer object, addr=%x, length=%d >", s->ptr_start, s->len );
		return PyString_FromString(buf);
	}
开发者ID:bahamut8348,项目名称:xkcode,代码行数:7,代码来源:IOCP_BUFFER.cpp


示例11: xerbla_

int xerbla_(char *srname, integer *info)
{
        const char* format = "On entry to %.*s" \
                " parameter number %d had an illegal value";
        char buf[57 + 6 + 4]; /* 57 for strlen(format),
                                 6 for name, 4 for param. num. */

        int len = 0; /* length of subroutine name*/
#ifdef WITH_THREAD
        PyGILState_STATE save;
#endif

        while( len<6 && srname[len]!='\0' )
                len++;
        while( len && srname[len-1]==' ' )
                len--;

        PyOS_snprintf(buf, sizeof(buf), format, len, srname, *info);
#ifdef WITH_THREAD
        save = PyGILState_Ensure();
        PyErr_SetString(PyExc_ValueError, buf);
        PyGILState_Release(save);
#endif
        return 0;
}
开发者ID:pyhits,项目名称:numpy,代码行数:25,代码来源:python_xerbla.c


示例12: form_repr

static PyObject *
form_repr(formobject *f)
{
	char buf[100];
	PyOS_snprintf(buf, sizeof(buf), "<FORMS_form at %p, window=%ld>",
		      f, f->ob_form->window);
	return PyString_FromString(buf);
}
开发者ID:Androtos,项目名称:toolchain_benchmark,代码行数:8,代码来源:flmodule.c


示例13: Py_GetVersion

const char *
Py_GetVersion(void)
{
	static char version[250];
	PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
		      PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
	return version;
}
开发者ID:0xcc,项目名称:python-read,代码行数:8,代码来源:getversion.c


示例14: _PyImport_GetDynLoadFunc

dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
				    const char *pathname, FILE *fp)
{
	char funcname[258];

	PyOS_snprintf(funcname, sizeof(funcname), "init%.200s", shortname);
	return dl_loadmod(Py_GetProgramName(), pathname, funcname);
}
开发者ID:0xcc,项目名称:python-read,代码行数:8,代码来源:dynload_dl.c


示例15: ps

static void
ps(void)
{
    char buffer[100];
    PyOS_snprintf(buffer, sizeof(buffer),
                  "ps -l -p %d </dev/null | sed 1d\n", getpid());
    system(buffer);
}
开发者ID:0xcc,项目名称:python-read,代码行数:8,代码来源:pysvr.c


示例16: generic_repr

static PyObject *
generic_repr(genericobject *g)
{
	char buf[100];
	PyOS_snprintf(buf, sizeof(buf), "<FORMS_object at %p, objclass=%d>",
		      g, g->ob_generic->objclass);
	return PyString_FromString(buf);
}
开发者ID:Androtos,项目名称:toolchain_benchmark,代码行数:8,代码来源:flmodule.c


示例17: pylog_repr

static PyObject *
pylog_repr(PyLogObject *s)
{
    char buf[512];
    PyOS_snprintf(buf, sizeof(buf),
                "<Log object ... TODO>");
    return PyBytes_FromString(buf);
}
开发者ID:ahans,项目名称:lcm,代码行数:8,代码来源:pyeventlog.c


示例18: Mat22_repr

/* returns new ref string formatted */
static PyObject *
Mat22_repr(Mat22 *self)
{
    char buf[BUF_SIZE];
    PyOS_snprintf(buf, BUF_SIZE, MAT22_FORMAT, 
            self->col1->x, self->col2->x, self->col1->y, self->col2->y);
    return PyString_FromString(buf);
}
开发者ID:shengtu,项目名称:pypybox2d,代码行数:9,代码来源:mat22module.c


示例19: Py_GetBuildInfo

const char *
Py_GetBuildInfo(void)
{
	static char buildinfo[50];
	PyOS_snprintf(buildinfo, sizeof(buildinfo),
		      "#%d, %.20s, %.9s", BUILD, DATE, TIME);
	return buildinfo;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:8,代码来源:getbuildinfo.c


示例20: connectPool_repr

static PyObject*
connectPool_repr(PyConnectPoolObject *v)
{
    //printf("connectPool_repr\n");
    char buf[64 + NAME_MAX];
    PyOS_snprintf(buf, sizeof(buf), "connect to %s in port %d with %d busy and %d free",
                  v->db, v->port, PySequence_Length(v->cons_busy), PySequence_Length(v->cons_free));
    return PyString_FromString(buf);
}
开发者ID:yuriyao,项目名称:MYSQLPD,代码行数:9,代码来源:mysql_c.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PyObject_AsFileDescriptor函数代码示例发布时间:2022-05-30
下一篇:
C++ PyNumber_Float函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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