diff options
author | Andrew MacIntyre <andymac@bullseye.apana.org.au> | 2002-02-22 11:06:30 (GMT) |
---|---|---|
committer | Andrew MacIntyre <andymac@bullseye.apana.org.au> | 2002-02-22 11:06:30 (GMT) |
commit | f47d60ffecd4ef701cbc435effbc44ff9c87a6e4 (patch) | |
tree | 3bb784526b6814a9cfb27440283285132bb584ea /Lib/plat-os2emx | |
parent | f2d7d1580598f413986e7577f38e257fc51f3ce5 (diff) | |
download | cpython-f47d60ffecd4ef701cbc435effbc44ff9c87a6e4.zip cpython-f47d60ffecd4ef701cbc435effbc44ff9c87a6e4.tar.gz cpython-f47d60ffecd4ef701cbc435effbc44ff9c87a6e4.tar.bz2 |
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
Diffstat (limited to 'Lib/plat-os2emx')
-rw-r--r-- | Lib/plat-os2emx/IN.py | 82 | ||||
-rw-r--r-- | Lib/plat-os2emx/SOCKET.py | 106 | ||||
-rw-r--r-- | Lib/plat-os2emx/grp.py | 147 | ||||
-rw-r--r-- | Lib/plat-os2emx/pwd.py | 169 | ||||
-rw-r--r-- | Lib/plat-os2emx/regen | 7 |
5 files changed, 511 insertions, 0 deletions
diff --git a/Lib/plat-os2emx/IN.py b/Lib/plat-os2emx/IN.py new file mode 100644 index 0000000..8b06eb8 --- /dev/null +++ b/Lib/plat-os2emx/IN.py @@ -0,0 +1,82 @@ +# Generated by h2py from f:/emx/include/netinet/in.h + +# Included from sys/param.h +PAGE_SIZE = 0x1000 +HZ = 100 +MAXNAMLEN = 260 +MAXPATHLEN = 260 +def htonl(X): return _swapl(X) + +def ntohl(X): return _swapl(X) + +def htons(X): return _swaps(X) + +def ntohs(X): return _swaps(X) + +IPPROTO_IP = 0 +IPPROTO_ICMP = 1 +IPPROTO_IGMP = 2 +IPPROTO_GGP = 3 +IPPROTO_TCP = 6 +IPPROTO_EGP = 8 +IPPROTO_PUP = 12 +IPPROTO_UDP = 17 +IPPROTO_IDP = 22 +IPPROTO_TP = 29 +IPPROTO_EON = 80 +IPPROTO_RAW = 255 +IPPROTO_MAX = 256 +IPPORT_RESERVED = 1024 +IPPORT_USERRESERVED = 5000 +def IN_CLASSA(i): return (((long)(i) & 0x80000000) == 0) + +IN_CLASSA_NET = 0xff000000 +IN_CLASSA_NSHIFT = 24 +IN_CLASSA_HOST = 0x00ffffff +IN_CLASSA_MAX = 128 +def IN_CLASSB(i): return (((long)(i) & 0xc0000000) == 0x80000000) + +IN_CLASSB_NET = 0xffff0000 +IN_CLASSB_NSHIFT = 16 +IN_CLASSB_HOST = 0x0000ffff +IN_CLASSB_MAX = 65536 +def IN_CLASSC(i): return (((long)(i) & 0xe0000000) == 0xc0000000) + +IN_CLASSC_NET = 0xffffff00 +IN_CLASSC_NSHIFT = 8 +IN_CLASSC_HOST = 0x000000ff +def IN_CLASSD(i): return (((long)(i) & 0xf0000000) == 0xe0000000) + +IN_CLASSD_NET = 0xf0000000 +IN_CLASSD_NSHIFT = 28 +IN_CLASSD_HOST = 0x0fffffff +def IN_MULTICAST(i): return IN_CLASSD(i) + +def IN_EXPERIMENTAL(i): return (((long)(i) & 0xe0000000) == 0xe0000000) + +def IN_BADCLASS(i): return (((long)(i) & 0xf0000000) == 0xf0000000) + +INADDR_ANY = 0x00000000 +INADDR_LOOPBACK = 0x7f000001 +INADDR_BROADCAST = 0xffffffff +INADDR_NONE = 0xffffffff +INADDR_UNSPEC_GROUP = 0xe0000000 +INADDR_ALLHOSTS_GROUP = 0xe0000001 +INADDR_MAX_LOCAL_GROUP = 0xe00000ff +IN_LOOPBACKNET = 127 +IP_OPTIONS = 1 +IP_MULTICAST_IF = 2 +IP_MULTICAST_TTL = 3 +IP_MULTICAST_LOOP = 4 +IP_ADD_MEMBERSHIP = 5 +IP_DROP_MEMBERSHIP = 6 +IP_HDRINCL = 2 +IP_TOS = 3 +IP_TTL = 4 +IP_RECVOPTS = 5 +IP_RECVRETOPTS = 6 +IP_RECVDSTADDR = 7 +IP_RETOPTS = 8 +IP_DEFAULT_MULTICAST_TTL = 1 +IP_DEFAULT_MULTICAST_LOOP = 1 +IP_MAX_MEMBERSHIPS = 20 diff --git a/Lib/plat-os2emx/SOCKET.py b/Lib/plat-os2emx/SOCKET.py new file mode 100644 index 0000000..dac594a --- /dev/null +++ b/Lib/plat-os2emx/SOCKET.py @@ -0,0 +1,106 @@ +# Generated by h2py from f:/emx/include/sys/socket.h + +# Included from sys/types.h +FD_SETSIZE = 256 + +# Included from sys/uio.h +FREAD = 1 +FWRITE = 2 +SOCK_STREAM = 1 +SOCK_DGRAM = 2 +SOCK_RAW = 3 +SOCK_RDM = 4 +SOCK_SEQPACKET = 5 +SO_DEBUG = 0x0001 +SO_ACCEPTCONN = 0x0002 +SO_REUSEADDR = 0x0004 +SO_KEEPALIVE = 0x0008 +SO_DONTROUTE = 0x0010 +SO_BROADCAST = 0x0020 +SO_USELOOPBACK = 0x0040 +SO_LINGER = 0x0080 +SO_OOBINLINE = 0x0100 +SO_L_BROADCAST = 0x0200 +SO_RCV_SHUTDOWN = 0x0400 +SO_SND_SHUTDOWN = 0x0800 +SO_SNDBUF = 0x1001 +SO_RCVBUF = 0x1002 +SO_SNDLOWAT = 0x1003 +SO_RCVLOWAT = 0x1004 +SO_SNDTIMEO = 0x1005 +SO_RCVTIMEO = 0x1006 +SO_ERROR = 0x1007 +SO_TYPE = 0x1008 +SO_OPTIONS = 0x1010 +SOL_SOCKET = 0xffff +AF_UNSPEC = 0 +AF_UNIX = 1 +AF_INET = 2 +AF_IMPLINK = 3 +AF_PUP = 4 +AF_CHAOS = 5 +AF_NS = 6 +AF_NBS = 7 +AF_ISO = 7 +AF_OSI = AF_ISO +AF_ECMA = 8 +AF_DATAKIT = 9 +AF_CCITT = 10 +AF_SNA = 11 +AF_DECnet = 12 +AF_DLI = 13 +AF_LAT = 14 +AF_HYLINK = 15 +AF_APPLETALK = 16 +AF_NB = 17 +AF_NETBIOS = AF_NB +AF_OS2 = AF_UNIX +AF_MAX = 18 +PF_UNSPEC = AF_UNSPEC +PF_UNIX = AF_UNIX +PF_INET = AF_INET +PF_IMPLINK = AF_IMPLINK +PF_PUP = AF_PUP +PF_CHAOS = AF_CHAOS +PF_NS = AF_NS +PF_NBS = AF_NBS +PF_ISO = AF_ISO +PF_OSI = AF_ISO +PF_ECMA = AF_ECMA +PF_DATAKIT = AF_DATAKIT +PF_CCITT = AF_CCITT +PF_SNA = AF_SNA +PF_DECnet = AF_DECnet +PF_DLI = AF_DLI +PF_LAT = AF_LAT +PF_HYLINK = AF_HYLINK +PF_APPLETALK = AF_APPLETALK +PF_NB = AF_NB +PF_NETBIOS = AF_NB +PF_OS2 = AF_UNIX +PF_MAX = AF_MAX +SOMAXCONN = 5 +MSG_OOB = 0x1 +MSG_PEEK = 0x2 +MSG_DONTROUTE = 0x4 +MSG_EOR = 0x8 +MSG_TRUNC = 0x10 +MSG_CTRUNC = 0x20 +MSG_WAITALL = 0x40 +MSG_MAXIOVLEN = 16 +SCM_RIGHTS = 0x01 +MT_FREE = 0 +MT_DATA = 1 +MT_HEADER = 2 +MT_SOCKET = 3 +MT_PCB = 4 +MT_RTABLE = 5 +MT_HTABLE = 6 +MT_ATABLE = 7 +MT_SONAME = 8 +MT_ZOMBIE = 9 +MT_SOOPTS = 10 +MT_FTABLE = 11 +MT_RIGHTS = 12 +MT_IFADDR = 13 +MAXSOCKETS = 2048 diff --git a/Lib/plat-os2emx/grp.py b/Lib/plat-os2emx/grp.py new file mode 100644 index 0000000..228f4c1 --- /dev/null +++ b/Lib/plat-os2emx/grp.py @@ -0,0 +1,147 @@ +# this module is an OS/2 oriented replacement for the grp standard +# extension module. + +# written by Andrew MacIntyre, April 2001. +# released into the public domain "as is", with NO WARRANTY + +# note that this implementation checks whether ":" or ";" as used as +# the field separator character. + +"""Replacement for grp standard extension module, intended for use on +OS/2 and similar systems which don't normally have an /etc/group file. + +The standard Unix group database is an ASCII text file with 4 fields per +record (line), separated by a colon: + - group name (string) + - group password (optional encrypted string) + - group id (integer) + - group members (comma delimited list of userids, with no spaces) + +Note that members are only included in the group file for groups that +aren't their primary groups. +(see the section 8.2 of the Python Library Reference) + +This implementation differs from the standard Unix implementation by +allowing use of the platform's native path separator character - ';' on OS/2, +DOS and MS-Windows - as the field separator in addition to the Unix +standard ":". + +The module looks for the group database at the following locations +(in order first to last): + - ${ETC_GROUP} (or %ETC_GROUP%) + - ${ETC}/group (or %ETC%/group) + - ${PYTHONHOME}/Etc/group (or %PYTHONHOME%/Etc/group) + +Classes +------- + +None + +Functions +--------- + +getgrgid(gid) - return the record for group-id gid as a 4-tuple + +getgrnam(name) - return the record for group 'name' as a 4-tuple + +getgrall() - return a list of 4-tuples, each tuple being one record + (NOTE: the order is arbitrary) + +Attributes +---------- + +group_file - the path of the group database file + +""" + +import os + +# try and find the group file +__group_path = [] +if os.environ.has_key('ETC_GROUP'): + __group_path.append(os.environ['ETC_GROUP']) +if os.environ.has_key('ETC'): + __group_path.append('%s/group' % os.environ['ETC']) +if os.environ.has_key('PYTHONHOME'): + __group_path.append('%s/Etc/group' % os.environ['PYTHONHOME']) + +group_file = None +for __i in __group_path: + try: + __f = open(__i, 'r') + __f.close() + group_file = __i + break + except: + pass + +# decide what field separator we can try to use - Unix standard, with +# the platform's path separator as an option. No special field conversion +# handlers are required for the group file. +__field_sep = [':'] +if os.pathsep: + if os.pathsep != ':': + __field_sep.append(os.pathsep) + +# helper routine to identify which separator character is in use +def __get_field_sep(record): + fs = None + for c in __field_sep: + # there should be 3 delimiter characters (for 4 fields) + if record.count(c) == 3: + fs = c + break + if fs: + return fs + else: + raise KeyError, '>> group database fields not delimited <<' + +# read the whole file, parsing each entry into tuple form +# with dictionaries to speed recall by GID or group name +def __read_group_file(): + if group_file: + group = open(group_file, 'r') + else: + raise KeyError, '>> no group database <<' + gidx = {} + namx = {} + sep = None + while 1: + entry = group.readline().strip() + if len(entry) > 3: + if sep == None: + sep = __get_field_sep(entry) + fields = entry.split(sep) + fields[2] = int(fields[2]) + record = tuple(fields) + if not gidx.has_key(fields[2]): + gidx[fields[2]] = record + if not namx.has_key(fields[0]): + namx[fields[0]] = record + elif len(entry) > 0: + pass # skip empty or malformed records + else: + break + group.close() + if len(gidx) == 0: + raise KeyError + return (gidx, namx) + +# return the group database entry by GID +def getgrgid(gid): + g, n = __read_group_file() + return g[gid] + +# return the group database entry by group name +def getgrnam(name): + g, n = __read_group_file() + return n[name] + +# return all the group database entries +def getgrall(): + g, n = __read_group_file() + return g.values() + +# test harness +if __name__ == '__main__': + getgrall() diff --git a/Lib/plat-os2emx/pwd.py b/Lib/plat-os2emx/pwd.py new file mode 100644 index 0000000..6e2b008 --- /dev/null +++ b/Lib/plat-os2emx/pwd.py @@ -0,0 +1,169 @@ +# this module is an OS/2 oriented replacement for the pwd standard +# extension module. + +# written by Andrew MacIntyre, April 2001. +# released into the public domain "as is", with NO WARRANTY + +# note that this implementation checks whether ":" or ";" as used as +# the field separator character. Path conversions are are applied when +# the database uses ":" as the field separator character. + +"""Replacement for pwd standard extension module, intended for use on +OS/2 and similar systems which don't normally have an /etc/passwd file. + +The standard Unix password database is an ASCII text file with 7 fields +per record (line), separated by a colon: + - user name (string) + - password (encrypted string, or "*" or "") + - user id (integer) + - group id (integer) + - description (usually user's name) + - home directory (path to user's home directory) + - shell (path to the user's login shell) + +(see the section 8.1 of the Python Library Reference) + +This implementation differs from the standard Unix implementation by +allowing use of the platform's native path separator character - ';' on OS/2, +DOS and MS-Windows - as the field separator in addition to the Unix +standard ":". Additionally, when ":" is the separator path conversions +are applied to deal with any munging of the drive letter reference. + +The module looks for the password database at the following locations +(in order first to last): + - ${ETC_PASSWD} (or %ETC_PASSWD%) + - ${ETC}/passwd (or %ETC%/passwd) + - ${PYTHONHOME}/Etc/passwd (or %PYTHONHOME%/Etc/passwd) + +Classes +------- + +None + +Functions +--------- + +getpwuid(uid) - return the record for user-id uid as a 7-tuple + +getpwnam(name) - return the record for user 'name' as a 7-tuple + +getpwall() - return a list of 7-tuples, each tuple being one record + (NOTE: the order is arbitrary) + +Attributes +---------- + +passwd_file - the path of the password database file + +""" + +import os + +# try and find the passwd file +__passwd_path = [] +if os.environ.has_key('ETC_PASSWD'): + __passwd_path.append(os.environ['ETC_PASSWD']) +if os.environ.has_key('ETC'): + __passwd_path.append('%s/passwd' % os.environ['ETC']) +if os.environ.has_key('PYTHONHOME'): + __passwd_path.append('%s/Etc/passwd' % os.environ['PYTHONHOME']) + +passwd_file = None +for __i in __passwd_path: + try: + __f = open(__i, 'r') + __f.close() + passwd_file = __i + break + except: + pass + +# path conversion handlers +def __nullpathconv(path): + return path.replace(os.altsep, os.sep) + +def __unixpathconv(path): + # two known drive letter variations: "x;" and "$x" + if path[0] == '$': + conv = path[1] + ':' + path[2:] + elif path[1] == ';': + conv = path[0] + ':' + path[2:] + else: + conv = path + return conv.replace(os.altsep, os.sep) + +# decide what field separator we can try to use - Unix standard, with +# the platform's path separator as an option. No special field conversion +# handler is required when using the platform's path separator as field +# separator, but are required for the home directory and shell fields when +# using the standard Unix (":") field separator. +__field_sep = {':': __unixpathconv} +if os.pathsep: + if os.pathsep != ':': + __field_sep[os.pathsep] = __nullpathconv + +# helper routine to identify which separator character is in use +def __get_field_sep(record): + fs = None + for c in __field_sep.keys(): + # there should be 6 delimiter characters (for 7 fields) + if record.count(c) == 6: + fs = c + break + if fs: + return fs + else: + raise KeyError, '>> passwd database fields not delimited <<' + +# read the whole file, parsing each entry into tuple form +# with dictionaries to speed recall by UID or passwd name +def __read_passwd_file(): + if passwd_file: + passwd = open(passwd_file, 'r') + else: + raise KeyError, '>> no password database <<' + uidx = {} + namx = {} + sep = None + while 1: + entry = passwd.readline().strip() + if len(entry) > 6: + if sep == None: + sep = __get_field_sep(entry) + fields = entry.split(sep) + for i in (2, 3): + fields[i] = int(fields[i]) + for i in (5, 6): + fields[i] = __field_sep[sep](fields[i]) + record = tuple(fields) + if not uidx.has_key(fields[2]): + uidx[fields[2]] = record + if not namx.has_key(fields[0]): + namx[fields[0]] = record + elif len(entry) > 0: + pass # skip empty or malformed records + else: + break + passwd.close() + if len(uidx) == 0: + raise KeyError + return (uidx, namx) + +# return the passwd database entry by UID +def getpwuid(uid): + u, n = __read_passwd_file() + return u[uid] + +# return the passwd database entry by passwd name +def getpwnam(name): + u, n = __read_passwd_file() + return n[name] + +# return all the passwd database entries +def getpwall(): + u, n = __read_passwd_file() + return n.values() + +# test harness +if __name__ == '__main__': + getpwall() diff --git a/Lib/plat-os2emx/regen b/Lib/plat-os2emx/regen new file mode 100644 index 0000000..3ecd2a8 --- /dev/null +++ b/Lib/plat-os2emx/regen @@ -0,0 +1,7 @@ +#! /bin/sh +export INCLUDE=$C_INCLUDE_PATH +set -v +python.exe ../../Tools/scripts/h2py.py $C_INCLUDE_PATH/fcntl.h +python.exe ../../Tools/scripts/h2py.py $C_INCLUDE_PATH/sys/socket.h +python.exe ../../Tools/scripts/h2py.py -i '(u_long)' $C_INCLUDE_PATH/netinet/in.h +#python.exe ../../Tools/scripts/h2py.py $C_INCLUDE_PATH/termios.h |