| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,8 @@ | |||
| 14 | 14 | ||
| 15 | 15 | """ | |
| 16 | 16 | ||
| 17 | + import _string | ||
| 18 | + | ||
| 17 | 19 | # Some strings for ctype-style character classification | |
| 18 | 20 | whitespace = ' \t\n\r\v\f' | |
| 19 | 21 | ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' | |
@@ -170,8 +172,8 @@ def convert(mo): | |||
| 170 | 172 | # The hard parts are reused from the C implementation. They're exposed as "_" | |
| 171 | 173 | # prefixed methods of str. | |
| 172 | 174 | ||
| 173 | - # The overall parser is implemented in str._formatter_parser. | ||
| 174 | - # The field name parser is implemented in str._formatter_field_name_split | ||
| 175 | + # The overall parser is implemented in _string.formatter_parser. | ||
| 176 | + # The field name parser is implemented in _string.formatter_field_name_split | ||
| 175 | 177 | ||
| 176 | 178 | class Formatter: | |
| 177 | 179 | def format(self, format_string, *args, **kwargs): | |
@@ -251,7 +253,7 @@ def convert_field(self, value, conversion): | |||
| 251 | 253 | # if field_name is not None, it is looked up, formatted | |
| 252 | 254 | # with format_spec and conversion and then used | |
| 253 | 255 | def parse(self, format_string): | |
| 254 | - return format_string._formatter_parser() | ||
| 256 | + return _string.formatter_parser(format_string) | ||
| 255 | 257 | ||
| 256 | 258 | ||
| 257 | 259 | # given a field_name, find the object it references. | |
@@ -260,7 +262,7 @@ def parse(self, format_string): | |||
| 260 | 262 | # used_args: a set of which args have been used | |
| 261 | 263 | # args, kwargs: as passed in to vformat | |
| 262 | 264 | def get_field(self, field_name, args, kwargs): | |
| 263 | - first, rest = field_name._formatter_field_name_split() | ||
| 265 | + first, rest = _string.formatter_field_name_split(field_name) | ||
| 264 | 266 | ||
| 265 | 267 | obj = self.get_value(first, args, kwargs) | |
| 266 | 268 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,9 @@ What's New in Python 3.2 Beta 1? | |||
| 10 | 10 | Core and Builtins | |
| 11 | 11 | ----------------- | |
| 12 | 12 | ||
| 13 | + - Issue #9418: Moved private string methods ``_formatter_parser`` and | ||
| 14 | + ``_formatter_field_name_split`` into a new ``_string`` module. | ||
| 15 | + | ||
| 13 | 16 | - Issue #9992: Remove PYTHONFSENCODING environment variable. | |
| 14 | 17 | ||
| 15 | 18 | Library | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ extern PyObject* PyInit_imp(void); | |||
| 29 | 29 | extern PyObject* PyInit_gc(void); | |
| 30 | 30 | extern PyObject* PyInit__ast(void); | |
| 31 | 31 | extern PyObject* _PyWarnings_Init(void); | |
| 32 | + extern PyObject* PyInit__string(void); | ||
| 32 | 33 | ||
| 33 | 34 | struct _inittab _PyImport_Inittab[] = { | |
| 34 | 35 | ||
@@ -54,6 +55,9 @@ struct _inittab _PyImport_Inittab[] = { | |||
| 54 | 55 | /* This lives in _warnings.c */ | |
| 55 | 56 | {"_warnings", _PyWarnings_Init}, | |
| 56 | 57 | ||
| 58 | + /* This lives in Objects/unicodeobject.c */ | ||
| 59 | + {"_string", PyInit__string}, | ||
| 60 | + | ||
| 57 | 61 | /* Sentinel */ | |
| 58 | 62 | {0, 0} | |
| 59 | 63 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1180,7 +1180,7 @@ static PyTypeObject PyFormatterIter_Type = { | |||
| 1180 | 1180 | describing the parsed elements. It's a wrapper around | |
| 1181 | 1181 | stringlib/string_format.h's MarkupIterator */ | |
| 1182 | 1182 | static PyObject * | |
| 1183 | - formatter_parser(STRINGLIB_OBJECT *self) | ||
| 1183 | + formatter_parser(PyObject *ignored, STRINGLIB_OBJECT *self) | ||
| 1184 | 1184 | { | |
| 1185 | 1185 | formatteriterobject *it; | |
| 1186 | 1186 | ||
@@ -1315,7 +1315,7 @@ static PyTypeObject PyFieldNameIter_Type = { | |||
| 1315 | 1315 | field_name_split. The iterator it returns is a | |
| 1316 | 1316 | FieldNameIterator */ | |
| 1317 | 1317 | static PyObject * | |
| 1318 | - formatter_field_name_split(STRINGLIB_OBJECT *self) | ||
| 1318 | + formatter_field_name_split(PyObject *ignored, STRINGLIB_OBJECT *self) | ||
| 1319 | 1319 | { | |
| 1320 | 1320 | SubString first; | |
| 1321 | 1321 | Py_ssize_t first_idx; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8968,8 +8968,6 @@ static PyMethodDef unicode_methods[] = { | |||
| 8968 | 8968 | {"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__}, | |
| 8969 | 8969 | {"format", (PyCFunction) do_string_format, METH_VARARGS | METH_KEYWORDS, format__doc__}, | |
| 8970 | 8970 | {"__format__", (PyCFunction) unicode__format__, METH_VARARGS, p_format__doc__}, | |
| 8971 | - {"_formatter_field_name_split", (PyCFunction) formatter_field_name_split, METH_NOARGS}, | ||
| 8972 | - {"_formatter_parser", (PyCFunction) formatter_parser, METH_NOARGS}, | ||
| 8973 | 8971 | {"maketrans", (PyCFunction) unicode_maketrans, | |
| 8974 | 8972 | METH_VARARGS | METH_STATIC, maketrans__doc__}, | |
| 8975 | 8973 | {"__sizeof__", (PyCFunction) unicode__sizeof__, METH_NOARGS, sizeof__doc__}, | |
@@ -10170,6 +10168,36 @@ PyUnicode_AsUnicodeCopy(PyObject *object) | |||
| 10170 | 10168 | return copy; | |
| 10171 | 10169 | } | |
| 10172 | 10170 | ||
| 10171 | + /* A _string module, to export formatter_parser and formatter_field_name_split | ||
| 10172 | + to the string.Formatter class implemented in Python. */ | ||
| 10173 | + | ||
| 10174 | + static PyMethodDef _string_methods[] = { | ||
| 10175 | + {"formatter_field_name_split", (PyCFunction) formatter_field_name_split, | ||
| 10176 | + METH_O, PyDoc_STR("split the argument as a field name")}, | ||
| 10177 | + {"formatter_parser", (PyCFunction) formatter_parser, | ||
| 10178 | + METH_O, PyDoc_STR("parse the argument as a format string")}, | ||
| 10179 | + {NULL, NULL} | ||
| 10180 | + }; | ||
| 10181 | + | ||
| 10182 | + static struct PyModuleDef _string_module = { | ||
| 10183 | + PyModuleDef_HEAD_INIT, | ||
| 10184 | + "_string", | ||
| 10185 | + PyDoc_STR("string helper module"), | ||
| 10186 | + 0, | ||
| 10187 | + _string_methods, | ||
| 10188 | + NULL, | ||
| 10189 | + NULL, | ||
| 10190 | + NULL, | ||
| 10191 | + NULL | ||
| 10192 | + }; | ||
| 10193 | + | ||
| 10194 | + PyMODINIT_FUNC | ||
| 10195 | + PyInit__string(void) | ||
| 10196 | + { | ||
| 10197 | + return PyModule_Create(&_string_module); | ||
| 10198 | + } | ||
| 10199 | + | ||
| 10200 | + | ||
| 10173 | 10201 | #ifdef __cplusplus | |
| 10174 | 10202 | } | |
| 10175 | 10203 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,6 +62,7 @@ extern PyObject* PyInit__io(void); | |||
| 62 | 62 | extern PyObject* PyInit__pickle(void); | |
| 63 | 63 | extern PyObject* PyInit_atexit(void); | |
| 64 | 64 | extern PyObject* _PyWarnings_Init(void); | |
| 65 | + extern PyObject* PyInit__string(void); | ||
| 65 | 66 | ||
| 66 | 67 | /* tools/freeze/makeconfig.py marker for additional "extern" */ | |
| 67 | 68 | /* -- ADDMODULE MARKER 1 -- */ | |
@@ -147,6 +148,7 @@ struct _inittab _PyImport_Inittab[] = { | |||
| 147 | 148 | {"builtins", NULL}, | |
| 148 | 149 | {"sys", NULL}, | |
| 149 | 150 | {"_warnings", _PyWarnings_Init}, | |
| 151 | + {"_string", PyInit__string}, | ||
| 150 | 152 | ||
| 151 | 153 | {"_io", PyInit__io}, | |
| 152 | 154 | {"_pickle", PyInit__pickle}, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments