comparison Python/sysmodule.c @ 42817:5355337709e1

Implementation of PEP 3101, Advanced String Formatting. Known issues: The string.Formatter class, as discussed in the PEP, is incomplete. Error handling needs to conform to the PEP. Need to fix this warning that I introduced in Python/formatter_unicode.c: Objects/stringlib/unicodedefs.h:26: warning: `STRINGLIB_CMP' defined but not used Need to make sure sign formatting is correct, more tests needed. Need to remove '()' sign formatting, left over from an earlier version of the PEP.
author Eric Smith <eric@trueblade.com>
date Sat, 25 Aug 2007 02:26:07 +0000
parents f81d94c05a0e
children 5fd65e250843
comparison
equal deleted inserted replaced
42816:872c7c3f0af3 42817:5355337709e1
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 _unicodeformatter_iterator 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 _unicodeformatter_iterator(str);
684 }
685
686 /* sys_formatter_lookup is used to implement string.Formatter.vformat.
687 it takes an PEP 3101 "field name", args, and kwargs, and returns a
688 tuple (index, name, object). see unicodeobject.c's
689 _unicodeformatter_lookup for details */
690 static PyObject *
691 sys_formatter_lookup(PyObject *self, PyObject *args)
692 {
693 PyObject *field_name;
694 PyObject *arg_args;
695 PyObject *kwargs;
696
697 if (!PyArg_ParseTuple(args, "OOO:_formatter_lookup", &field_name,
698 &arg_args, &kwargs))
699 return NULL;
700
701 if (!PyUnicode_Check(field_name)) {
702 PyErr_SetString(PyExc_TypeError,
703 "_formatter_lookup expects unicode object");
704 return NULL;
705 }
706
707 return _unicodeformatter_lookup(field_name, arg_args, kwargs);
708 }
709
662 710
663 PyDoc_STRVAR(call_tracing_doc, 711 PyDoc_STRVAR(call_tracing_doc,
664 "call_tracing(func, args) -> object\n\ 712 "call_tracing(func, args) -> object\n\
665 \n\ 713 \n\
666 Call func(*args), while tracing is enabled. The tracing state is\n\ 714 Call func(*args), while tracing is enabled. The tracing state is\n\
722 /* Might as well keep this in alphabetic order */ 770 /* Might as well keep this in alphabetic order */
723 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, 771 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
724 callstats_doc}, 772 callstats_doc},
725 {"_current_frames", sys_current_frames, METH_NOARGS, 773 {"_current_frames", sys_current_frames, METH_NOARGS,
726 current_frames_doc}, 774 current_frames_doc},
775 {"_formatter_parser", sys_formatter_iterator, METH_VARARGS},
776 {"_formatter_lookup", sys_formatter_lookup, METH_VARARGS},
727 {"displayhook", sys_displayhook, METH_O, displayhook_doc}, 777 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
728 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc}, 778 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
729 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, 779 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
730 {"exit", sys_exit, METH_VARARGS, exit_doc}, 780 {"exit", sys_exit, METH_VARARGS, exit_doc},
731 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, 781 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,