comparison Python/sysmodule.c @ 42875:5fd65e250843

PEP 3101: Completed string.Formatter class. Reimplemented field_name to object transformation.
author Eric Smith <eric@trueblade.com>
date Sun, 26 Aug 2007 22:27:13 +0000
parents 5355337709e1
children 6b4781dc81ff
comparison
equal deleted inserted replaced
42873:d8ad29c68763 42875:5fd65e250843
681 } 681 }
682 682
683 return _unicodeformatter_iterator(str); 683 return _unicodeformatter_iterator(str);
684 } 684 }
685 685
686 /* sys_formatter_lookup is used to implement string.Formatter.vformat. 686 /* sys_formatter_field_name_split is used to implement
687 it takes an PEP 3101 "field name", args, and kwargs, and returns a 687 string.Formatter.vformat. it takes an PEP 3101 "field name", and
688 tuple (index, name, object). see unicodeobject.c's 688 returns a tuple of (first, rest): "first", the part before the
689 _unicodeformatter_lookup for details */ 689 first '.' or '['; and "rest", an iterator for the rest of the field
690 static PyObject * 690 name. see unicodeobjects' _unicode_formatter_field_name_split for
691 sys_formatter_lookup(PyObject *self, PyObject *args) 691 details */
692 static PyObject *
693 sys_formatter_field_name_split(PyObject *self, PyObject *args)
692 { 694 {
693 PyObject *field_name; 695 PyObject *field_name;
694 PyObject *arg_args; 696
695 PyObject *kwargs; 697 if (!PyArg_ParseTuple(args, "O:_formatter_field_name_split",
696 698 &field_name))
697 if (!PyArg_ParseTuple(args, "OOO:_formatter_lookup", &field_name,
698 &arg_args, &kwargs))
699 return NULL; 699 return NULL;
700 700
701 if (!PyUnicode_Check(field_name)) { 701 if (!PyUnicode_Check(field_name)) {
702 PyErr_SetString(PyExc_TypeError, 702 PyErr_SetString(PyExc_TypeError, "_formatter_field_name_split "
703 "_formatter_lookup expects unicode object"); 703 "expects unicode object");
704 return NULL; 704 return NULL;
705 } 705 }
706 706
707 return _unicodeformatter_lookup(field_name, arg_args, kwargs); 707 return _unicodeformatter_field_name_split(field_name);
708 } 708 }
709 709
710 710
711 PyDoc_STRVAR(call_tracing_doc, 711 PyDoc_STRVAR(call_tracing_doc,
712 "call_tracing(func, args) -> object\n\ 712 "call_tracing(func, args) -> object\n\
771 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, 771 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
772 callstats_doc}, 772 callstats_doc},
773 {"_current_frames", sys_current_frames, METH_NOARGS, 773 {"_current_frames", sys_current_frames, METH_NOARGS,
774 current_frames_doc}, 774 current_frames_doc},
775 {"_formatter_parser", sys_formatter_iterator, METH_VARARGS}, 775 {"_formatter_parser", sys_formatter_iterator, METH_VARARGS},
776 {"_formatter_lookup", sys_formatter_lookup, METH_VARARGS}, 776 {"_formatter_field_name_split", sys_formatter_field_name_split,
777 METH_VARARGS},
777 {"displayhook", sys_displayhook, METH_O, displayhook_doc}, 778 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
778 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc}, 779 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
779 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, 780 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
780 {"exit", sys_exit, METH_VARARGS, exit_doc}, 781 {"exit", sys_exit, METH_VARARGS, exit_doc},
781 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, 782 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,