Coverage for aiocoap/util/socknumbers.py: 58%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

24 statements  

1# This file is part of the Python aiocoap library project. 

2# 

3# Copyright (c) 2012-2014 Maciej Wasilak <http://sixpinetrees.blogspot.com/>, 

4# 2013-2014 Christian Amsüss <c.amsuess@energyharvesting.at> 

5# 

6# aiocoap is free software, this file is published under the MIT license as 

7# described in the accompanying LICENSE file. 

8 

9"""This module contains numeric constants that would be expected in the socket 

10module, but are not exposed there. 

11 

12This gathers both socket numbers that can be present in the socket module (eg. 

13the PKTINFO constants) but are not in some versions (eg. on macOS before 

14<https://bugs.python.org/issue35569> is fixed) and platform dependent constants 

15that are not generally available at all (the ERR constants). 

16 

17Where available, the CPython-private IN module is used to obtain some platform 

18specific constants. 

19 

20Any hints on where to get them from in a more reliable way are appreciated; 

21possible options are parsing C header files (at build time?) or interacting 

22with shared libraries for obtaining the symbols. The right way would probably 

23be including them in Python in a "other constants defined on this platform for 

24sockets" module or dictionary. 

25""" 

26 

27import sys 

28 

29try: 

30 from socket import IPV6_PKTINFO, IPV6_RECVPKTINFO 

31except ImportError: 

32 if sys.platform == 'linux': 

33 # Not sure if here are any Linux builds at all where this is 

34 # unavailable 

35 IPV6_PKTINFO = 50 

36 IPv6_RECVPKTINFO = 49 

37 elif sys.platform == 'darwin': 

38 # when __APPLE_USE_RFC_3542 is defined / as would be when 

39 # https://bugs.python.org/issue35569 is fixed 

40 IPV6_PKTINFO = 46 

41 IPV6_RECVPKTINFO = 61 

42 # Not attempting to make any guesses for other platforms; the udp6 module 

43 # will fail to import where it needs the specifics 

44 

45try: 

46 from IN import IPV6_RECVERR, IP_RECVERR 

47except ImportError: 

48 if sys.platform == 'linux': 

49 IPV6_RECVERR = 25 

50 IP_RECVERR = 11 

51 

52# for https://bitbucket.org/pypy/pypy/issues/2648/ 

53try: 

54 from socket import MSG_ERRQUEUE 

55except ImportError: 

56 if sys.platform == 'linux': 

57 MSG_ERRQUEUE = 8192 

58 

59HAS_RECVERR = 'IP_RECVERR' in locals() and 'MSG_ERRQUEUE' in locals() 

60"""Indicates whether the discovered constants indicate that the Linux 

61`setsockopt(IPV6, RECVERR)` / `recvmsg(..., MSG_ERRQUEUE)` mechanism is 

62available"""