@@ -457,8 +457,7 @@ static PyObject *Proxy_oct(ProxyObject *self)
457
457
458
458
if ((nb = self -> wrapped -> ob_type -> tp_as_number ) == NULL ||
459
459
nb -> nb_oct == NULL ) {
460
- PyErr_SetString (PyExc_TypeError ,
461
- "oct() argument can't be converted to oct" );
460
+ PyErr_SetString (PyExc_TypeError , "oct() argument can't be converted to oct" );
462
461
return NULL ;
463
462
}
464
463
@@ -477,8 +476,7 @@ static PyObject *Proxy_hex(ProxyObject *self)
477
476
478
477
if ((nb = self -> wrapped -> ob_type -> tp_as_number ) == NULL ||
479
478
nb -> nb_hex == NULL ) {
480
- PyErr_SetString (PyExc_TypeError ,
481
- "hex() argument can't be converted to hex" );
479
+ PyErr_SetString (PyExc_TypeError , "hex() argument can't be converted to hex" );
482
480
return NULL ;
483
481
}
484
482
@@ -854,8 +852,7 @@ static PyObject *Proxy_dir(
854
852
855
853
/* ------------------------------------------------------------------------- */
856
854
857
- static PyObject * Proxy_enter (
858
- ProxyObject * self , PyObject * args , PyObject * kwds )
855
+ static PyObject * Proxy_enter (ProxyObject * self )
859
856
{
860
857
PyObject * method = NULL ;
861
858
PyObject * result = NULL ;
@@ -867,7 +864,7 @@ static PyObject *Proxy_enter(
867
864
if (!method )
868
865
return NULL ;
869
866
870
- result = PyObject_Call (method , args , kwds );
867
+ result = PyObject_CallObject (method , NULL );
871
868
872
869
Py_DECREF (method );
873
870
@@ -1227,6 +1224,121 @@ static PyObject *Proxy_call(
1227
1224
1228
1225
/* ------------------------------------------------------------------------- */ ;
1229
1226
1227
+ #if PY_MAJOR_VERSION >= 3
1228
+
1229
+ static PyObject * Proxy_aenter (ProxyObject * self )
1230
+ {
1231
+ PyObject * method = NULL ;
1232
+ PyObject * result = NULL ;
1233
+
1234
+ Proxy__ENSURE_WRAPPED_OR_RETURN_NULL (self );
1235
+
1236
+ method = PyObject_GetAttrString (self -> wrapped , "__aenter__" );
1237
+
1238
+ if (!method )
1239
+ return NULL ;
1240
+
1241
+ result = PyObject_CallObject (method , NULL );
1242
+
1243
+ Py_DECREF (method );
1244
+
1245
+ return result ;
1246
+ }
1247
+
1248
+ /* ------------------------------------------------------------------------- */
1249
+
1250
+ static PyObject * Proxy_aexit (
1251
+ ProxyObject * self , PyObject * args , PyObject * kwds )
1252
+ {
1253
+ PyObject * method = NULL ;
1254
+ PyObject * result = NULL ;
1255
+
1256
+ Proxy__ENSURE_WRAPPED_OR_RETURN_NULL (self );
1257
+
1258
+ method = PyObject_GetAttrString (self -> wrapped , "__aexit__" );
1259
+
1260
+ if (!method )
1261
+ return NULL ;
1262
+
1263
+ result = PyObject_Call (method , args , kwds );
1264
+
1265
+ Py_DECREF (method );
1266
+
1267
+ return result ;
1268
+ }
1269
+
1270
+ /* ------------------------------------------------------------------------- */
1271
+
1272
+ static PyObject * Proxy_await (ProxyObject * self )
1273
+ {
1274
+ Proxy__ENSURE_WRAPPED_OR_RETURN_NULL (self );
1275
+
1276
+ unaryfunc meth = NULL ;
1277
+ PyObject * wrapped = self -> wrapped ;
1278
+ PyTypeObject * type = Py_TYPE (wrapped );
1279
+
1280
+
1281
+ if (type -> tp_as_async != NULL ) {
1282
+ meth = type -> tp_as_async -> am_await ;
1283
+ }
1284
+
1285
+ if (meth != NULL ) {
1286
+ return (* meth )(wrapped );
1287
+ }
1288
+
1289
+ PyErr_Format (PyExc_TypeError , " %.100s is missing the __await__ method" , type -> tp_name );
1290
+ return NULL ;
1291
+ }
1292
+
1293
+ /* ------------------------------------------------------------------------- */ ;
1294
+
1295
+ static PyObject * Proxy_aiter (ProxyObject * self )
1296
+ {
1297
+ Proxy__ENSURE_WRAPPED_OR_RETURN_NULL (self );
1298
+
1299
+ unaryfunc meth = NULL ;
1300
+ PyObject * wrapped = self -> wrapped ;
1301
+ PyTypeObject * type = Py_TYPE (wrapped );
1302
+
1303
+ if (type -> tp_as_async != NULL ) {
1304
+ meth = type -> tp_as_async -> am_aiter ;
1305
+ }
1306
+
1307
+ if (meth != NULL ) {
1308
+ return (* meth )(wrapped );
1309
+ }
1310
+
1311
+ PyErr_Format (PyExc_TypeError , " %.100s is missing the __aiter__ method" , type -> tp_name );
1312
+ return NULL ;
1313
+ }
1314
+
1315
+ /* ------------------------------------------------------------------------- */ ;
1316
+
1317
+ static PyObject * Proxy_anext (ProxyObject * self )
1318
+ {
1319
+ Proxy__ENSURE_WRAPPED_OR_RETURN_NULL (self );
1320
+
1321
+
1322
+ unaryfunc meth = NULL ;
1323
+ PyObject * wrapped = self -> wrapped ;
1324
+ PyTypeObject * type = Py_TYPE (wrapped );
1325
+
1326
+ if (type -> tp_as_async != NULL ) {
1327
+ meth = type -> tp_as_async -> am_anext ;
1328
+ }
1329
+
1330
+ if (meth != NULL ) {
1331
+ return (* meth )(wrapped );
1332
+ }
1333
+
1334
+ PyErr_Format (PyExc_TypeError , " %.100s is missing the __anext__ method" , type -> tp_name );
1335
+ return NULL ;
1336
+ }
1337
+
1338
+ #endif
1339
+
1340
+ /* ------------------------------------------------------------------------- */ ;
1341
+
1230
1342
static PyNumberMethods Proxy_as_number = {
1231
1343
(binaryfunc )Proxy_add , /*nb_add*/
1232
1344
(binaryfunc )Proxy_subtract , /*nb_subtract*/
@@ -1299,10 +1411,17 @@ static PyMappingMethods Proxy_as_mapping = {
1299
1411
(objobjargproc )Proxy_setitem , /*mp_ass_subscript*/
1300
1412
};
1301
1413
1414
+ #if PY_MAJOR_VERSION >= 3
1415
+ static PyAsyncMethods Proxy_as_async = {
1416
+ (unaryfunc )Proxy_await , /* am_await */
1417
+ (unaryfunc )Proxy_aiter , /* am_aiter */
1418
+ (unaryfunc )Proxy_anext , /* am_anext */
1419
+ };
1420
+ #endif
1421
+
1302
1422
static PyMethodDef Proxy_methods [] = {
1303
1423
{ "__dir__" , (PyCFunction )Proxy_dir , METH_NOARGS , 0 },
1304
- { "__enter__" , (PyCFunction )Proxy_enter ,
1305
- METH_VARARGS | METH_KEYWORDS , 0 },
1424
+ { "__enter__" , (PyCFunction )Proxy_enter , METH_NOARGS , 0 },
1306
1425
{ "__exit__" , (PyCFunction )Proxy_exit ,
1307
1426
METH_VARARGS | METH_KEYWORDS , 0 },
1308
1427
{ "__getattr__" , (PyCFunction )Proxy_getattr ,
@@ -1314,6 +1433,9 @@ static PyMethodDef Proxy_methods[] = {
1314
1433
{ "__fspath__" , (PyCFunction )Proxy_fspath , METH_NOARGS , 0 },
1315
1434
#if PY_MAJOR_VERSION >= 3
1316
1435
{ "__round__" , (PyCFunction )Proxy_round , METH_NOARGS , 0 },
1436
+ { "__aenter__" , (PyCFunction )Proxy_aenter , METH_NOARGS , 0 },
1437
+ { "__aexit__" , (PyCFunction )Proxy_aexit ,
1438
+ METH_VARARGS | METH_KEYWORDS , 0 },
1317
1439
#endif
1318
1440
{ NULL , NULL },
1319
1441
};
@@ -1348,7 +1470,11 @@ PyTypeObject Proxy_Type = {
1348
1470
0 , /*tp_print*/
1349
1471
0 , /*tp_getattr*/
1350
1472
0 , /*tp_setattr*/
1473
+ #if PY_MAJOR_VERSION >= 3
1474
+ & Proxy_as_async , /* tp_as_async */
1475
+ #else
1351
1476
0 , /*tp_compare*/
1477
+ #endif
1352
1478
(unaryfunc )Proxy_repr , /*tp_repr*/
1353
1479
& Proxy_as_number , /*tp_as_number*/
1354
1480
& Proxy_as_sequence , /*tp_as_sequence*/
0 commit comments