@@ -1474,8 +1474,6 @@ context_config(getdns_ContextObject *self, PyObject *args, PyObject *keywds)
1474
1474
}
1475
1475
getdns_config = pdict_to_gdict (py_config );
1476
1476
char buf [4096 ];
1477
- getdns_pretty_snprint_dict (buf , 4096 , getdns_config );
1478
- printf ("%s\n" , buf );
1479
1477
if ((ret = getdns_context_config (context , getdns_config )) != GETDNS_RETURN_GOOD ) {
1480
1478
PyErr_SetString (getdns_error , getdns_get_errorstr_by_id (ret ));
1481
1479
return NULL ;
@@ -1505,12 +1503,26 @@ pdict_to_gdict(PyObject *py_dict)
1505
1503
for ( i = 0 ; i < keys_size ; i ++ ) {
1506
1504
key = PyList_GetItem (py_keys , i );
1507
1505
py_item = PyDict_GetItem (py_dict , key );
1508
- if (PyInt_Check (py_item ))
1506
+ #if PY_MAJOR_VERSION >= 3
1507
+ if (PyLong_Check (py_item ))
1508
+ (void )getdns_dict_set_int (g_dict , PyBytes_AsString (PyUnicode_AsEncodedString (key , "ascii" , NULL )), (uint32_t )PyLong_AsLong (py_item ));
1509
+ #else
1510
+ if (PyInt_Check (py_item ))
1509
1511
(void )getdns_dict_set_int (g_dict , PyString_AsString (key ), (uint32_t )PyInt_AsLong (py_item ));
1512
+ #endif
1513
+ #if PY_MAJOR_VERSION >= 3
1514
+ else if (PyUnicode_Check (py_item )) {
1515
+ #else
1510
1516
else if (PyString_Check (py_item )) {
1517
+ #endif
1511
1518
getdns_bindata g_bindata ;
1519
+ #if PY_MAJOR_VERSION >= 3
1520
+ char * str = PyBytes_AsString (PyUnicode_AsEncodedString (py_item , "ascii" , NULL ));
1521
+ keystr = PyBytes_AsString (PyUnicode_AsEncodedString (key , "ascii" , NULL ));
1522
+ #else
1512
1523
char * str = PyString_AsString (py_item );
1513
1524
keystr = PyString_AsString (key );
1525
+ #endif
1514
1526
if (!strncmp (keystr , "address_data" , strlen ("address_data" ))) {
1515
1527
int af ;
1516
1528
char buf [16 ];
@@ -1531,12 +1543,27 @@ pdict_to_gdict(PyObject *py_dict)
1531
1543
g_bindata .data = (uint8_t * )str ;
1532
1544
g_bindata .size = strlen (str );
1533
1545
}
1546
+ #if PY_MAJOR_VERSION >= 3
1547
+ (void )getdns_dict_set_bindata (g_dict , PyBytes_AsString (
1548
+ PyUnicode_AsEncodedString (key , "ascii" , NULL )),
1549
+ & g_bindata );
1550
+ } else if (PyList_Check (py_item )) {
1551
+ getdns_list * tmp_list = plist_to_glist (py_item );
1552
+ getdns_dict_set_list (g_dict , PyBytes_AsString (
1553
+ PyUnicode_AsEncodedString (key , "ascii" , NULL )),
1554
+ tmp_list );
1555
+ } else if (PyDict_Check (py_dict ))
1556
+ getdns_dict_set_dict (g_dict , PyBytes_AsString (
1557
+ PyUnicode_AsEncodedString (key , "ascii ", NULL )),
1558
+ pdict_to_gdict (py_item ));
1559
+ #else
1534
1560
(void )getdns_dict_set_bindata (g_dict , PyString_AsString (key ), & g_bindata );
1535
1561
} else if (PyList_Check (py_item )) {
1536
1562
getdns_list * tmp_list = plist_to_glist (py_item );
1537
1563
getdns_dict_set_list (g_dict , PyString_AsString (key ), tmp_list );
1538
1564
} else if (PyDict_Check (py_dict ))
1539
1565
getdns_dict_set_dict (g_dict , PyString_AsString (key ), pdict_to_gdict (py_item ));
1566
+ #endif
1540
1567
}
1541
1568
return g_dict ;
1542
1569
}
@@ -1557,11 +1584,24 @@ plist_to_glist(PyObject *py_list)
1557
1584
list_size = PyList_Size (py_list );
1558
1585
for ( i = 0 ; i < list_size ; i ++ ) {
1559
1586
py_item = PyList_GetItem (py_list , i );
1587
+ #if PY_MAJOR_VERSION >= 3
1588
+ if (PyLong_Check (py_item ))
1589
+ (void )getdns_list_set_int (g_list , (int )i , (uint32_t )PyLong_AsLong (py_item ));
1590
+ #else
1560
1591
if (PyInt_Check (py_item ))
1561
1592
(void )getdns_list_set_int (g_list , (int )i , (uint32_t )PyInt_AsLong (py_item ));
1593
+ #endif
1594
+ #if PY_MAJOR_VERSION >= 3
1595
+ else if (PyUnicode_Check (py_item )) {
1596
+ #else
1562
1597
else if (PyString_Check (py_item )) {
1598
+ #endif
1563
1599
getdns_bindata g_bindata ;
1600
+ #if PY_MAJOR_VERSION >= 3
1601
+ char * str = PyBytes_AsString (PyUnicode_AsEncodedString (py_item , "ascii" , NULL ));
1602
+ #else
1564
1603
char * str = PyString_AsString (py_item );
1604
+ #endif
1565
1605
g_bindata .size = strlen (str );
1566
1606
g_bindata .data = (uint8_t * )str ;
1567
1607
(void )getdns_list_set_bindata (g_list , (int )i , & g_bindata );
0 commit comments