aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib-python/3/plat-os2emx')
-rw-r--r--lib-python/3/plat-os2emx/IN.py82
-rw-r--r--lib-python/3/plat-os2emx/SOCKET.py106
-rw-r--r--lib-python/3/plat-os2emx/_emx_link.py79
-rw-r--r--lib-python/3/plat-os2emx/grp.py182
-rw-r--r--lib-python/3/plat-os2emx/pwd.py208
-rwxr-xr-xlib-python/3/plat-os2emx/regen7
6 files changed, 664 insertions, 0 deletions
diff --git a/lib-python/3/plat-os2emx/IN.py b/lib-python/3/plat-os2emx/IN.py
new file mode 100644
index 0000000000..753ae24883
--- /dev/null
+++ b/lib-python/3/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 (((int)(i) & 0x80000000) == 0)
+
+IN_CLASSA_NET = 0xff000000
+IN_CLASSA_NSHIFT = 24
+IN_CLASSA_HOST = 0x00ffffff
+IN_CLASSA_MAX = 128
+def IN_CLASSB(i): return (((int)(i) & 0xc0000000) == 0x80000000)
+
+IN_CLASSB_NET = 0xffff0000
+IN_CLASSB_NSHIFT = 16
+IN_CLASSB_HOST = 0x0000ffff
+IN_CLASSB_MAX = 65536
+def IN_CLASSC(i): return (((int)(i) & 0xe0000000) == 0xc0000000)
+
+IN_CLASSC_NET = 0xffffff00
+IN_CLASSC_NSHIFT = 8
+IN_CLASSC_HOST = 0x000000ff
+def IN_CLASSD(i): return (((int)(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 (((int)(i) & 0xe0000000) == 0xe0000000)
+
+def IN_BADCLASS(i): return (((int)(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-python/3/plat-os2emx/SOCKET.py b/lib-python/3/plat-os2emx/SOCKET.py
new file mode 100644
index 0000000000..dac594ad7f
--- /dev/null
+++ b/lib-python/3/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-python/3/plat-os2emx/_emx_link.py b/lib-python/3/plat-os2emx/_emx_link.py
new file mode 100644
index 0000000000..01e6b54c8d
--- /dev/null
+++ b/lib-python/3/plat-os2emx/_emx_link.py
@@ -0,0 +1,79 @@
+# _emx_link.py
+
+# Written by Andrew I MacIntyre, December 2002.
+
+"""_emx_link.py is a simplistic emulation of the Unix link(2) library routine
+for creating so-called hard links. It is intended to be imported into
+the os module in place of the unimplemented (on OS/2) Posix link()
+function (os.link()).
+
+We do this on OS/2 by implementing a file copy, with link(2) semantics:-
+ - the target cannot already exist;
+ - we hope that the actual file open (if successful) is actually
+ atomic...
+
+Limitations of this approach/implementation include:-
+ - no support for correct link counts (EMX stat(target).st_nlink
+ is always 1);
+ - thread safety undefined;
+ - default file permissions (r+w) used, can't be over-ridden;
+ - implemented in Python so comparatively slow, especially for large
+ source files;
+ - need sufficient free disk space to store the copy.
+
+Behaviour:-
+ - any exception should propagate to the caller;
+ - want target to be an exact copy of the source, so use binary mode;
+ - returns None, same as os.link() which is implemented in posixmodule.c;
+ - target removed in the event of a failure where possible;
+ - given the motivation to write this emulation came from trying to
+ support a Unix resource lock implementation, where minimal overhead
+ during creation of the target is desirable and the files are small,
+ we read a source block before attempting to create the target so that
+ we're ready to immediately write some data into it.
+"""
+
+import os
+import errno
+
+__all__ = ['link']
+
+def link(source, target):
+ """link(source, target) -> None
+
+ Attempt to hard link the source file to the target file name.
+ On OS/2, this creates a complete copy of the source file.
+ """
+
+ s = os.open(source, os.O_RDONLY | os.O_BINARY)
+ if os.isatty(s):
+ raise OSError(errno.EXDEV, 'Cross-device link')
+ data = os.read(s, 1024)
+
+ try:
+ t = os.open(target, os.O_WRONLY | os.O_BINARY | os.O_CREAT | os.O_EXCL)
+ except OSError:
+ os.close(s)
+ raise
+
+ try:
+ while data:
+ os.write(t, data)
+ data = os.read(s, 1024)
+ except OSError:
+ os.close(s)
+ os.close(t)
+ os.unlink(target)
+ raise
+
+ os.close(s)
+ os.close(t)
+
+if __name__ == '__main__':
+ import sys
+ try:
+ link(sys.argv[1], sys.argv[2])
+ except IndexError:
+ print('Usage: emx_link <source> <target>')
+ except OSError:
+ print('emx_link: %s' % str(sys.exc_info()[1]))
diff --git a/lib-python/3/plat-os2emx/grp.py b/lib-python/3/plat-os2emx/grp.py
new file mode 100644
index 0000000000..ee63ef8ae2
--- /dev/null
+++ b/lib-python/3/plat-os2emx/grp.py
@@ -0,0 +1,182 @@
+# this module is an OS/2 oriented replacement for the grp standard
+# extension module.
+
+# written by Andrew MacIntyre, April 2001.
+# updated July 2003, adding field accessor support
+
+# 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 'ETC_GROUP' in os.environ:
+ __group_path.append(os.environ['ETC_GROUP'])
+if 'ETC' in os.environ:
+ __group_path.append('%s/group' % os.environ['ETC'])
+if 'PYTHONHOME' in os.environ:
+ __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 <<')
+
+# class to match the new record field name accessors.
+# the resulting object is intended to behave like a read-only tuple,
+# with each member also accessible by a field name.
+class Group:
+ def __init__(self, name, passwd, gid, mem):
+ self.__dict__['gr_name'] = name
+ self.__dict__['gr_passwd'] = passwd
+ self.__dict__['gr_gid'] = gid
+ self.__dict__['gr_mem'] = mem
+ self.__dict__['_record'] = (self.gr_name, self.gr_passwd,
+ self.gr_gid, self.gr_mem)
+
+ def __len__(self):
+ return 4
+
+ def __getitem__(self, key):
+ return self._record[key]
+
+ def __setattr__(self, name, value):
+ raise AttributeError('attribute read-only: %s' % name)
+
+ def __repr__(self):
+ return str(self._record)
+
+ def __cmp__(self, other):
+ this = str(self._record)
+ if this == other:
+ return 0
+ elif this < other:
+ return -1
+ else:
+ return 1
+
+
+# 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 is None:
+ sep = __get_field_sep(entry)
+ fields = entry.split(sep)
+ fields[2] = int(fields[2])
+ fields[3] = [f.strip() for f in fields[3].split(',')]
+ record = Group(*fields)
+ if fields[2] not in gidx:
+ gidx[fields[2]] = record
+ if fields[0] not in namx:
+ 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-python/3/plat-os2emx/pwd.py b/lib-python/3/plat-os2emx/pwd.py
new file mode 100644
index 0000000000..2cb077f5ab
--- /dev/null
+++ b/lib-python/3/plat-os2emx/pwd.py
@@ -0,0 +1,208 @@
+# this module is an OS/2 oriented replacement for the pwd standard
+# extension module.
+
+# written by Andrew MacIntyre, April 2001.
+# updated July 2003, adding field accessor support
+
+# 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 'ETC_PASSWD' in os.environ:
+ __passwd_path.append(os.environ['ETC_PASSWD'])
+if 'ETC' in os.environ:
+ __passwd_path.append('%s/passwd' % os.environ['ETC'])
+if 'PYTHONHOME' in os.environ:
+ __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 <<')
+
+# class to match the new record field name accessors.
+# the resulting object is intended to behave like a read-only tuple,
+# with each member also accessible by a field name.
+class Passwd:
+ def __init__(self, name, passwd, uid, gid, gecos, dir, shell):
+ self.__dict__['pw_name'] = name
+ self.__dict__['pw_passwd'] = passwd
+ self.__dict__['pw_uid'] = uid
+ self.__dict__['pw_gid'] = gid
+ self.__dict__['pw_gecos'] = gecos
+ self.__dict__['pw_dir'] = dir
+ self.__dict__['pw_shell'] = shell
+ self.__dict__['_record'] = (self.pw_name, self.pw_passwd,
+ self.pw_uid, self.pw_gid,
+ self.pw_gecos, self.pw_dir,
+ self.pw_shell)
+
+ def __len__(self):
+ return 7
+
+ def __getitem__(self, key):
+ return self._record[key]
+
+ def __setattr__(self, name, value):
+ raise AttributeError('attribute read-only: %s' % name)
+
+ def __repr__(self):
+ return str(self._record)
+
+ def __cmp__(self, other):
+ this = str(self._record)
+ if this == other:
+ return 0
+ elif this < other:
+ return -1
+ else:
+ return 1
+
+
+# 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 True:
+ entry = passwd.readline().strip()
+ if len(entry) > 6:
+ if sep is 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 = Passwd(*fields)
+ if fields[2] not in uidx:
+ uidx[fields[2]] = record
+ if fields[0] not in namx:
+ 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-python/3/plat-os2emx/regen b/lib-python/3/plat-os2emx/regen
new file mode 100755
index 0000000000..3ecd2a8605
--- /dev/null
+++ b/lib-python/3/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