Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Modules/future_builtins.c

    r2 r391  
    1515Functions:\n\
    1616\n\
    17 hex(arg) -- Returns the hexadecimal representation of an integer\n\
    18 oct(arg) -- Returns the octal representation of an integer\n\
     17ascii(arg) -- Returns the canonical string representation of an object.\n\
     18filter(pred, iterable) -- Returns an iterator yielding those items of \n\
     19       iterable for which pred(item) is true.\n\
     20hex(arg) -- Returns the hexadecimal representation of an integer.\n\
     21map(func, *iterables) -- Returns an iterator that computes the function \n\
     22    using arguments from each of the iterables.\n\
     23oct(arg) -- Returns the octal representation of an integer.\n\
     24zip(iter1 [,iter2 [...]]) -- Returns a zip object whose .next() method \n\
     25    returns a tuple where the i-th element comes from the i-th iterable \n\
     26    argument.\n\
    1927\n\
    2028The typical usage of this module is to replace existing builtins in a\n\
    2129module's namespace:\n \n\
    22 from future_builtins import hex, oct\n");
     30from future_builtins import ascii, filter, map, hex, oct, zip\n");
    2331
    2432static PyObject *
    2533builtin_hex(PyObject *self, PyObject *v)
    2634{
    27         return PyNumber_ToBase(v, 16);
     35    return PyNumber_ToBase(v, 16);
    2836}
    2937
     
    3745builtin_oct(PyObject *self, PyObject *v)
    3846{
    39         return PyNumber_ToBase(v, 8);
     47    return PyNumber_ToBase(v, 8);
    4048}
    4149
     
    4957builtin_ascii(PyObject *self, PyObject *v)
    5058{
    51         return PyObject_Repr(v);
     59    return PyObject_Repr(v);
    5260}
    5361
     
    6270
    6371static PyMethodDef module_functions[] = {
    64         {"hex",         builtin_hex,        METH_O, hex_doc},
    65         {"oct",         builtin_oct,        METH_O, oct_doc},
    66         {"ascii",       builtin_ascii,      METH_O, ascii_doc},
    67         {NULL,          NULL}   /* Sentinel */
     72    {"hex",             builtin_hex,        METH_O, hex_doc},
     73    {"oct",             builtin_oct,        METH_O, oct_doc},
     74    {"ascii",           builtin_ascii,      METH_O, ascii_doc},
     75    {NULL,              NULL}   /* Sentinel */
    6876};
    6977
     
    7482initfuture_builtins(void)
    7583{
    76         PyObject *m, *itertools, *iter_func;
    77         char *it_funcs[] = {"imap", "ifilter", "izip", NULL};
    78         char **cur_func;
     84    PyObject *m, *itertools, *iter_func;
     85    char *it_funcs[] = {"imap", "ifilter", "izip", NULL};
     86    char **cur_func;
    7987
    80         m = Py_InitModule3("future_builtins", module_functions, module_doc);
    81         if (m == NULL)
    82                 return;
     88    m = Py_InitModule3("future_builtins", module_functions, module_doc);
     89    if (m == NULL)
     90        return;
    8391
    84         itertools = PyImport_ImportModuleNoBlock("itertools");
    85         if (itertools == NULL)
    86                 return;
     92    itertools = PyImport_ImportModuleNoBlock("itertools");
     93    if (itertools == NULL)
     94        return;
    8795
    88         for (cur_func = it_funcs; *cur_func; ++cur_func){
    89                 iter_func = PyObject_GetAttrString(itertools, *cur_func);
    90                 if (iter_func == NULL)
    91                         return;
    92                 PyModule_AddObject(m, *cur_func+1, iter_func);
    93         }
    94         Py_DECREF(itertools);
    95         /* any other initialization needed */
     96    /* If anything in the following loop fails, we fall through. */
     97    for (cur_func = it_funcs; *cur_func; ++cur_func){
     98        iter_func = PyObject_GetAttrString(itertools, *cur_func);
     99        if (iter_func == NULL ||
     100            PyModule_AddObject(m, *cur_func+1, iter_func) < 0)
     101            break;
     102    }
     103    Py_DECREF(itertools);
     104    /* any other initialization needed */
    96105}
Note: See TracChangeset for help on using the changeset viewer.