Kaydet (Commit) e226b559 authored tarafından Eric Smith's avatar Eric Smith

PEP 3101: Removed _formatter_xxx routines from sysmodule, and made them unicode…

PEP 3101: Removed _formatter_xxx routines from sysmodule, and made them unicode methods instead (per GvR suggestion).
üst 8cef8a89
...@@ -1437,9 +1437,6 @@ PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr( ...@@ -1437,9 +1437,6 @@ PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr(
const Py_UNICODE *s, Py_UNICODE c const Py_UNICODE *s, Py_UNICODE c
); );
PyObject *_PyUnicode_FormatterIterator(PyObject *str);
PyObject *_PyUnicode_FormatterFieldNameSplit(PyObject *field_name);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -200,10 +200,8 @@ class Template(metaclass=_TemplateMetaclass): ...@@ -200,10 +200,8 @@ class Template(metaclass=_TemplateMetaclass):
# exposed here via the sys module. sys was chosen because it's always # exposed here via the sys module. sys was chosen because it's always
# available and doesn't have to be dynamically loaded. # available and doesn't have to be dynamically loaded.
# The overall parser is implemented in sys._formatter_parser. # The overall parser is implemented in str._formatter_parser.
# The field name parser is implemented in sys._formatter_field_name_split # The field name parser is implemented in str._formatter_field_name_split
from sys import _formatter_parser, _formatter_field_name_split
class Formatter: class Formatter:
def format(self, format_string, *args, **kwargs): def format(self, format_string, *args, **kwargs):
...@@ -213,13 +211,13 @@ class Formatter: ...@@ -213,13 +211,13 @@ class Formatter:
used_args = set() used_args = set()
result = [] result = []
for (is_markup, literal, field_name, format_spec, conversion) in \ for (is_markup, literal, field_name, format_spec, conversion) in \
_formatter_parser(format_string): format_string._formatter_parser():
if is_markup: if is_markup:
# given the field_name, find the object it references # given the field_name, find the object it references
# split it into the first part, and and iterator that # split it into the first part, and and iterator that
# looks over the rest # looks over the rest
first, rest = _formatter_field_name_split(field_name) first, rest = field_name._formatter_field_name_split()
used_args.add(first) used_args.add(first)
obj = self.get_value(first, args, kwargs) obj = self.get_value(first, args, kwargs)
......
This diff is collapsed.
...@@ -660,54 +660,6 @@ sys_current_frames(PyObject *self, PyObject *noargs) ...@@ -660,54 +660,6 @@ sys_current_frames(PyObject *self, PyObject *noargs)
return _PyThread_CurrentFrames(); return _PyThread_CurrentFrames();
} }
/* sys_formatter_iterator is used to implement
string.Formatter.vformat. it parses a string and returns tuples
describing the parsed elements. see unicodeobject.c's
_PyUnicode_FormatterIterator for details */
static PyObject *
sys_formatter_iterator(PyObject *self, PyObject *args)
{
/* in 2.6, check type and dispatch to unicode or string
accordingly */
PyObject *str;
if (!PyArg_ParseTuple(args, "O:_formatter_iterator", &str))
return NULL;
if (!PyUnicode_Check(str)) {
PyErr_SetString(PyExc_TypeError,
"_formatter_iterator expects unicode object");
return NULL;
}
return _PyUnicode_FormatterIterator(str);
}
/* sys_formatter_field_name_split is used to implement
string.Formatter.vformat. it takes an PEP 3101 "field name", and
returns a tuple of (first, rest): "first", the part before the
first '.' or '['; and "rest", an iterator for the rest of the field
name. see unicodeobjects' _PyUnicode_FormatterFieldNameSplit for
details */
static PyObject *
sys_formatter_field_name_split(PyObject *self, PyObject *args)
{
PyObject *field_name;
if (!PyArg_ParseTuple(args, "O:_formatter_field_name_split",
&field_name))
return NULL;
if (!PyUnicode_Check(field_name)) {
PyErr_SetString(PyExc_TypeError, "_formatter_field_name_split "
"expects unicode object");
return NULL;
}
return _PyUnicode_FormatterFieldNameSplit(field_name);
}
PyDoc_STRVAR(call_tracing_doc, PyDoc_STRVAR(call_tracing_doc,
"call_tracing(func, args) -> object\n\ "call_tracing(func, args) -> object\n\
\n\ \n\
...@@ -772,9 +724,6 @@ static PyMethodDef sys_methods[] = { ...@@ -772,9 +724,6 @@ static PyMethodDef sys_methods[] = {
callstats_doc}, callstats_doc},
{"_current_frames", sys_current_frames, METH_NOARGS, {"_current_frames", sys_current_frames, METH_NOARGS,
current_frames_doc}, current_frames_doc},
{"_formatter_parser", sys_formatter_iterator, METH_VARARGS},
{"_formatter_field_name_split", sys_formatter_field_name_split,
METH_VARARGS},
{"displayhook", sys_displayhook, METH_O, displayhook_doc}, {"displayhook", sys_displayhook, METH_O, displayhook_doc},
{"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc}, {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
{"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment