comparison Python/sysmodule.c @ 42896:7bf8f2339ec6

PEP 3101: Removed _formatter_xxx routines from sysmodule, and made them unicode methods instead (per GvR suggestion).
author Eric Smith <eric@trueblade.com>
date Mon, 27 Aug 2007 11:28:18 +0000
parents 6b4781dc81ff
children 4e6b4ba60c3b
comparison
equal deleted inserted replaced
42895:594f89ec0607 42896:7bf8f2339ec6
657 static PyObject * 657 static PyObject *
658 sys_current_frames(PyObject *self, PyObject *noargs) 658 sys_current_frames(PyObject *self, PyObject *noargs)
659 { 659 {
660 return _PyThread_CurrentFrames(); 660 return _PyThread_CurrentFrames();
661 } 661 }
662
663 /* sys_formatter_iterator is used to implement
664 string.Formatter.vformat. it parses a string and returns tuples
665 describing the parsed elements. see unicodeobject.c's
666 _PyUnicode_FormatterIterator for details */
667 static PyObject *
668 sys_formatter_iterator(PyObject *self, PyObject *args)
669 {
670 /* in 2.6, check type and dispatch to unicode or string
671 accordingly */
672 PyObject *str;
673
674 if (!PyArg_ParseTuple(args, "O:_formatter_iterator", &str))
675 return NULL;
676
677 if (!PyUnicode_Check(str)) {
678 PyErr_SetString(PyExc_TypeError,
679 "_formatter_iterator expects unicode object");
680 return NULL;
681 }
682
683 return _PyUnicode_FormatterIterator(str);
684 }
685
686 /* sys_formatter_field_name_split is used to implement
687 string.Formatter.vformat. it takes an PEP 3101 "field name", and
688 returns a tuple of (first, rest): "first", the part before the
689 first '.' or '['; and "rest", an iterator for the rest of the field
690 name. see unicodeobjects' _PyUnicode_FormatterFieldNameSplit for
691 details */
692 static PyObject *
693 sys_formatter_field_name_split(PyObject *self, PyObject *args)
694 {
695 PyObject *field_name;
696
697 if (!PyArg_ParseTuple(args, "O:_formatter_field_name_split",
698 &field_name))
699 return NULL;
700
701 if (!PyUnicode_Check(field_name)) {
702 PyErr_SetString(PyExc_TypeError, "_formatter_field_name_split "
703 "expects unicode object");
704 return NULL;
705 }
706
707 return _PyUnicode_FormatterFieldNameSplit(field_name);
708 }
709
710 662
711 PyDoc_STRVAR(call_tracing_doc, 663 PyDoc_STRVAR(call_tracing_doc,
712 "call_tracing(func, args) -> object\n\ 664 "call_tracing(func, args) -> object\n\
713 \n\ 665 \n\
714 Call func(*args), while tracing is enabled. The tracing state is\n\ 666 Call func(*args), while tracing is enabled. The tracing state is\n\
770 /* Might as well keep this in alphabetic order */ 722 /* Might as well keep this in alphabetic order */
771 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, 723 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
772 callstats_doc}, 724 callstats_doc},
773 {"_current_frames", sys_current_frames, METH_NOARGS, 725 {"_current_frames", sys_current_frames, METH_NOARGS,
774 current_frames_doc}, 726 current_frames_doc},
775 {"_formatter_parser", sys_formatter_iterator, METH_VARARGS},
776 {"_formatter_field_name_split", sys_formatter_field_name_split,
777 METH_VARARGS},
778 {"displayhook", sys_displayhook, METH_O, displayhook_doc}, 727 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
779 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc}, 728 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
780 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, 729 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
781 {"exit", sys_exit, METH_VARARGS, exit_doc}, 730 {"exit", sys_exit, METH_VARARGS, exit_doc},
782 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, 731 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,