1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
|
Index: netifaces/netifaces.c
===================================================================
--- netifaces.orig/netifaces.c 2013-12-13 01:17:20.210600845 +0100
+++ netifaces/netifaces.c 2013-12-13 01:17:20.206600845 +0100
@@ -1,5 +1,19 @@
#include <Python.h>
+#if PY_MAJOR_VERSION >= 3
+
+#define IS_PY3K
+
+# define PyText_FromUTF8 PyUnicode_FromString
+# define PyInt_FromLong PyLong_FromLong
+
+#else // Python 2.x
+
+# define PyText_FromUTF8 PyString_FromString
+// obviously, PyInt_FromLong is PyInt_FromLong
+
+#endif
+
#ifndef WIN32
# include <sys/types.h>
@@ -171,8 +185,6 @@
# define AF_LINK -1000
# endif
# define HAVE_AF_LINK 0
-#elif defined(__GNU__)
-# define HAVE_AF_LINK 0
#else
# define HAVE_AF_LINK 1
#endif
@@ -506,7 +518,7 @@
}
*--ptr = '\0';
- hwaddr = PyString_FromString (buffer);
+ hwaddr = PyText_FromUTF8 (buffer);
dict = PyDict_New ();
if (!dict) {
@@ -544,7 +556,7 @@
if (iRet)
continue;
- addr = PyString_FromString (buffer);
+ addr = PyText_FromUTF8 (buffer);
/* Find the netmask, where possible */
if (family == AF_INET) {
@@ -615,7 +627,7 @@
&dwLen);
if (iRet == 0)
- mask = PyString_FromString (buffer);
+ mask = PyText_FromUTF8 (buffer);
dwLen = sizeof (buffer);
iRet = WSAAddressToString ((SOCKADDR *)&bcastAddr,
@@ -625,7 +637,7 @@
&dwLen);
if (iRet == 0)
- bcast = PyString_FromString (buffer);
+ bcast = PyText_FromUTF8 (buffer);
else
printf ("%d\n", iRet);
@@ -699,7 +711,7 @@
&dwLen);
if (iRet == 0)
- mask = PyString_FromString (buffer);
+ mask = PyText_FromUTF8 (buffer);
dwLen = sizeof (buffer);
iRet = WSAAddressToString ((SOCKADDR *)&bcastAddr,
@@ -709,7 +721,7 @@
&dwLen);
if (iRet == 0)
- bcast = PyString_FromString (buffer);
+ bcast = PyText_FromUTF8 (buffer);
break;
}
@@ -777,13 +789,13 @@
continue;
if (string_from_sockaddr (addr->ifa_addr, buffer, sizeof (buffer)) == 0)
- pyaddr = PyString_FromString (buffer);
+ pyaddr = PyText_FromUTF8 (buffer);
if (string_from_sockaddr (addr->ifa_netmask, buffer, sizeof (buffer)) == 0)
- netmask = PyString_FromString (buffer);
+ netmask = PyText_FromUTF8 (buffer);
if (string_from_sockaddr (addr->ifa_broadaddr, buffer, sizeof (buffer)) == 0)
- braddr = PyString_FromString (buffer);
+ braddr = PyText_FromUTF8 (buffer);
PyObject *dict = PyDict_New();
@@ -842,7 +854,7 @@
found = TRUE;
if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0) {
- PyObject *hwaddr = PyString_FromString (buffer);
+ PyObject *hwaddr = PyText_FromUTF8 (buffer);
PyObject *dict = PyDict_New ();
if (!hwaddr || !dict) {
@@ -874,7 +886,7 @@
found = TRUE;
if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
- addr = PyString_FromString (buffer);
+ addr = PyText_FromUTF8 (buffer);
}
#endif
@@ -887,7 +899,7 @@
found = TRUE;
if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
- netmask = PyString_FromString (buffer);
+ netmask = PyText_FromUTF8 (buffer);
}
#endif
@@ -913,7 +925,7 @@
found = TRUE;
if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
- braddr = PyString_FromString (buffer);
+ braddr = PyText_FromUTF8 (buffer);
}
#endif
@@ -926,7 +938,7 @@
found = TRUE;
if (string_from_sockaddr ((struct sockaddr *)&ifr.CNAME(ifr_addr), buffer, sizeof (buffer)) == 0)
- dstaddr = PyString_FromString (buffer);
+ dstaddr = PyText_FromUTF8 (buffer);
}
#endif
@@ -1020,7 +1032,7 @@
}
for (pInfo = pAdapterAddresses; pInfo; pInfo = pInfo->Next) {
- PyObject *ifname = (PyObject *)PyString_FromString (pInfo->AdapterName);
+ PyObject *ifname = (PyObject *)PyText_FromUTF8 (pInfo->AdapterName);
PyList_Append (result, ifname);
Py_DECREF (ifname);
@@ -1042,7 +1054,7 @@
for (addr = addrs; addr; addr = addr->ifa_next) {
if (!prev_name || strncmp (addr->ifa_name, prev_name, IFNAMSIZ) != 0) {
- PyObject *ifname = PyString_FromString (addr->ifa_name);
+ PyObject *ifname = PyText_FromUTF8 (addr->ifa_name);
if (!PySequence_Contains (result, ifname))
PyList_Append (result, ifname);
@@ -1110,7 +1122,7 @@
+ ifc.CNAME(ifc_len));
while (pfreq < pfreqend) {
if (!prev_name || strncmp (prev_name, pfreq->CNAME(ifr_name), IFNAMSIZ) != 0) {
- PyObject *name = PyString_FromString (pfreq->CNAME(ifr_name));
+ PyObject *name = PyText_FromUTF8 (pfreq->CNAME(ifr_name));
if (!PySequence_Contains (result, name))
PyList_Append (result, name);
@@ -1152,8 +1164,28 @@
{ NULL, NULL, 0, NULL }
};
-PyMODINIT_FUNC
-initnetifaces (void)
+#ifdef IS_PY3K
+
+struct module_state {
+ PyObject *error;
+};
+
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "netifaces",
+ NULL,
+ sizeof(struct module_state),
+ methods,
+ NULL,
+ NULL, // ext_traverse,
+ NULL, // ext_clear,
+ NULL
+};
+
+#endif
+
+static PyObject *
+netifaces_init (void)
{
PyObject *address_family_dict;
PyObject *m;
@@ -1164,304 +1196,308 @@
WSAStartup(MAKEWORD (2, 2), &wsad);
#endif
+#ifndef IS_PY3K
m = Py_InitModule ("netifaces", methods);
+#else
+ m = PyModule_Create (&moduledef);
+#endif
/* Address families (auto-detect using #ifdef) */
address_family_dict = PyDict_New();
#ifdef AF_UNSPEC
PyModule_AddIntConstant (m, "AF_UNSPEC", AF_UNSPEC);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_UNSPEC),
- PyString_FromString("AF_UNSPEC"));
+ PyText_FromUTF8("AF_UNSPEC"));
#endif
#ifdef AF_UNIX
PyModule_AddIntConstant (m, "AF_UNIX", AF_UNIX);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_UNIX),
- PyString_FromString("AF_UNIX"));
+ PyText_FromUTF8("AF_UNIX"));
#endif
#ifdef AF_FILE
PyModule_AddIntConstant (m, "AF_FILE", AF_FILE);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_FILE),
- PyString_FromString("AF_FILE"));
+ PyText_FromUTF8("AF_FILE"));
#endif
#ifdef AF_INET
PyModule_AddIntConstant (m, "AF_INET", AF_INET);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_INET),
- PyString_FromString("AF_INET"));
+ PyText_FromUTF8("AF_INET"));
#endif
#ifdef AF_AX25
PyModule_AddIntConstant (m, "AF_AX25", AF_AX25);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_AX25),
- PyString_FromString("AF_AX25"));
+ PyText_FromUTF8("AF_AX25"));
#endif
#ifdef AF_IMPLINK
PyModule_AddIntConstant (m, "AF_IMPLINK", AF_IMPLINK);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_IMPLINK),
- PyString_FromString("AF_IMPLINK"));
+ PyText_FromUTF8("AF_IMPLINK"));
#endif
#ifdef AF_PUP
PyModule_AddIntConstant (m, "AF_PUP", AF_PUP);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_PUP),
- PyString_FromString("AF_PUP"));
+ PyText_FromUTF8("AF_PUP"));
#endif
#ifdef AF_CHAOS
PyModule_AddIntConstant (m, "AF_CHAOS", AF_CHAOS);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_CHAOS),
- PyString_FromString("AF_CHAOS"));
+ PyText_FromUTF8("AF_CHAOS"));
#endif
#ifdef AF_NS
PyModule_AddIntConstant (m, "AF_NS", AF_NS);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_NS),
- PyString_FromString("AF_NS"));
+ PyText_FromUTF8("AF_NS"));
#endif
#ifdef AF_ISO
PyModule_AddIntConstant (m, "AF_ISO", AF_ISO);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ISO),
- PyString_FromString("AF_ISO"));
+ PyText_FromUTF8("AF_ISO"));
#endif
#ifdef AF_ECMA
PyModule_AddIntConstant (m, "AF_ECMA", AF_ECMA);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ECMA),
- PyString_FromString("AF_ECMA"));
+ PyText_FromUTF8("AF_ECMA"));
#endif
#ifdef AF_DATAKIT
PyModule_AddIntConstant (m, "AF_DATAKIT", AF_DATAKIT);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_DATAKIT),
- PyString_FromString("AF_DATAKIT"));
+ PyText_FromUTF8("AF_DATAKIT"));
#endif
#ifdef AF_CCITT
PyModule_AddIntConstant (m, "AF_CCITT", AF_CCITT);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_CCITT),
- PyString_FromString("AF_CCITT"));
+ PyText_FromUTF8("AF_CCITT"));
#endif
#ifdef AF_SNA
PyModule_AddIntConstant (m, "AF_SNA", AF_SNA);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_SNA),
- PyString_FromString("AF_SNA"));
+ PyText_FromUTF8("AF_SNA"));
#endif
#ifdef AF_DECnet
PyModule_AddIntConstant (m, "AF_DECnet", AF_DECnet);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_DECnet),
- PyString_FromString("AF_DECnet"));
+ PyText_FromUTF8("AF_DECnet"));
#endif
#ifdef AF_DLI
PyModule_AddIntConstant (m, "AF_DLI", AF_DLI);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_DLI),
- PyString_FromString("AF_DLI"));
+ PyText_FromUTF8("AF_DLI"));
#endif
#ifdef AF_LAT
PyModule_AddIntConstant (m, "AF_LAT", AF_LAT);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_LAT),
- PyString_FromString("AF_LAT"));
+ PyText_FromUTF8("AF_LAT"));
#endif
#ifdef AF_HYLINK
PyModule_AddIntConstant (m, "AF_HYLINK", AF_HYLINK);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_HYLINK),
- PyString_FromString("AF_HYLINK"));
+ PyText_FromUTF8("AF_HYLINK"));
#endif
#ifdef AF_APPLETALK
PyModule_AddIntConstant (m, "AF_APPLETALK", AF_APPLETALK);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_APPLETALK),
- PyString_FromString("AF_APPLETALK"));
+ PyText_FromUTF8("AF_APPLETALK"));
#endif
#ifdef AF_ROUTE
PyModule_AddIntConstant (m, "AF_ROUTE", AF_ROUTE);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ROUTE),
- PyString_FromString("AF_ROUTE"));
+ PyText_FromUTF8("AF_ROUTE"));
#endif
#ifdef AF_LINK
PyModule_AddIntConstant (m, "AF_LINK", AF_LINK);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_LINK),
- PyString_FromString("AF_LINK"));
+ PyText_FromUTF8("AF_LINK"));
#endif
#ifdef AF_PACKET
PyModule_AddIntConstant (m, "AF_PACKET", AF_PACKET);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_PACKET),
- PyString_FromString("AF_PACKET"));
+ PyText_FromUTF8("AF_PACKET"));
#endif
#ifdef AF_COIP
PyModule_AddIntConstant (m, "AF_COIP", AF_COIP);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_COIP),
- PyString_FromString("AF_COIP"));
+ PyText_FromUTF8("AF_COIP"));
#endif
#ifdef AF_CNT
PyModule_AddIntConstant (m, "AF_CNT", AF_CNT);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_CNT),
- PyString_FromString("AF_CNT"));
+ PyText_FromUTF8("AF_CNT"));
#endif
#ifdef AF_IPX
PyModule_AddIntConstant (m, "AF_IPX", AF_IPX);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_IPX),
- PyString_FromString("AF_IPX"));
+ PyText_FromUTF8("AF_IPX"));
#endif
#ifdef AF_SIP
PyModule_AddIntConstant (m, "AF_SIP", AF_SIP);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_SIP),
- PyString_FromString("AF_SIP"));
+ PyText_FromUTF8("AF_SIP"));
#endif
#ifdef AF_NDRV
PyModule_AddIntConstant (m, "AF_NDRV", AF_NDRV);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_NDRV),
- PyString_FromString("AF_NDRV"));
+ PyText_FromUTF8("AF_NDRV"));
#endif
#ifdef AF_ISDN
PyModule_AddIntConstant (m, "AF_ISDN", AF_ISDN);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ISDN),
- PyString_FromString("AF_ISDN"));
+ PyText_FromUTF8("AF_ISDN"));
#endif
#ifdef AF_INET6
PyModule_AddIntConstant (m, "AF_INET6", AF_INET6);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_INET6),
- PyString_FromString("AF_INET6"));
+ PyText_FromUTF8("AF_INET6"));
#endif
#ifdef AF_NATM
PyModule_AddIntConstant (m, "AF_NATM", AF_NATM);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_NATM),
- PyString_FromString("AF_NATM"));
+ PyText_FromUTF8("AF_NATM"));
#endif
#ifdef AF_SYSTEM
PyModule_AddIntConstant (m, "AF_SYSTEM", AF_SYSTEM);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_SYSTEM),
- PyString_FromString("AF_SYSTEM"));
+ PyText_FromUTF8("AF_SYSTEM"));
#endif
#ifdef AF_NETBIOS
PyModule_AddIntConstant (m, "AF_NETBIOS", AF_NETBIOS);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_NETBIOS),
- PyString_FromString("AF_NETBIOS"));
+ PyText_FromUTF8("AF_NETBIOS"));
#endif
#ifdef AF_NETBEUI
PyModule_AddIntConstant (m, "AF_NETBEUI", AF_NETBEUI);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_NETBEUI),
- PyString_FromString("AF_NETBEUI"));
+ PyText_FromUTF8("AF_NETBEUI"));
#endif
#ifdef AF_PPP
PyModule_AddIntConstant (m, "AF_PPP", AF_PPP);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_PPP),
- PyString_FromString("AF_PPP"));
+ PyText_FromUTF8("AF_PPP"));
#endif
#ifdef AF_ATM
PyModule_AddIntConstant (m, "AF_ATM", AF_ATM);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ATM),
- PyString_FromString("AF_ATM"));
+ PyText_FromUTF8("AF_ATM"));
#endif
#ifdef AF_ATMPVC
PyModule_AddIntConstant (m, "AF_ATMPVC", AF_ATMPVC);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ATMPVC),
- PyString_FromString("AF_ATMPVC"));
+ PyText_FromUTF8("AF_ATMPVC"));
#endif
#ifdef AF_ATMSVC
PyModule_AddIntConstant (m, "AF_ATMSVC", AF_ATMSVC);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ATMSVC),
- PyString_FromString("AF_ATMSVC"));
+ PyText_FromUTF8("AF_ATMSVC"));
#endif
#ifdef AF_NETGRAPH
PyModule_AddIntConstant (m, "AF_NETGRAPH", AF_NETGRAPH);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_NETGRAPH),
- PyString_FromString("AF_NETGRAPH"));
+ PyText_FromUTF8("AF_NETGRAPH"));
#endif
#ifdef AF_VOICEVIEW
PyModule_AddIntConstant (m, "AF_VOICEVIEW", AF_VOICEVIEW);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_VOICEVIEW),
- PyString_FromString("AF_VOICEVIEW"));
+ PyText_FromUTF8("AF_VOICEVIEW"));
#endif
#ifdef AF_FIREFOX
PyModule_AddIntConstant (m, "AF_FIREFOX", AF_FIREFOX);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_FIREFOX),
- PyString_FromString("AF_FIREFOX"));
+ PyText_FromUTF8("AF_FIREFOX"));
#endif
#ifdef AF_UNKNOWN1
PyModule_AddIntConstant (m, "AF_UNKNOWN1", AF_UNKNOWN1);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_UNKNOWN1),
- PyString_FromString("AF_UNKNOWN1"));
+ PyText_FromUTF8("AF_UNKNOWN1"));
#endif
#ifdef AF_BAN
PyModule_AddIntConstant (m, "AF_BAN", AF_BAN);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_BAN),
- PyString_FromString("AF_BAN"));
+ PyText_FromUTF8("AF_BAN"));
#endif
#ifdef AF_CLUSTER
PyModule_AddIntConstant (m, "AF_CLUSTER", AF_CLUSTER);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_CLUSTER),
- PyString_FromString("AF_CLUSTER"));
+ PyText_FromUTF8("AF_CLUSTER"));
#endif
#ifdef AF_12844
PyModule_AddIntConstant (m, "AF_12844", AF_12844);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_12844),
- PyString_FromString("AF_12844"));
+ PyText_FromUTF8("AF_12844"));
#endif
#ifdef AF_IRDA
PyModule_AddIntConstant (m, "AF_IRDA", AF_IRDA);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_IRDA),
- PyString_FromString("AF_IRDA"));
+ PyText_FromUTF8("AF_IRDA"));
#endif
#ifdef AF_NETDES
PyModule_AddIntConstant (m, "AF_NETDES", AF_NETDES);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_NETDES),
- PyString_FromString("AF_NETDES"));
+ PyText_FromUTF8("AF_NETDES"));
#endif
#ifdef AF_NETROM
PyModule_AddIntConstant (m, "AF_NETROM", AF_NETROM);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_NETROM),
- PyString_FromString("AF_NETROM"));
+ PyText_FromUTF8("AF_NETROM"));
#endif
#ifdef AF_BRIDGE
PyModule_AddIntConstant (m, "AF_BRIDGE", AF_BRIDGE);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_BRIDGE),
- PyString_FromString("AF_BRIDGE"));
+ PyText_FromUTF8("AF_BRIDGE"));
#endif
#ifdef AF_X25
PyModule_AddIntConstant (m, "AF_X25", AF_X25);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_X25),
- PyString_FromString("AF_X25"));
+ PyText_FromUTF8("AF_X25"));
#endif
#ifdef AF_ROSE
PyModule_AddIntConstant (m, "AF_ROSE", AF_ROSE);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ROSE),
- PyString_FromString("AF_ROSE"));
+ PyText_FromUTF8("AF_ROSE"));
#endif
#ifdef AF_SECURITY
PyModule_AddIntConstant (m, "AF_SECURITY", AF_SECURITY);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_SECURITY),
- PyString_FromString("AF_SECURITY"));
+ PyText_FromUTF8("AF_SECURITY"));
#endif
#ifdef AF_KEY
PyModule_AddIntConstant (m, "AF_KEY", AF_KEY);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_KEY),
- PyString_FromString("AF_KEY"));
+ PyText_FromUTF8("AF_KEY"));
#endif
#ifdef AF_NETLINK
PyModule_AddIntConstant (m, "AF_NETLINK", AF_NETLINK);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_NETLINK),
- PyString_FromString("AF_NETLINK"));
+ PyText_FromUTF8("AF_NETLINK"));
#endif
#ifdef AF_ASH
PyModule_AddIntConstant (m, "AF_ASH", AF_ASH);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ASH),
- PyString_FromString("AF_ASH"));
+ PyText_FromUTF8("AF_ASH"));
#endif
#ifdef AF_ECONET
PyModule_AddIntConstant (m, "AF_ECONET", AF_ECONET);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_ECONET),
- PyString_FromString("AF_ECONET"));
+ PyText_FromUTF8("AF_ECONET"));
#endif
#ifdef AF_SNA
PyModule_AddIntConstant (m, "AF_SNA", AF_SNA);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_SNA),
- PyString_FromString("AF_SNA"));
+ PyText_FromUTF8("AF_SNA"));
#endif
#ifdef AF_PPPOX
PyModule_AddIntConstant (m, "AF_PPPOX", AF_PPPOX);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_PPPOX),
- PyString_FromString("AF_PPPOX"));
+ PyText_FromUTF8("AF_PPPOX"));
#endif
#ifdef AF_WANPIPE
PyModule_AddIntConstant (m, "AF_WANPIPE", AF_WANPIPE);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_WANPIPE),
- PyString_FromString("AF_WANPIPE"));
+ PyText_FromUTF8("AF_WANPIPE"));
#endif
#ifdef AF_BLUETOOTH
PyModule_AddIntConstant (m, "AF_BLUETOOTH", AF_BLUETOOTH);
PyDict_SetItem(address_family_dict, PyInt_FromLong(AF_BLUETOOTH),
- PyString_FromString("AF_BLUETOOTH"));
+ PyText_FromUTF8("AF_BLUETOOTH"));
#endif
PyModule_AddObject(m, "address_families", address_family_dict);
@@ -1470,4 +1506,20 @@
#define STR(x) _STR(x)
PyModule_AddStringConstant(m, "version", STR(NETIFACES_VERSION));
+
+ return m;
}
+
+#ifdef IS_PY3K
+PyMODINIT_FUNC
+PyInit_netifaces (void)
+{
+ return netifaces_init();
+}
+#else
+PyMODINIT_FUNC
+initnetifaces (void)
+{
+ netifaces_init();
+}
+#endif
Index: netifaces/setup.py
===================================================================
--- netifaces.orig/setup.py 2013-12-13 01:17:20.210600845 +0100
+++ netifaces/setup.py 2013-12-13 01:19:14.242595543 +0100
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
import setuptools
import os
import sys
@@ -7,6 +9,57 @@
from distutils.errors import *
import pickle
+if sys.version_info[0] == 3:
+ import builtins
+ print_ = getattr(builtins, "print")
+ del builtins
+else:
+ def print_(*args, **kwargs):
+ """The new-style print function."""
+ fp = kwargs.pop("file", sys.stdout)
+ if fp is None:
+ return
+ def write(data):
+ if not isinstance(data, basestring):
+ data = str(data)
+ fp.write(data)
+ want_unicode = False
+ sep = kwargs.pop("sep", None)
+ if sep is not None:
+ if isinstance(sep, unicode):
+ want_unicode = True
+ elif not isinstance(sep, str):
+ raise TypeError("sep must be None or a string")
+ end = kwargs.pop("end", None)
+ if end is not None:
+ if isinstance(end, unicode):
+ want_unicode = True
+ elif not isinstance(end, str):
+ raise TypeError("end must be None or a string")
+ if kwargs:
+ raise TypeError("invalid keyword arguments to print()")
+ if not want_unicode:
+ for arg in args:
+ if isinstance(arg, unicode):
+ want_unicode = True
+ break
+ if want_unicode:
+ newline = unicode("\n")
+ space = unicode(" ")
+ else:
+ newline = "\n"
+ space = " "
+ if sep is None:
+ sep = space
+ if end is None:
+ end = newline
+ for i, arg in enumerate(args):
+ if i:
+ write(sep)
+ write(arg)
+ write(end)
+
+
__version__ = "0.8"
# Disable hard links, otherwise building distributions fails on OS X
@@ -47,7 +100,7 @@
if os.path.exists(name):
os.unlink(name)
thefile = open(name, 'w')
- print >>thefile, contents
+ print_(contents, file=thefile)
thefile.close()
sys.stdout.flush()
@@ -97,7 +150,7 @@
# things to test for features is slow
cache_file = os.path.join(self.build_temp, 'config.cache')
if os.path.exists(cache_file):
- myfile = open(cache_file, 'r')
+ myfile = open(cache_file, 'rb')
try:
results = pickle.load(myfile)
finally:
@@ -107,7 +160,7 @@
self.conftestidx = 0
- print "checking for getifaddrs...",
+ print_("checking for getifaddrs...", end=' ')
result = results.get('have_getifaddrs', None)
if result is not None:
@@ -137,14 +190,14 @@
result = False
if result:
- print "found. %s" % cached
+ print("found. %s" % cached)
self.compiler.define_macro('HAVE_GETIFADDRS', 1)
else:
- print "not found. %s" % cached
+ print("not found. %s" % cached)
results['have_getifaddrs'] = result
- print "checking for getnameinfo...",
+ print_("checking for getnameinfo...", end=' ')
result = results.get('have_getnameinfo', None)
if result is not None:
@@ -185,15 +238,15 @@
result = False
if result:
- print "found. %s" % cached
+ print("found. %s" % cached)
self.compiler.define_macro('HAVE_GETNAMEINFO', 1)
else:
- print "not found. %s" % cached
+ print("not found. %s" % cached)
results['have_getnameinfo'] = result
if not results['have_getifaddrs']:
- print "checking for socket IOCTLs...",
+ print_("checking for socket IOCTLs...", end=' ')
result = results.get('have_socket_ioctls', None)
if result is not None:
@@ -249,16 +302,16 @@
result.append(ioctl)
if result:
- print "%r. %s" % (result, cached)
+ print("%r. %s" % (result, cached))
for ioctl in result:
self.compiler.define_macro('HAVE_%s' % ioctl, 1)
self.compiler.define_macro('HAVE_SOCKET_IOCTLS', 1)
else:
- print "not found. %s" % cached
+ print("not found. %s" % cached)
results['have_socket_ioctls'] = result
- print "checking for optional header files...",
+ print_("checking for optional header files...", end=' ')
result = results.get('have_headers', None)
if result is not None:
@@ -288,17 +341,17 @@
result.append(header)
if result:
- print "%s. %s" % (' '.join(result), cached)
+ print("%s. %s" % (' '.join(result), cached))
for header in result:
macro = header.upper().replace('.', '_').replace('/', '_')
self.compiler.define_macro('HAVE_%s' % macro, 1)
else:
- print "none found. %s" % cached
+ print("none found. %s" % cached)
optional_headers = result
results['have_headers'] = result
- print "checking whether struct sockaddr has a length field...",
+ print_("checking whether struct sockaddr has a length field...", end=' ')
result = results.get('have_sockaddr_sa_len', None)
if result is not None:
@@ -321,10 +374,10 @@
result = self.test_build(testrig)
if result:
- print 'yes. %s' % cached
+ print('yes. %s' % cached)
self.compiler.define_macro('HAVE_SOCKADDR_SA_LEN', 1)
else:
- print 'no. %s' % cached
+ print('no. %s' % cached)
results['have_sockaddr_sa_len'] = result
@@ -334,7 +387,7 @@
# however, unfortunately, getifaddrs() doesn't return the
# lengths, because they're in the sa_len field on just about
# everything but Linux.
- print "checking which sockaddr_xxx structs are defined...",
+ print_("checking which sockaddr_xxx structs are defined...", end=' ')
result = results.get('have_sockaddrs', None)
if result is not None:
@@ -374,17 +427,17 @@
result.append(sockaddr)
if result:
- print '%s. %s' % (' '.join(result), cached)
+ print('%s. %s' % (' '.join(result), cached))
for sockaddr in result:
self.compiler.define_macro('HAVE_SOCKADDR_%s' \
% sockaddr.upper(), 1)
else:
- print 'none! %s' % cached
+ print('none! %s' % cached)
results['have_sockaddrs'] = result
# Save the results to our config.cache file
- myfile = open(cache_file, 'w')
+ myfile = open(cache_file, 'wb')
try:
pickle.dump(results, myfile)
finally:
@@ -399,6 +452,9 @@
description="Portable network interface information.",
license="MIT License",
long_description="""\
+(Python 3.x compatibility added by Kevin Kelley <kelleyk@kelleyk.net>.
+The functionality of the module should remain unchanged.)
+
netifaces provides a (hopefully portable-ish) way for Python programmers to
get access to a list of the network interfaces on the local machine, and to
obtain the addresses of those network interfaces.
@@ -414,9 +470,14 @@
author_email='alastair@alastairs-place.net',
url='http://alastairs-place.net/netifaces',
classifiers=[
- 'Development Status :: 4 - Beta',
- 'Intended Audience :: Developers',
- 'License :: OSI Approved :: MIT License',
- 'Topic :: System :: Networking',
- ],
+ 'Development Status :: 4 - Beta',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: MIT License',
+ 'Topic :: System :: Networking',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.2',
+ ],
ext_modules=[iface_mod])
|