@@ -1156,6 +1156,67 @@ context_setattr(PyObject *self, PyObject *name, PyObject *value)
1156
1156
return PyObject_GenericSetAttr (self , name , value );
1157
1157
}
1158
1158
1159
+ static int
1160
+ context_setattrs (PyObject * self , PyObject * prec , PyObject * rounding ,
1161
+ PyObject * emin , PyObject * emax , PyObject * capitals ,
1162
+ PyObject * clamp , PyObject * status , PyObject * traps ) {
1163
+
1164
+ int ret ;
1165
+ if (prec != Py_None && context_setprec (self , prec , NULL ) < 0 ) {
1166
+ return -1 ;
1167
+ }
1168
+ if (rounding != Py_None && context_setround (self , rounding , NULL ) < 0 ) {
1169
+ return -1 ;
1170
+ }
1171
+ if (emin != Py_None && context_setemin (self , emin , NULL ) < 0 ) {
1172
+ return -1 ;
1173
+ }
1174
+ if (emax != Py_None && context_setemax (self , emax , NULL ) < 0 ) {
1175
+ return -1 ;
1176
+ }
1177
+ if (capitals != Py_None && context_setcapitals (self , capitals , NULL ) < 0 ) {
1178
+ return -1 ;
1179
+ }
1180
+ if (clamp != Py_None && context_setclamp (self , clamp , NULL ) < 0 ) {
1181
+ return -1 ;
1182
+ }
1183
+
1184
+ if (traps != Py_None ) {
1185
+ if (PyList_Check (traps )) {
1186
+ ret = context_settraps_list (self , traps );
1187
+ }
1188
+ #ifdef EXTRA_FUNCTIONALITY
1189
+ else if (PyLong_Check (traps )) {
1190
+ ret = context_settraps (self , traps , NULL );
1191
+ }
1192
+ #endif
1193
+ else {
1194
+ ret = context_settraps_dict (self , traps );
1195
+ }
1196
+ if (ret < 0 ) {
1197
+ return ret ;
1198
+ }
1199
+ }
1200
+ if (status != Py_None ) {
1201
+ if (PyList_Check (status )) {
1202
+ ret = context_setstatus_list (self , status );
1203
+ }
1204
+ #ifdef EXTRA_FUNCTIONALITY
1205
+ else if (PyLong_Check (status )) {
1206
+ ret = context_setstatus (self , status , NULL );
1207
+ }
1208
+ #endif
1209
+ else {
1210
+ ret = context_setstatus_dict (self , status );
1211
+ }
1212
+ if (ret < 0 ) {
1213
+ return ret ;
1214
+ }
1215
+ }
1216
+
1217
+ return 0 ;
1218
+ }
1219
+
1159
1220
static PyObject *
1160
1221
context_clear_traps (PyObject * self , PyObject * dummy UNUSED )
1161
1222
{
@@ -1255,7 +1316,6 @@ context_init(PyObject *self, PyObject *args, PyObject *kwds)
1255
1316
PyObject * clamp = Py_None ;
1256
1317
PyObject * status = Py_None ;
1257
1318
PyObject * traps = Py_None ;
1258
- int ret ;
1259
1319
1260
1320
assert (PyTuple_Check (args ));
1261
1321
@@ -1267,59 +1327,11 @@ context_init(PyObject *self, PyObject *args, PyObject *kwds)
1267
1327
return -1 ;
1268
1328
}
1269
1329
1270
- if (prec != Py_None && context_setprec (self , prec , NULL ) < 0 ) {
1271
- return -1 ;
1272
- }
1273
- if (rounding != Py_None && context_setround (self , rounding , NULL ) < 0 ) {
1274
- return -1 ;
1275
- }
1276
- if (emin != Py_None && context_setemin (self , emin , NULL ) < 0 ) {
1277
- return -1 ;
1278
- }
1279
- if (emax != Py_None && context_setemax (self , emax , NULL ) < 0 ) {
1280
- return -1 ;
1281
- }
1282
- if (capitals != Py_None && context_setcapitals (self , capitals , NULL ) < 0 ) {
1283
- return -1 ;
1284
- }
1285
- if (clamp != Py_None && context_setclamp (self , clamp , NULL ) < 0 ) {
1286
- return -1 ;
1287
- }
1288
-
1289
- if (traps != Py_None ) {
1290
- if (PyList_Check (traps )) {
1291
- ret = context_settraps_list (self , traps );
1292
- }
1293
- #ifdef EXTRA_FUNCTIONALITY
1294
- else if (PyLong_Check (traps )) {
1295
- ret = context_settraps (self , traps , NULL );
1296
- }
1297
- #endif
1298
- else {
1299
- ret = context_settraps_dict (self , traps );
1300
- }
1301
- if (ret < 0 ) {
1302
- return ret ;
1303
- }
1304
- }
1305
- if (status != Py_None ) {
1306
- if (PyList_Check (status )) {
1307
- ret = context_setstatus_list (self , status );
1308
- }
1309
- #ifdef EXTRA_FUNCTIONALITY
1310
- else if (PyLong_Check (status )) {
1311
- ret = context_setstatus (self , status , NULL );
1312
- }
1313
- #endif
1314
- else {
1315
- ret = context_setstatus_dict (self , status );
1316
- }
1317
- if (ret < 0 ) {
1318
- return ret ;
1319
- }
1320
- }
1321
-
1322
- return 0 ;
1330
+ return context_setattrs (
1331
+ self , prec , rounding ,
1332
+ emin , emax , capitals ,
1333
+ clamp , status , traps
1334
+ );
1323
1335
}
1324
1336
1325
1337
static PyObject *
@@ -1721,13 +1733,28 @@ PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v)
1721
1733
static PyObject *
1722
1734
ctxmanager_new (PyTypeObject * type UNUSED , PyObject * args , PyObject * kwds )
1723
1735
{
1724
- static char * kwlist [] = {"ctx" , NULL };
1736
+ static char * kwlist [] = {
1737
+ "ctx" , "prec" , "rounding" ,
1738
+ "Emin" , "Emax" , "capitals" ,
1739
+ "clamp" , "flags" , "traps" ,
1740
+ NULL
1741
+ };
1725
1742
PyDecContextManagerObject * self ;
1726
1743
PyObject * local = Py_None ;
1727
1744
PyObject * global ;
1728
1745
1746
+ PyObject * prec = Py_None ;
1747
+ PyObject * rounding = Py_None ;
1748
+ PyObject * Emin = Py_None ;
1749
+ PyObject * Emax = Py_None ;
1750
+ PyObject * capitals = Py_None ;
1751
+ PyObject * clamp = Py_None ;
1752
+ PyObject * flags = Py_None ;
1753
+ PyObject * traps = Py_None ;
1754
+
1729
1755
CURRENT_CONTEXT (global );
1730
- if (!PyArg_ParseTupleAndKeywords (args , kwds , "|O" , kwlist , & local )) {
1756
+ if (!PyArg_ParseTupleAndKeywords (args , kwds , "|OOOOOOOOO" , kwlist , & local ,
1757
+ & prec , & rounding , & Emin , & Emax , & capitals , & clamp , & flags , & traps )) {
1731
1758
return NULL ;
1732
1759
}
1733
1760
if (local == Py_None ) {
@@ -1754,6 +1781,17 @@ ctxmanager_new(PyTypeObject *type UNUSED, PyObject *args, PyObject *kwds)
1754
1781
self -> global = global ;
1755
1782
Py_INCREF (self -> global );
1756
1783
1784
+ int ret = context_setattrs (
1785
+ self -> local , prec , rounding ,
1786
+ Emin , Emax , capitals ,
1787
+ clamp , flags , traps
1788
+ );
1789
+
1790
+ if (ret < 0 ) {
1791
+ Py_DECREF (self );
1792
+ return NULL ;
1793
+ }
1794
+
1757
1795
return (PyObject * )self ;
1758
1796
}
1759
1797
0 commit comments