Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f47d60f

Browse files
author
Andrew MacIntyre
committed
Create and populate OS/2 EMX port platform specific library directory:
Lib/plat-os2emx/ IN.py SOCKET.py grp.py pwd.py // pwd module that can process real passwd files regen
1 parent f2d7d15 commit f47d60f

5 files changed

Lines changed: 511 additions & 0 deletions

File tree

Lib/plat-os2emx/IN.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Generated by h2py from f:/emx/include/netinet/in.h
2+
3+
# Included from sys/param.h
4+
PAGE_SIZE = 0x1000
5+
HZ = 100
6+
MAXNAMLEN = 260
7+
MAXPATHLEN = 260
8+
def htonl(X): return _swapl(X)
9+
10+
def ntohl(X): return _swapl(X)
11+
12+
def htons(X): return _swaps(X)
13+
14+
def ntohs(X): return _swaps(X)
15+
16+
IPPROTO_IP = 0
17+
IPPROTO_ICMP = 1
18+
IPPROTO_IGMP = 2
19+
IPPROTO_GGP = 3
20+
IPPROTO_TCP = 6
21+
IPPROTO_EGP = 8
22+
IPPROTO_PUP = 12
23+
IPPROTO_UDP = 17
24+
IPPROTO_IDP = 22
25+
IPPROTO_TP = 29
26+
IPPROTO_EON = 80
27+
IPPROTO_RAW = 255
28+
IPPROTO_MAX = 256
29+
IPPORT_RESERVED = 1024
30+
IPPORT_USERRESERVED = 5000
31+
def IN_CLASSA(i): return (((long)(i) & 0x80000000) == 0)
32+
33+
IN_CLASSA_NET = 0xff000000
34+
IN_CLASSA_NSHIFT = 24
35+
IN_CLASSA_HOST = 0x00ffffff
36+
IN_CLASSA_MAX = 128
37+
def IN_CLASSB(i): return (((long)(i) & 0xc0000000) == 0x80000000)
38+
39+
IN_CLASSB_NET = 0xffff0000
40+
IN_CLASSB_NSHIFT = 16
41+
IN_CLASSB_HOST = 0x0000ffff
42+
IN_CLASSB_MAX = 65536
43+
def IN_CLASSC(i): return (((long)(i) & 0xe0000000) == 0xc0000000)
44+
45+
IN_CLASSC_NET = 0xffffff00
46+
IN_CLASSC_NSHIFT = 8
47+
IN_CLASSC_HOST = 0x000000ff
48+
def IN_CLASSD(i): return (((long)(i) & 0xf0000000) == 0xe0000000)
49+
50+
IN_CLASSD_NET = 0xf0000000
51+
IN_CLASSD_NSHIFT = 28
52+
IN_CLASSD_HOST = 0x0fffffff
53+
def IN_MULTICAST(i): return IN_CLASSD(i)
54+
55+
def IN_EXPERIMENTAL(i): return (((long)(i) & 0xe0000000) == 0xe0000000)
56+
57+
def IN_BADCLASS(i): return (((long)(i) & 0xf0000000) == 0xf0000000)
58+
59+
INADDR_ANY = 0x00000000
60+
INADDR_LOOPBACK = 0x7f000001
61+
INADDR_BROADCAST = 0xffffffff
62+
INADDR_NONE = 0xffffffff
63+
INADDR_UNSPEC_GROUP = 0xe0000000
64+
INADDR_ALLHOSTS_GROUP = 0xe0000001
65+
INADDR_MAX_LOCAL_GROUP = 0xe00000ff
66+
IN_LOOPBACKNET = 127
67+
IP_OPTIONS = 1
68+
IP_MULTICAST_IF = 2
69+
IP_MULTICAST_TTL = 3
70+
IP_MULTICAST_LOOP = 4
71+
IP_ADD_MEMBERSHIP = 5
72+
IP_DROP_MEMBERSHIP = 6
73+
IP_HDRINCL = 2
74+
IP_TOS = 3
75+
IP_TTL = 4
76+
IP_RECVOPTS = 5
77+
IP_RECVRETOPTS = 6
78+
IP_RECVDSTADDR = 7
79+
IP_RETOPTS = 8
80+
IP_DEFAULT_MULTICAST_TTL = 1
81+
IP_DEFAULT_MULTICAST_LOOP = 1
82+
IP_MAX_MEMBERSHIPS = 20

Lib/plat-os2emx/SOCKET.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Generated by h2py from f:/emx/include/sys/socket.h
2+
3+
# Included from sys/types.h
4+
FD_SETSIZE = 256
5+
6+
# Included from sys/uio.h
7+
FREAD = 1
8+
FWRITE = 2
9+
SOCK_STREAM = 1
10+
SOCK_DGRAM = 2
11+
SOCK_RAW = 3
12+
SOCK_RDM = 4
13+
SOCK_SEQPACKET = 5
14+
SO_DEBUG = 0x0001
15+
SO_ACCEPTCONN = 0x0002
16+
SO_REUSEADDR = 0x0004
17+
SO_KEEPALIVE = 0x0008
18+
SO_DONTROUTE = 0x0010
19+
SO_BROADCAST = 0x0020
20+
SO_USELOOPBACK = 0x0040
21+
SO_LINGER = 0x0080
22+
SO_OOBINLINE = 0x0100
23+
SO_L_BROADCAST = 0x0200
24+
SO_RCV_SHUTDOWN = 0x0400
25+
SO_SND_SHUTDOWN = 0x0800
26+
SO_SNDBUF = 0x1001
27+
SO_RCVBUF = 0x1002
28+
SO_SNDLOWAT = 0x1003
29+
SO_RCVLOWAT = 0x1004
30+
SO_SNDTIMEO = 0x1005
31+
SO_RCVTIMEO = 0x1006
32+
SO_ERROR = 0x1007
33+
SO_TYPE = 0x1008
34+
SO_OPTIONS = 0x1010
35+
SOL_SOCKET = 0xffff
36+
AF_UNSPEC = 0
37+
AF_UNIX = 1
38+
AF_INET = 2
39+
AF_IMPLINK = 3
40+
AF_PUP = 4
41+
AF_CHAOS = 5
42+
AF_NS = 6
43+
AF_NBS = 7
44+
AF_ISO = 7
45+
AF_OSI = AF_ISO
46+
AF_ECMA = 8
47+
AF_DATAKIT = 9
48+
AF_CCITT = 10
49+
AF_SNA = 11
50+
AF_DECnet = 12
51+
AF_DLI = 13
52+
AF_LAT = 14
53+
AF_HYLINK = 15
54+
AF_APPLETALK = 16
55+
AF_NB = 17
56+
AF_NETBIOS = AF_NB
57+
AF_OS2 = AF_UNIX
58+
AF_MAX = 18
59+
PF_UNSPEC = AF_UNSPEC
60+
PF_UNIX = AF_UNIX
61+
PF_INET = AF_INET
62+
PF_IMPLINK = AF_IMPLINK
63+
PF_PUP = AF_PUP
64+
PF_CHAOS = AF_CHAOS
65+
PF_NS = AF_NS
66+
PF_NBS = AF_NBS
67+
PF_ISO = AF_ISO
68+
PF_OSI = AF_ISO
69+
PF_ECMA = AF_ECMA
70+
PF_DATAKIT = AF_DATAKIT
71+
PF_CCITT = AF_CCITT
72+
PF_SNA = AF_SNA
73+
PF_DECnet = AF_DECnet
74+
PF_DLI = AF_DLI
75+
PF_LAT = AF_LAT
76+
PF_HYLINK = AF_HYLINK
77+
PF_APPLETALK = AF_APPLETALK
78+
PF_NB = AF_NB
79+
PF_NETBIOS = AF_NB
80+
PF_OS2 = AF_UNIX
81+
PF_MAX = AF_MAX
82+
SOMAXCONN = 5
83+
MSG_OOB = 0x1
84+
MSG_PEEK = 0x2
85+
MSG_DONTROUTE = 0x4
86+
MSG_EOR = 0x8
87+
MSG_TRUNC = 0x10
88+
MSG_CTRUNC = 0x20
89+
MSG_WAITALL = 0x40
90+
MSG_MAXIOVLEN = 16
91+
SCM_RIGHTS = 0x01
92+
MT_FREE = 0
93+
MT_DATA = 1
94+
MT_HEADER = 2
95+
MT_SOCKET = 3
96+
MT_PCB = 4
97+
MT_RTABLE = 5
98+
MT_HTABLE = 6
99+
MT_ATABLE = 7
100+
MT_SONAME = 8
101+
MT_ZOMBIE = 9
102+
MT_SOOPTS = 10
103+
MT_FTABLE = 11
104+
MT_RIGHTS = 12
105+
MT_IFADDR = 13
106+
MAXSOCKETS = 2048

