3 ### Setup for mLib bindings
5 ### (c) 2019 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Python interface to mLib.
12 ### mLib/Python is free software: you can redistribute it and/or modify it
13 ### under the terms of the GNU General Public License as published by the
14 ### Free Software Foundation; either version 2 of the License, or (at your
15 ### option) any later version.
17 ### mLib/Python is distributed in the hope that it will be useful, but
18 ### WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ### General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with mLib/Python. If not, write to the Free Software
24 ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 import types
as _types
30 ###--------------------------------------------------------------------------
31 ### Import the main C extension module.
33 if _sys
.version_info
>= (3,): from . import _base
36 ###--------------------------------------------------------------------------
39 ## Register our module.
40 _base
._ready(_sys
.modules
[__name__
])
41 def default_lostexchook(why
, ty
, val
, tb
):
42 """`mLib.lostexchook(WHY, TY, VAL, TB)' reports lost exceptions."""
43 _sys
.stderr
.write("\n\n!!! LOST EXCEPTION: %s\n" % why
)
44 _sys
.excepthook(ty
, val
, tb
)
45 _sys
.stderr
.write("\n")
46 lostexchook
= default_lostexchook
48 ## For the benefit of the reporter functions, we need the program name.
49 _base
.ego(_sys
.argv
[0])
51 ## Initialize the module.
56 if i
[0] != '_': d
[i
] = b
[i
];
59 ## A handy function for our work: add the methods of a named class to an
60 ## existing class. This is how we write the Python-implemented parts of our
65 if type(a
) is _types
.MethodType
:
67 elif type(a
) not in (_types
.FunctionType
, staticmethod, classmethod):
71 ###--------------------------------------------------------------------------
74 DEFAULT_ATOMTABLE
= AtomTable()
76 if _sys
.version_info
>= (3,):
77 def atoms(): return iter(DEFAULT_ATOMTABLE
.values())
79 def atoms(): return DEFAULT_ATOMTABLE
.itervalues()
82 def __repr__(me
): return "Atom(%r)" % me
.name
86 ###--------------------------------------------------------------------------
87 ### User-interface funtions.
89 def pquis(msg
, file = _sys
.stdout
):
90 "pquis(MSG, [file = sys.stdout]): write MSG, replacing `$' by program name"
91 file.write(msg
.replace("$", quis
))
93 ###----- That's all, folks --------------------------------------------------