@@ -1156,6 +1156,67 @@ context_setattr(PyObject *self, PyObject *name, PyObject *value)
11561156 return PyObject_GenericSetAttr (self , name , value );
11571157}
11581158
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+
11591220static PyObject *
11601221context_clear_traps (PyObject * self , PyObject * dummy UNUSED )
11611222{
@@ -1255,7 +1316,6 @@ context_init(PyObject *self, PyObject *args, PyObject *kwds)
12551316 PyObject * clamp = Py_None ;
12561317 PyObject * status = Py_None ;
12571318 PyObject * traps = Py_None ;
1258- int ret ;
12591319
12601320 assert (PyTuple_Check (args ));
12611321
@@ -1267,59 +1327,11 @@ context_init(PyObject *self, PyObject *args, PyObject *kwds)
12671327 return -1 ;
12681328 }
12691329
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+ );
13231335}
13241336
13251337static PyObject *
@@ -1721,13 +1733,28 @@ PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v)
17211733static PyObject *
17221734ctxmanager_new (PyTypeObject * type UNUSED , PyObject * args , PyObject * kwds )
17231735{
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+ };
17251742 PyDecContextManagerObject * self ;
17261743 PyObject * local = Py_None ;
17271744 PyObject * global ;
17281745
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+
17291755 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 )) {
17311758 return NULL ;
17321759 }
17331760 if (local == Py_None ) {
@@ -1754,6 +1781,17 @@ ctxmanager_new(PyTypeObject *type UNUSED, PyObject *args, PyObject *kwds)
17541781 self -> global = global ;
17551782 Py_INCREF (self -> global );
17561783
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+
17571795 return (PyObject * )self ;
17581796}
17591797
0 commit comments