Lib/plat-os2emx/grp.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# this module is an OS/2 oriented replacement for the grp standard
2+
# extension module.
3+
4+
# written by Andrew MacIntyre, April 2001.
5+
# released into the public domain "as is", with NO WARRANTY
6+
7+
# note that this implementation checks whether ":" or ";" as used as
8+
# the field separator character.
9+
10+
"""Replacement for grp standard extension module, intended for use on
11+
OS/2 and similar systems which don't normally have an /etc/group file.
12+
13+
The standard Unix group database is an ASCII text file with 4 fields per
14+
record (line), separated by a colon:
15+
- group name (string)
16+
- group password (optional encrypted string)
17+
- group id (integer)
18+
- group members (comma delimited list of userids, with no spaces)
19+
20+
Note that members are only included in the group file for groups that
21+
aren't their primary groups.
22+
(see the section 8.2 of the Python Library Reference)
23+
24+
This implementation differs from the standard Unix implementation by
25+
allowing use of the platform's native path separator character - ';' on OS/2,
26+
DOS and MS-Windows - as the field separator in addition to the Unix
27+
standard ":".
28+
29+
The module looks for the group database at the following locations
30+
(in order first to last):
31+
- ${ETC_GROUP} (or %ETC_GROUP%)
32+
- ${ETC}/group (or %ETC%/group)
33+
- ${PYTHONHOME}/Etc/group (or %PYTHONHOME%/Etc/group)
34+
35+
Classes
36+
-------
37+
38+
None
39+
40+
Functions
41+
---------
42+
43+
getgrgid(gid) - return the record for group-id gid as a 4-tuple
44+
45+
getgrnam(name) - return the record for group 'name' as a 4-tuple
46+
47+
getgrall() - return a list of 4-tuples, each tuple being one record
48+
(NOTE: the order is arbitrary)
49+
50+
Attributes
51+
----------
52+
53+
group_file - the path of the group database file
54+
55+
"""
56+
57+
import os
58+
59+
# try and find the group file
60+
__group_path = []
61+
if os.environ.has_key('ETC_GROUP'):
62+
__group_path.append(os.environ['ETC_GROUP'])
63+
if os.environ.has_key('ETC'):
64+
__group_path.append('%s/group' % os.environ['ETC'])
65+
if os.environ.has_key('PYTHONHOME'):
66+
__group_path.append('%s/Etc/group' % os.environ['PYTHONHOME'])
67+
68+
group_file = None
69+
for __i in __group_path:
70+
try:
71+
__f = open(__i, 'r')
72+
__f.close()
73+
group_file = __i
74+
break
75+
except:
76+
pass
77+
78+
# decide what field separator we can try to use - Unix standard, with
79+
# the platform's path separator as an option. No special field conversion
80+
# handlers are required for the group file.
81+
__field_sep = [':']
82+
if os.pathsep:
83+
if os.pathsep != ':':
84+
__field_sep.append(os.pathsep)
85+
86+
# helper routine to identify which separator character is in use
87+
def __get_field_sep(record):
88+
fs = None
89+
for c in __field_sep:
90+
# there should be 3 delimiter characters (for 4 fields)
91+
if record.count(c) == 3:
92+
fs = c
93+
break
94+
if fs:
95+
return fs
96+
else:
97+
raise KeyError, '>> group database fields not delimited <<'
98+
99+
# read the whole file, parsing each entry into tuple form
100+
# with dictionaries to speed recall by GID or group name
101+
def __read_group_file():
102+
if group_file:
103+
group = open(group_file, 'r')
104+
else:
105+
raise KeyError, '>> no group database <<'
106+
gidx = {}
107+
namx = {}
108+
sep = None
109+
while 1:
110+
entry = group.readline().strip()
111+
if len(entry) > 3:
112+
if sep == None:
113+
sep = __get_field_sep(entry)
114+
fields = entry.split(sep)
115+
fields[2] = int(fields[2])
116+
record = tuple(fields)
117+
if not gidx.has_key(fields[2]):
118+
gidx[fields[2]] = record
119+
if not namx.has_key(fields[0]):
120+
namx[fields[0]] = record
121+
elif len(entry) > 0:
122+
pass # skip empty or malformed records
123+
else:
124+
break
125+
group.close()
126+
if len(gidx) == 0:
127+
raise KeyError
128+
return (gidx, namx)
129+
130+
# return the group database entry by GID
131+
def getgrgid(gid):
132+
g, n = __read_group_file()
133+
return g[gid]
134+
135+
# return the group database entry by group name
136+
def getgrnam(name):
137+
g, n = __read_group_file()
138+
return n[name]
139+
140+
# return all the group database entries
141+
def getgrall():
142+
g, n = __read_group_file()
143+
return g.values()
144+
145+
# test harness
146+
if __name__ == '__main__':
147+
getgrall()

0 commit comments

Comments
 (0)