diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-03-21 22:36:19 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-03-21 22:36:19 (GMT) |
commit | 2614cda20910e1b2529d5af4a95327f8cdfcc35a (patch) | |
tree | 4a2d95569150aa2b6f81eb8ea921eac67afa2bf8 | |
parent | b5023a1433c4afbf2460a6433593769d1d99bee5 (diff) | |
download | cpython-2614cda20910e1b2529d5af4a95327f8cdfcc35a.zip cpython-2614cda20910e1b2529d5af4a95327f8cdfcc35a.tar.gz cpython-2614cda20910e1b2529d5af4a95327f8cdfcc35a.tar.bz2 |
Merged revisions 78338,78345-78346,78561-78562,78566,78574,78581,78634,78660,78675 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78338 | andrew.kuchling | 2010-02-22 15:04:02 -0600 (Mon, 22 Feb 2010) | 4 lines
Remove Tools/modulator, a reference to it in the docs, and a screenshot of it.
(I asked the BDFL first, and he approved removing it. The last actual bugfix
to Tools/modulator was in 2001; since then all changes have been search-and-replace:
string methods, whitespace fixes, etc.)
........
r78345 | andrew.kuchling | 2010-02-22 17:10:52 -0600 (Mon, 22 Feb 2010) | 1 line
#7706: DONT_HAVE_ERRNO_H is no longer defined by configure (after rev.46819).
........
r78346 | andrew.kuchling | 2010-02-22 17:12:00 -0600 (Mon, 22 Feb 2010) | 1 line
#7706: add include guards where they're missing; required for Windows CE
........
r78561 | andrew.kuchling | 2010-03-01 13:51:43 -0600 (Mon, 01 Mar 2010) | 1 line
#7191: describe more details of wbits parameter
........
r78562 | andrew.kuchling | 2010-03-01 14:11:57 -0600 (Mon, 01 Mar 2010) | 1 line
#7637: avoid repeated-concatenation antipattern in example
........
r78566 | barry.warsaw | 2010-03-01 15:46:51 -0600 (Mon, 01 Mar 2010) | 4 lines
Manually copy patch for bug 7250 from the release26-maint branch. I suck
because I did this in the wrong order and couldn't smack svnmerge into
submission.
........
r78574 | benjamin.peterson | 2010-03-01 17:25:13 -0600 (Mon, 01 Mar 2010) | 1 line
remove CVS id
........
r78581 | michael.foord | 2010-03-02 08:22:15 -0600 (Tue, 02 Mar 2010) | 1 line
Link correction in documentation.
........
r78634 | benjamin.peterson | 2010-03-03 15:28:25 -0600 (Wed, 03 Mar 2010) | 1 line
rephrase
........
r78660 | dirkjan.ochtman | 2010-03-04 13:21:53 -0600 (Thu, 04 Mar 2010) | 4 lines
Try to fix buildbot breakage from r78384.
Thanks bitdancer and briancurtin for the help.
........
r78675 | florent.xicluna | 2010-03-04 19:12:14 -0600 (Thu, 04 Mar 2010) | 2 lines
These line should not be there.
........
38 files changed, 24 insertions, 1459 deletions
diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst index edc2c8c..d5f55c7 100644 --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -381,12 +381,7 @@ source distribution. A more substantial example module is included in the Python source distribution as :file:`Modules/xxmodule.c`. This file may be used as a template or simply -read as an example. The :program:`modulator.py` script included in the source -distribution or Windows install provides a simple graphical user interface for -declaring the functions and objects which a module should implement, and can -generate a template which can be filled in. The script lives in the -:file:`Tools/modulator/` directory; see the :file:`README` file there for more -information. +read as an example. .. _compilation: diff --git a/Doc/includes/minidom-example.py b/Doc/includes/minidom-example.py index 88048c0..5ee7682 100644 --- a/Doc/includes/minidom-example.py +++ b/Doc/includes/minidom-example.py @@ -19,11 +19,11 @@ document = """\ dom = xml.dom.minidom.parseString(document) def getText(nodelist): - rc = "" + rc = [] for node in nodelist: if node.nodeType == node.TEXT_NODE: - rc = rc + node.data - return rc + rc.append(node.data) + return ''.join(rc) def handleSlideshow(slideshow): print("<html>") diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 53d86a0..0515688 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -67,7 +67,7 @@ The following sections walk you through this example. Creating a parser ^^^^^^^^^^^^^^^^^ -Mose uses of the :mod:`argparse` module will start out by creating an +The first step in using the :mod:`argparse` is creating an :class:`ArgumentParser` object:: >>> parser = argparse.ArgumentParser(description='Process some integers.') diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index 8225efb..ad6a641 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -90,7 +90,7 @@ This example uses the iterator form:: .. seealso:: - http://www.pysqlite.org + http://code.google.com/p/pysqlite/ The pysqlite web page -- sqlite3 is developed externally under the name "pysqlite". diff --git a/Doc/library/zlib.rst b/Doc/library/zlib.rst index 4bd8019..44e9edb 100644 --- a/Doc/library/zlib.rst +++ b/Doc/library/zlib.rst @@ -96,14 +96,18 @@ The available exception and functions in this module are: Decompresses the data in *string*, returning a string containing the uncompressed data. The *wbits* parameter controls the size of the window - buffer. If *bufsize* is given, it is used as the initial size of the output + buffer, and is discussed further below. + If *bufsize* is given, it is used as the initial size of the output buffer. Raises the :exc:`error` exception if any error occurs. The absolute value of *wbits* is the base two logarithm of the size of the history buffer (the "window size") used when compressing data. Its absolute value should be between 8 and 15 for the most recent versions of the zlib library, larger values resulting in better compression at the expense of greater - memory usage. The default value is 15. When *wbits* is negative, the standard + memory usage. When decompressing a stream, *wbits* must not be smaller + than the size originally used to compress the stream; using a too-small + value will result in an exception. The default value is therefore the + highest value, 15. When *wbits* is negative, the standard :program:`gzip` header is suppressed; this is an undocumented feature of the zlib library, used for compatibility with :program:`unzip`'s compression file format. diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 708af0a..3564a57 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -31,8 +31,6 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* CVS: $Id$ */ - /* A number of SysV or ncurses functions don't have wrappers yet; if you diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index a785e79..8b876d1 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -2,9 +2,15 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#ifdef HAVE_SYS_TYPES_H #include <sys/types.h> +#endif +#ifdef HAVE_SYS_STAT_H #include <sys/stat.h> +#endif +#ifdef HAVE_FCNTL_H #include <fcntl.h> +#endif #include <stddef.h> /* For offsetof */ #include "_iomodule.h" diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 5d053f0..13806c7 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -7,12 +7,17 @@ #include "intrcheck.h" #ifdef MS_WINDOWS +#ifdef HAVE_PROCESS_H #include <process.h> #endif +#endif +#ifdef HAVE_SIGNAL_H #include <signal.h> - +#endif +#ifdef HAVE_SYS_STAT_H #include <sys/stat.h> +#endif #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #endif diff --git a/Tools/README b/Tools/README index db6e370..8cde228 100644 --- a/Tools/README +++ b/Tools/README @@ -21,9 +21,6 @@ i18n Tools for internationalization. pygettext.py and msgfmt.py generates a binary message catalog from a catalog in text format. -modulator Interactively generate boiler plate for an extension - module. Works easiest if you have Tk. - pynche A Tkinter-based color editor. scripts A number of useful single-file programs, e.g. tabnanny.py diff --git a/Tools/modulator/EXAMPLE.py b/Tools/modulator/EXAMPLE.py deleted file mode 100644 index b36a5a7..0000000 --- a/Tools/modulator/EXAMPLE.py +++ /dev/null @@ -1,53 +0,0 @@ -# -# Example input file for modulator if you don't have tk. -# -# You may also have to strip some imports out of modulator to make -# it work. - -import genmodule - -# -# Generate code for a simple object with a method called sample - -o = genmodule.object() -o.name = 'simple object' -o.abbrev = 'simp' -o.methodlist = ['sample'] -o.funclist = ['new'] - -# -# Generate code for an object that looks numberish -# -o2 = genmodule.object() -o2.name = 'number-like object' -o2.abbrev = 'nl' -o2.typelist = ['tp_as_number'] -o2.funclist = ['new', 'tp_repr', 'tp_compare'] - -# -# Generate code for a method with a full complement of functions, -# some methods, accessible as sequence and allowing structmember.c type -# structure access as well. -# -o3 = genmodule.object() -o3.name = 'over-the-top object' -o3.abbrev = 'ot' -o3.methodlist = ['method1', 'method2'] -o3.funclist = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr', - 'tp_compare', 'tp_repr', 'tp_hash'] -o3.typelist = ['tp_as_sequence', 'structure'] - -# -# Now generate code for a module that incorporates these object types. -# Also add the boilerplates for functions to create instances of each -# type. -# -m = genmodule.module() -m.name = 'sample' -m.abbrev = 'sample' -m.methodlist = ['newsimple', 'newnumberish', 'newott'] -m.objects = [o, o2, o3] - -fp = open('EXAMPLEmodule.c', 'w') -genmodule.write(fp, m) -fp.close() diff --git a/Tools/modulator/README b/Tools/modulator/README deleted file mode 100644 index aae86b4..0000000 --- a/Tools/modulator/README +++ /dev/null @@ -1,25 +0,0 @@ -This is release 1.2 of modulator, a generator of boilerplate code for -modules to be written in C. - -Difference between 1.2 and 1.1: __doc__ templates are now generated -(thanks to Jim Fulton). - -Difference between 1.1 and 1.0: the templates now use "new-style" -naming conventions. Many thanks to Chak Tan <tan@ee.rochester.edu> for -supplying them. - -Usage when you have tk is *really* simple: start modulator, fill out -the forms specifying all the objects and methods, tell modulator -whether objects should also be accessible as sequences, etc and press -'generate code'. It will write a complete skeleton module for you. - -Usage when you don't have tk is slightly more difficult. Look at -EXAMPLE.py for some details (to run, use "python EXAMPLE.py"). Don't -bother with EXAMPLE.py if you have Tkinter!!! - -Oh yeah: you'll probably want to change Templates/copyright, or all -your code ends up as being copyrighted to CWI:-) - -Let me know what you think, - Jack Jansen, jack@cwi.nl - diff --git a/Tools/modulator/ScrolledListbox.py b/Tools/modulator/ScrolledListbox.py deleted file mode 100644 index 2ec646d..0000000 --- a/Tools/modulator/ScrolledListbox.py +++ /dev/null @@ -1,37 +0,0 @@ -# A ScrolledList widget feels like a list widget but also has a -# vertical scroll bar on its right. (Later, options may be added to -# add a horizontal bar as well, to make the bars disappear -# automatically when not needed, to move them to the other side of the -# window, etc.) -# -# Configuration options are passed to the List widget. -# A Frame widget is inserted between the master and the list, to hold -# the Scrollbar widget. -# Most methods calls are inherited from the List widget; Pack methods -# are redirected to the Frame widget however. - -from Tkinter import * -from Tkinter import _cnfmerge - -class ScrolledListbox(Listbox): - def __init__(self, master=None, cnf={}): - cnf = _cnfmerge(cnf) - fcnf = {} - vcnf = {'name': 'vbar', - Pack: {'side': 'right', 'fill': 'y'},} - for k in list(cnf.keys()): - if type(k) == ClassType or k == 'name': - fcnf[k] = cnf[k] - del cnf[k] - self.frame = Frame(master, fcnf) - self.vbar = Scrollbar(self.frame, vcnf) - cnf[Pack] = {'side': 'left', 'fill': 'both', 'expand': 'yes'} - cnf['name'] = 'list' - Listbox.__init__(self, self.frame, cnf) - self['yscrollcommand'] = (self.vbar, 'set') - self.vbar['command'] = (self, 'yview') - - # Copy Pack methods of self.frame -- hack! - for m in Pack.__dict__: - if m[0] != '_' and m != 'config': - setattr(self, m, getattr(self.frame, m)) diff --git a/Tools/modulator/Templates/copyright b/Tools/modulator/Templates/copyright deleted file mode 100644 index e69de29..0000000 --- a/Tools/modulator/Templates/copyright +++ /dev/null diff --git a/Tools/modulator/Templates/module_head b/Tools/modulator/Templates/module_head deleted file mode 100644 index be00109..0000000 --- a/Tools/modulator/Templates/module_head +++ /dev/null @@ -1,6 +0,0 @@ - -#include "Python.h" - -static PyObject *ErrorObject; - -/* ----------------------------------------------------- */ diff --git a/Tools/modulator/Templates/module_method b/Tools/modulator/Templates/module_method deleted file mode 100644 index 3048b1f..0000000 --- a/Tools/modulator/Templates/module_method +++ /dev/null @@ -1,14 +0,0 @@ - -static char $abbrev$_$method$__doc__[] = -"" -; - -static PyObject * -$abbrev$_$method$(PyObject *self /* Not used */, PyObject *args) -{ - - if (!PyArg_ParseTuple(args, "")) - return NULL; - Py_INCREF(Py_None); - return Py_None; -} diff --git a/Tools/modulator/Templates/module_tail b/Tools/modulator/Templates/module_tail deleted file mode 100644 index 59cc50b..0000000 --- a/Tools/modulator/Templates/module_tail +++ /dev/null @@ -1,37 +0,0 @@ - -/* List of methods defined in the module */ - -static struct PyMethodDef $abbrev$_methods[] = { - $methodlist$ - {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ -}; - - -/* Initialization function for the module (*must* be called init$name$) */ - -static char $name$_module_documentation[] = -"" -; - -void -init$name$() -{ - PyObject *m, *d; - - /* Create the module and add the functions */ - m = Py_InitModule4("$name$", $abbrev$_methods, - $name$_module_documentation, - (PyObject*)NULL,PYTHON_API_VERSION); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyString_FromString("$name$.error"); - PyDict_SetItemString(d, "error", ErrorObject); - - /* XXXX Add constants here */ - - /* Check for errors */ - if (PyErr_Occurred()) - Py_FatalError("can't initialize module $name$"); -} - diff --git a/Tools/modulator/Templates/object_head b/Tools/modulator/Templates/object_head deleted file mode 100644 index 07d1f6a..0000000 --- a/Tools/modulator/Templates/object_head +++ /dev/null @@ -1,13 +0,0 @@ - -/* Declarations for objects of type $name$ */ - -typedef struct { - PyObject_HEAD - /* XXXX Add your own stuff here */ -} $abbrev$object; - -static PyTypeObject $Abbrev$type; - - - -/* ---------------------------------------------------------------- */ diff --git a/Tools/modulator/Templates/object_method b/Tools/modulator/Templates/object_method deleted file mode 100644 index b15162c..0000000 --- a/Tools/modulator/Templates/object_method +++ /dev/null @@ -1,14 +0,0 @@ - -static char $abbrev$_$method$__doc__[] = -"" -; - -static PyObject * -$abbrev$_$method$($abbrev$object *self, PyObject *args) -{ - if (!PyArg_ParseTuple(args, "")) - return NULL; - Py_INCREF(Py_None); - return Py_None; -} - diff --git a/Tools/modulator/Templates/object_mlist b/Tools/modulator/Templates/object_mlist deleted file mode 100644 index a12a9e1..0000000 --- a/Tools/modulator/Templates/object_mlist +++ /dev/null @@ -1,8 +0,0 @@ - -static struct PyMethodDef $abbrev$_methods[] = { - $methodlist$ - {NULL, NULL} /* sentinel */ -}; - -/* ---------- */ - diff --git a/Tools/modulator/Templates/object_new b/Tools/modulator/Templates/object_new deleted file mode 100644 index 30c5e36..0000000 --- a/Tools/modulator/Templates/object_new +++ /dev/null @@ -1,13 +0,0 @@ - -static $abbrev$object * -new$abbrev$object() -{ - $abbrev$object *self; - - self = PyObject_NEW($abbrev$object, &$Abbrev$type); - if (self == NULL) - return NULL; - /* XXXX Add your own initializers here */ - return self; -} - diff --git a/Tools/modulator/Templates/object_structure b/Tools/modulator/Templates/object_structure deleted file mode 100644 index 78daa62..0000000 --- a/Tools/modulator/Templates/object_structure +++ /dev/null @@ -1,37 +0,0 @@ - -/* Code to access structure members by accessing attributes */ - -#include "structmember.h" - -#define OFF(x) offsetof(XXXXobject, x) - -static PyMemberDef $abbrev$_memberlist[] = { - /* XXXX Add lines like { "foo", T_INT, OFF(foo), READONLY } */ - - {NULL} /* Sentinel */ -}; - -static PyObject * -$abbrev$_getattr($abbrev$object *self, char *name) -{ - PyObject *rv; - - /* XXXX Add your own getattr code here */ - rv = PyMember_GetOne((char *)/*XXXX*/0, &$abbrev$_memberlist[i]); - if (rv) - return rv; - PyErr_Clear(); - return Py_FindMethod($abbrev$_methods, (PyObject *)self, name); -} - - -static int -$abbrev$_setattr($abbrev$object *self, char *name, PyObject *v) -{ - /* XXXX Add your own setattr code here */ - if ( v == NULL ) { - PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute"); - return -1; - } - return PyMember_SetOne((char *)/*XXXX*/0, &$abbrev$_memberlist[i], v); -} diff --git a/Tools/modulator/Templates/object_tail b/Tools/modulator/Templates/object_tail deleted file mode 100644 index 1d1334c..0000000 --- a/Tools/modulator/Templates/object_tail +++ /dev/null @@ -1,33 +0,0 @@ - -static char $Abbrev$type__doc__[] = -"" -; - -static PyTypeObject $Abbrev$type = { - PyObject_HEAD_INIT(&PyType_Type) - 0, /*ob_size*/ - "$name$", /*tp_name*/ - sizeof($abbrev$object), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)$tp_dealloc$, /*tp_dealloc*/ - (printfunc)$tp_print$, /*tp_print*/ - (getattrfunc)$tp_getattr$, /*tp_getattr*/ - (setattrfunc)$tp_setattr$, /*tp_setattr*/ - (cmpfunc)$tp_compare$, /*tp_compare*/ - (reprfunc)$tp_repr$, /*tp_repr*/ - $tp_as_number$, /*tp_as_number*/ - $tp_as_sequence$, /*tp_as_sequence*/ - $tp_as_mapping$, /*tp_as_mapping*/ - (hashfunc)$tp_hash$, /*tp_hash*/ - (ternaryfunc)$tp_call$, /*tp_call*/ - (reprfunc)$tp_str$, /*tp_str*/ - - /* Space for future expansion */ - 0L,0L,0L,0L, - $Abbrev$type__doc__ /* Documentation string */ -}; - -/* End of code for $name$ objects */ -/* -------------------------------------------------------- */ - diff --git a/Tools/modulator/Templates/object_tp_as_mapping b/Tools/modulator/Templates/object_tp_as_mapping deleted file mode 100644 index f9213b7..0000000 --- a/Tools/modulator/Templates/object_tp_as_mapping +++ /dev/null @@ -1,29 +0,0 @@ - -/* Code to access $name$ objects as mappings */ - -static int -$abbrev$_length($abbrev$object *self) -{ - /* XXXX Return the size of the mapping */ -} - -static PyObject * -$abbrev$_subscript($abbrev$object *self, PyObject *key) -{ - /* XXXX Return the item of self indexed by key */ -} - -static int -$abbrev$_ass_sub($abbrev$object *self, PyObject *v, PyObject *w) -{ - /* XXXX Put w in self under key v */ - return 0; -} - -static PyMappingMethods $abbrev$_as_mapping = { - (inquiry)$abbrev$_length, /*mp_length*/ - (binaryfunc)$abbrev$_subscript, /*mp_subscript*/ - (objobjargproc)$abbrev$_ass_sub, /*mp_ass_subscript*/ -}; - -/* -------------------------------------------------------- */ diff --git a/Tools/modulator/Templates/object_tp_as_number b/Tools/modulator/Templates/object_tp_as_number deleted file mode 100644 index a3426c2..0000000 --- a/Tools/modulator/Templates/object_tp_as_number +++ /dev/null @@ -1,162 +0,0 @@ - -/* Code to access $name$ objects as numbers */ - -static PyObject * -$abbrev$_add($abbrev$object *v, $abbrev$object *w) -{ - /* XXXX Add them */ -} - -static PyObject * -$abbrev$_sub($abbrev$object *v, $abbrev$object *w) -{ - /* XXXX Subtract them */ -} - -static PyObject * -$abbrev$_mul($abbrev$object *v, $abbrev$object *w) -{ - /* XXXX Multiply them */ -} - -static PyObject * -$abbrev$_div($abbrev$object *x, $abbrev$object *y) -{ - /* XXXX Divide them */ -} - -static PyObject * -$abbrev$_mod($abbrev$object *x, $abbrev$object *y) -{ - /* XXXX Modulo them */ -} - -static PyObject * -$abbrev$_divmod($abbrev$object *x, $abbrev$object *y) -{ - /* XXXX Return 2-tuple with div and mod */ -} - -static PyObject * -$abbrev$_pow($abbrev$object *v, $abbrev$object *w, $abbrev$object *z) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_neg($abbrev$object *v) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_pos($abbrev$object *v) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_abs($abbrev$object *v) -{ - /* XXXX */ -} - -static int -$abbrev$_nonzero($abbrev$object *v) -{ - /* XXXX Return 1 if non-zero */ -} - -static PyObject * -$abbrev$_invert($abbrev$object *v) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_lshift($abbrev$object *v, $abbrev$object *w) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_rshift($abbrev$object *v, $abbrev$object *w) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_and($abbrev$object *v, $abbrev$object *w) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_xor($abbrev$object *v, $abbrev$object *w) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_or($abbrev$object *v, $abbrev$object *w) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_int($abbrev$object *v) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_long($abbrev$object *v) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_float($abbrev$object *v) -{ - /* XXXX */ -} - -static PyObject * -$abbrev$_oct($abbrev$object *v) -{ - /* XXXX Return object as octal stringobject */ -} - -static PyObject * -$abbrev$_hex($abbrev$object *v) -{ - /* XXXX Return object as hex stringobject */ -} - -static PyNumberMethods $abbrev$_as_number = { - (binaryfunc)$abbrev$_add, /*nb_add*/ - (binaryfunc)$abbrev$_sub, /*nb_subtract*/ - (binaryfunc)$abbrev$_mul, /*nb_multiply*/ - (binaryfunc)$abbrev$_div, /*nb_divide*/ - (binaryfunc)$abbrev$_mod, /*nb_remainder*/ - (binaryfunc)$abbrev$_divmod, /*nb_divmod*/ - (ternaryfunc)$abbrev$_pow, /*nb_power*/ - (unaryfunc)$abbrev$_neg, /*nb_negative*/ - (unaryfunc)$abbrev$_pos, /*nb_positive*/ - (unaryfunc)$abbrev$_abs, /*nb_absolute*/ - (inquiry)$abbrev$_nonzero, /*nb_nonzero*/ - (unaryfunc)$abbrev$_invert, /*nb_invert*/ - (binaryfunc)$abbrev$_lshift, /*nb_lshift*/ - (binaryfunc)$abbrev$_rshift, /*nb_rshift*/ - (binaryfunc)$abbrev$_and, /*nb_and*/ - (binaryfunc)$abbrev$_xor, /*nb_xor*/ - (binaryfunc)$abbrev$_or, /*nb_or*/ - (coercion)$abbrev$_coerce, /*nb_coerce*/ - (unaryfunc)$abbrev$_int, /*nb_int*/ - (unaryfunc)$abbrev$_long, /*nb_long*/ - (unaryfunc)$abbrev$_float, /*nb_float*/ - (unaryfunc)$abbrev$_oct, /*nb_oct*/ - (unaryfunc)$abbrev$_hex, /*nb_hex*/ -}; - -/* ------------------------------------------------------- */ diff --git a/Tools/modulator/Templates/object_tp_as_sequence b/Tools/modulator/Templates/object_tp_as_sequence deleted file mode 100644 index 54c0b92..0000000 --- a/Tools/modulator/Templates/object_tp_as_sequence +++ /dev/null @@ -1,58 +0,0 @@ - -/* Code to handle accessing $name$ objects as sequence objects */ - -static int -$abbrev$_length($abbrev$object *self) -{ - /* XXXX Return the size of the object */ -} - -static PyObject * -$abbrev$_concat($abbrev$object *self, PyObject *bb) -{ - /* XXXX Return the concatenation of self and bb */ -} - -static PyObject * -$abbrev$_repeat($abbrev$object *self, int n) -{ - /* XXXX Return a new object that is n times self */ -} - -static PyObject * -$abbrev$_item($abbrev$object *self, int i) -{ - /* XXXX Return the i-th object of self */ -} - -static PyObject * -$abbrev$_slice($abbrev$object *self, int ilow, int ihigh) -{ - /* XXXX Return the ilow..ihigh slice of self in a new object */ -} - -static int -$abbrev$_ass_item($abbrev$object *self, int i, PyObject *v) -{ - /* XXXX Assign to the i-th element of self */ - return 0; -} - -static int -$abbrev$_ass_slice(PyListObject *self, int ilow, int ihigh, PyObject *v) -{ - /* XXXX Replace ilow..ihigh slice of self with v */ - return 0; -} - -static PySequenceMethods $abbrev$_as_sequence = { - (inquiry)$abbrev$_length, /*sq_length*/ - (binaryfunc)$abbrev$_concat, /*sq_concat*/ - (intargfunc)$abbrev$_repeat, /*sq_repeat*/ - (intargfunc)$abbrev$_item, /*sq_item*/ - (intintargfunc)$abbrev$_slice, /*sq_slice*/ - (intobjargproc)$abbrev$_ass_item, /*sq_ass_item*/ - (intintobjargproc)$abbrev$_ass_slice, /*sq_ass_slice*/ -}; - -/* -------------------------------------------------------------- */ diff --git a/Tools/modulator/Templates/object_tp_call b/Tools/modulator/Templates/object_tp_call deleted file mode 100644 index a93f17f..0000000 --- a/Tools/modulator/Templates/object_tp_call +++ /dev/null @@ -1,7 +0,0 @@ - -static PyObject * -$abbrev$_call($abbrev$object *self, PyObject *args, PyObject *kwargs) -{ - /* XXXX Return the result of calling self with argument args */ -} - diff --git a/Tools/modulator/Templates/object_tp_compare b/Tools/modulator/Templates/object_tp_compare deleted file mode 100644 index 153bae0..0000000 --- a/Tools/modulator/Templates/object_tp_compare +++ /dev/null @@ -1,6 +0,0 @@ - -static int -$abbrev$_compare($abbrev$object *v, $abbrev$object *w) -{ - /* XXXX Compare objects and return -1, 0 or 1 */ -} diff --git a/Tools/modulator/Templates/object_tp_dealloc b/Tools/modulator/Templates/object_tp_dealloc deleted file mode 100644 index 440419a..0000000 --- a/Tools/modulator/Templates/object_tp_dealloc +++ /dev/null @@ -1,7 +0,0 @@ - -static void -$abbrev$_dealloc($abbrev$object *self) -{ - /* XXXX Add your own cleanup code here */ - PyMem_DEL(self); -} diff --git a/Tools/modulator/Templates/object_tp_getattr b/Tools/modulator/Templates/object_tp_getattr deleted file mode 100644 index 6a1b2e8..0000000 --- a/Tools/modulator/Templates/object_tp_getattr +++ /dev/null @@ -1,7 +0,0 @@ - -static PyObject * -$abbrev$_getattr($abbrev$object *self, char *name) -{ - /* XXXX Add your own getattr code here */ - return Py_FindMethod($abbrev$_methods, (PyObject *)self, name); -} diff --git a/Tools/modulator/Templates/object_tp_hash b/Tools/modulator/Templates/object_tp_hash deleted file mode 100644 index 2d63f6a..0000000 --- a/Tools/modulator/Templates/object_tp_hash +++ /dev/null @@ -1,6 +0,0 @@ - -static long -$abbrev$_hash($abbrev$object *self) -{ - /* XXXX Return a hash of self (or -1) */ -} diff --git a/Tools/modulator/Templates/object_tp_print b/Tools/modulator/Templates/object_tp_print deleted file mode 100644 index 76408d2..0000000 --- a/Tools/modulator/Templates/object_tp_print +++ /dev/null @@ -1,7 +0,0 @@ - -static int -$abbrev$_print($abbrev$object *self, FILE *fp, int flags) -{ - /* XXXX Add code here to print self to fp */ - return 0; -} diff --git a/Tools/modulator/Templates/object_tp_repr b/Tools/modulator/Templates/object_tp_repr deleted file mode 100644 index f122225..0000000 --- a/Tools/modulator/Templates/object_tp_repr +++ /dev/null @@ -1,9 +0,0 @@ - -static PyObject * -$abbrev$_repr($abbrev$object *self) -{ - PyObject *s; - - /* XXXX Add code here to put self into s */ - return s; -} diff --git a/Tools/modulator/Templates/object_tp_setattr b/Tools/modulator/Templates/object_tp_setattr deleted file mode 100644 index dfe4bc8..0000000 --- a/Tools/modulator/Templates/object_tp_setattr +++ /dev/null @@ -1,9 +0,0 @@ - -static int -$abbrev$_setattr($abbrev$object *self, char *name, PyObject *v) -{ - /* Set attribute 'name' to value 'v'. v==NULL means delete */ - - /* XXXX Add your own setattr code here */ - return -1; -} diff --git a/Tools/modulator/Templates/object_tp_str b/Tools/modulator/Templates/object_tp_str deleted file mode 100644 index 2e3648e..0000000 --- a/Tools/modulator/Templates/object_tp_str +++ /dev/null @@ -1,10 +0,0 @@ - -static PyObject * -$abbrev$_str($abbrev$object *self) -{ - PyObject *s; - - /* XXXX Add code here to put self into s */ - return s; -} - diff --git a/Tools/modulator/Tkextra.py b/Tools/modulator/Tkextra.py deleted file mode 100755 index e969dde..0000000 --- a/Tools/modulator/Tkextra.py +++ /dev/null @@ -1,234 +0,0 @@ -#! /usr/bin/env python3 - -# A Python function that generates dialog boxes with a text message, -# optional bitmap, and any number of buttons. -# Cf. Ousterhout, Tcl and the Tk Toolkit, Figs. 27.2-3, pp. 269-270. - -from Tkinter import * - -mainWidget = None - -def dialog(master, title, text, bitmap, default, *args): - - # 1. Create the top-level window and divide it into top - # and bottom parts. - - w = Toplevel(master, {'class': 'Dialog'}) - w.title(title) - w.iconname('Dialog') - - top = Frame(w, {'relief': 'raised', 'bd': 1, - Pack: {'side': 'top', 'fill': 'both'}}) - bot = Frame(w, {'relief': 'raised', 'bd': 1, - Pack: {'side': 'bottom', 'fill': 'both'}}) - - # 2. Fill the top part with the bitmap and message. - - msg = Message(top, - {'width': '3i', - 'text': text, - 'font': '-Adobe-Times-Medium-R-Normal-*-180-*', - Pack: {'side': 'right', 'expand': 1, - 'fill': 'both', - 'padx': '3m', 'pady': '3m'}}) - if bitmap: - bm = Label(top, {'bitmap': bitmap, - Pack: {'side': 'left', - 'padx': '3m', 'pady': '3m'}}) - - # 3. Create a row of buttons at the bottom of the dialog. - - buttons = [] - i = 0 - for but in args: - b = Button(bot, {'text': but, - 'command': ('set', 'button', i)}) - buttons.append(b) - if i == default: - bd = Frame(bot, {'relief': 'sunken', 'bd': 1, - Pack: {'side': 'left', 'expand': 1, - 'padx': '3m', 'pady': '2m'}}) - b.lift() - b.pack ({'in': bd, 'side': 'left', - 'padx': '2m', 'pady': '2m', - 'ipadx': '2m', 'ipady': '1m'}) - else: - b.pack ({'side': 'left', 'expand': 1, - 'padx': '3m', 'pady': '3m', - 'ipady': '2m', 'ipady': '1m'}) - i = i+1 - - # 4. Set up a binding for <Return>, if there's a default, - # set a grab, and claim the focus too. - - if default >= 0: - w.bind('<Return>', - lambda e, b=buttons[default], i=default: - (b.flash(), - b.setvar('button', i))) - - oldFocus = w.tk.call('focus') # XXX - w.grab_set() - w.focus() - - # 5. Wait for the user to respond, then restore the focus - # and return the index of the selected button. - - w.waitvar('button') - w.destroy() - w.tk.call('focus', oldFocus) # XXX - return w.getint(w.getvar('button')) - -def strdialog(master, title, text, bitmap, default, *args): - - # 1. Create the top-level window and divide it into top - # and bottom parts. - - w = Toplevel(master, {'class': 'Dialog'}) - w.title(title) - w.iconname('Dialog') - - top = Frame(w, {'relief': 'raised', 'bd': 1, - Pack: {'side': 'top', 'fill': 'both'}}) - if args: - bot = Frame(w, {'relief': 'raised', 'bd': 1, - Pack: {'side': 'bottom', 'fill': 'both'}}) - - # 2. Fill the top part with the bitmap, message and input field. - - if bitmap: - bm = Label(top, {'bitmap': bitmap, - Pack: {'side': 'left', - 'padx': '3m', 'pady': '3m'}}) - - msg = Message(top, - {'width': '3i', - 'text': text, - 'font': '-Adobe-Times-Medium-R-Normal-*-180-*', - Pack: {'side': 'left', - 'fill': 'both', - 'padx': '3m', 'pady': '3m'}}) - - field = Entry(top, - {'relief':'sunken', - Pack:{'side':'left', - 'fill':'x', - 'expand':1, - 'padx':'3m', 'pady':'3m'}}) - # 3. Create a row of buttons at the bottom of the dialog. - - buttons = [] - i = 0 - for but in args: - b = Button(bot, {'text': but, - 'command': ('set', 'button', i)}) - buttons.append(b) - if i == default: - bd = Frame(bot, {'relief': 'sunken', 'bd': 1, - Pack: {'side': 'left', 'expand': 1, - 'padx': '3m', 'pady': '2m'}}) - b.lift() - b.pack ({'in': bd, 'side': 'left', - 'padx': '2m', 'pady': '2m', - 'ipadx': '2m', 'ipady': '1m'}) - else: - b.pack ({'side': 'left', 'expand': 1, - 'padx': '3m', 'pady': '3m', - 'ipady': '2m', 'ipady': '1m'}) - i = i+1 - - # 4. Set up a binding for <Return>, if there's a default, - # set a grab, and claim the focus too. - - if not args: - w.bind('<Return>', lambda arg, top=top: top.setvar('button', 0)) - field.bind('<Return>', lambda arg, top=top: top.setvar('button', 0)) - elif default >= 0: - w.bind('<Return>', - lambda e, b=buttons[default], i=default: - (b.flash(), - b.setvar('button', i))) - field.bind('<Return>', - lambda e, b=buttons[default], i=default: - (b.flash(), - b.setvar('button', i))) - - oldFocus = w.tk.call('focus') # XXX - w.grab_set() - field.focus() - - # 5. Wait for the user to respond, then restore the focus - # and return the index of the selected button. - - w.waitvar('button') - v = field.get() - w.destroy() - w.tk.call('focus', oldFocus) # XXX - if args: - return v, w.getint(w.getvar('button')) - else: - return v - -def message(str): - i = dialog(mainWidget, 'Message', str, '', 0, 'OK') - -def askyn(str): - i = dialog(mainWidget, 'Question', str, '', 0, 'No', 'Yes') - return i - -def askync(str): - i = dialog(mainWidget, 'Question', str, '', 0, 'Cancel', 'No', 'Yes') - return i-1 - -def askstr(str): - i = strdialog(mainWidget, 'Question', str, '', 0) - return i - -def askfile(str): # XXXX For now... - i = strdialog(mainWidget, 'Question', str, '', 0) - return i - -# The rest is the test program. - -def _go(): - i = dialog(mainWidget, - 'Not Responding', - "The file server isn't responding right now; " - "I'll keep trying.", - '', - -1, - 'OK') - print('pressed button', i) - i = dialog(mainWidget, - 'File Modified', - 'File "tcl.h" has been modified since ' - 'the last time it was saved. ' - 'Do you want to save it before exiting the application?', - 'warning', - 0, - 'Save File', - 'Discard Changes', - 'Return To Editor') - print('pressed button', i) - print(message('Test of message')) - print(askyn('Test of yes/no')) - print(askync('Test of yes/no/cancel')) - print(askstr('Type a string:')) - print(strdialog(mainWidget, 'Question', 'Another string:', '', - 0, 'Save', 'Save as text')) - -def _test(): - global mainWidget - mainWidget = Frame() - Pack.config(mainWidget) - start = Button(mainWidget, - {'text': 'Press Here To Start', 'command': _go}) - start.pack() - endit = Button(mainWidget, - {'text': 'Exit', - 'command': 'exit', - Pack: {'fill' : 'both'}}) - mainWidget.mainloop() - -if __name__ == '__main__': - _test() diff --git a/Tools/modulator/genmodule.py b/Tools/modulator/genmodule.py deleted file mode 100755 index f8703ef..0000000 --- a/Tools/modulator/genmodule.py +++ /dev/null @@ -1,160 +0,0 @@ -# -# Genmodule - A python program to help you build (template) modules. -# -# Usage: -# -# o = genmodule.object() -# o.name = 'dwarve object' -# o.abbrev = 'dw' -# o.funclist = ['new', 'dealloc', 'getattr', 'setattr'] -# o.methodlist = ['dig'] -# -# m = genmodule.module() -# m.name = 'beings' -# m.abbrev = 'be' -# m.methodlist = ['newdwarve'] -# m.objects = [o] -# -# genmodule.write(sys.stdout, m) -# -import sys -import os -import varsubst - -error = 'genmodule.error' - -# -# Names of functions in the object-description struct. -# -FUNCLIST = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr', - 'tp_compare', 'tp_repr', 'tp_hash', 'tp_call', 'tp_str'] -TYPELIST = ['tp_as_number', 'tp_as_sequence', 'tp_as_mapping', 'structure'] - -# -# writer is a base class for the object and module classes -# it contains code common to both. -# -class writer: - def __init__(self): - self._subst = None - - def makesubst(self): - if not self._subst: - if 'abbrev' not in self.__dict__: - self.abbrev = self.name - self.Abbrev = self.abbrev[0].upper()+self.abbrev[1:] - subst = varsubst.Varsubst(self.__dict__) - subst.useindent(1) - self._subst = subst.subst - - def addcode(self, name, fp): - ifp = self.opentemplate(name) - self.makesubst() - d = ifp.read() - d = self._subst(d) - fp.write(d) - - def opentemplate(self, name): - for p in sys.path: - fn = os.path.join(p, name) - if os.path.exists(fn): - return open(fn, 'r') - fn = os.path.join(p, 'Templates') - fn = os.path.join(fn, name) - if os.path.exists(fn): - return open(fn, 'r') - raise error('Template '+name+' not found for '+self._type+' '+ \ - self.name) - -class module(writer): - _type = 'module' - - def writecode(self, fp): - self.addcode('copyright', fp) - self.addcode('module_head', fp) - for o in self.objects: - o.writehead(fp) - for o in self.objects: - o.writebody(fp) - new_ml = '' - for fn in self.methodlist: - self.method = fn - self.addcode('module_method', fp) - new_ml = new_ml + ( - '{"%s",\t(PyCFunction)%s_%s,\tMETH_VARARGS,\t%s_%s__doc__},\n' - %(fn, self.abbrev, fn, self.abbrev, fn)) - self.methodlist = new_ml - self.addcode('module_tail', fp) - -class object(writer): - _type = 'object' - def __init__(self): - self.typelist = [] - self.methodlist = [] - self.funclist = ['new'] - writer.__init__(self) - - def writecode(self, fp): - self.addcode('copyright', fp) - self.writehead(fp) - self.writebody(fp) - - def writehead(self, fp): - self.addcode('object_head', fp) - - def writebody(self, fp): - new_ml = '' - for fn in self.methodlist: - self.method = fn - self.addcode('object_method', fp) - new_ml = new_ml + ( - '{"%s",\t(PyCFunction)%s_%s,\tMETH_VARARGS,\t%s_%s__doc__},\n' - %(fn, self.abbrev, fn, self.abbrev, fn)) - self.methodlist = new_ml - self.addcode('object_mlist', fp) - - # Add getattr if we have methods - if self.methodlist and not 'tp_getattr' in self.funclist: - self.funclist.insert(0, 'tp_getattr') - - for fn in FUNCLIST: - setattr(self, fn, '0') - - # - # Special case for structure-access objects: put getattr in the - # list of functions but don't generate code for it directly, - # the code is obtained from the object_structure template. - # The same goes for setattr. - # - if 'structure' in self.typelist: - if 'tp_getattr' in self.funclist: - self.funclist.remove('tp_getattr') - if 'tp_setattr' in self.funclist: - self.funclist.remove('tp_setattr') - self.tp_getattr = self.abbrev + '_getattr' - self.tp_setattr = self.abbrev + '_setattr' - for fn in self.funclist: - self.addcode('object_'+fn, fp) - setattr(self, fn, '%s_%s'%(self.abbrev, fn[3:])) - for tn in TYPELIST: - setattr(self, tn, '0') - for tn in self.typelist: - self.addcode('object_'+tn, fp) - setattr(self, tn, '&%s_%s'%(self.abbrev, tn[3:])) - self.addcode('object_tail', fp) - -def write(fp, obj): - obj.writecode(fp) - -if __name__ == '__main__': - o = object() - o.name = 'dwarve object' - o.abbrev = 'dw' - o.funclist = ['new', 'tp_dealloc'] - o.methodlist = ['dig'] - m = module() - m.name = 'beings' - m.abbrev = 'be' - m.methodlist = ['newdwarve'] - m.objects = [o] - write(sys.stdout, m) diff --git a/Tools/modulator/modulator.py b/Tools/modulator/modulator.py deleted file mode 100755 index 76a7224..0000000 --- a/Tools/modulator/modulator.py +++ /dev/null @@ -1,383 +0,0 @@ -#! /usr/bin/env python3 -# -# Modulator - Generate skeleton modules. -# -# The user fills out some forms with information about what the module -# should support (methods, objects), names of these things, prefixes to -# use for C code, whether the objects should also support access as numbers, -# etc etc etc. -# When the user presses 'Generate code' we generate a complete skeleton -# module in C. -# -# Alternatively, the selections made can be save to a python sourcefile and -# this sourcefile can be passed on the command line (resulting in the same -# skeleton C code). -# -# Jack Jansen, CWI, October 1994. -# - -import sys, os -if os.name != 'mac': - sys.path.append(os.path.join(os.environ['HOME'], - 'src/python/Tools/modulator')) - -from Tkinter import * -from Tkextra import * -from ScrolledListbox import ScrolledListbox -import sys -import genmodule -import string - -oops = 'oops' - -IDENTSTARTCHARS = string.ascii_letters + '_' -IDENTCHARS = string.ascii_letters + string.digits + '_' - -# Check that string is a legal C identifier -def checkid(str): - if not str: return 0 - if not str[0] in IDENTSTARTCHARS: - return 0 - for c in str[1:]: - if not c in IDENTCHARS: - return 0 - return 1 - -def getlistlist(list): - rv = [] - n = list.size() - for i in range(n): - rv.append(list.get(i)) - return rv - -class UI: - def __init__(self): - self.main = Frame() - self.main.pack() - self.main.master.title('Modulator: Module view') - self.cmdframe = Frame(self.main, {'relief':'raised', 'bd':'0.5m', - Pack:{'side':'top', - 'fill':'x'}}) - self.objframe = Frame(self.main, {Pack:{'side':'top', 'fill':'x', - 'expand':1}}) - - - self.check_button = Button(self.cmdframe, - {'text':'Check', 'command':self.cb_check, - Pack:{'side':'left', 'padx':'0.5m'}}) - self.save_button = Button(self.cmdframe, - {'text':'Save...', 'command':self.cb_save, - Pack:{'side':'left', 'padx':'0.5m'}}) - self.code_button = Button(self.cmdframe, - {'text':'Generate code...', - 'command':self.cb_gencode, - Pack:{'side':'left', 'padx':'0.5m'}}) - self.quit_button = Button(self.cmdframe, - {'text':'Quit', - 'command':self.cb_quit, - Pack:{'side':'right', 'padx':'0.5m'}}) - - self.module = UI_module(self) - self.objects = [] - self.modified = 0 - - def run(self): - self.main.mainloop() - - def cb_quit(self, *args): - if self.modified: - if not askyn('You have not saved\nAre you sure you want to quit?'): - return - sys.exit(0) - - def cb_check(self, *args): - try: - self.module.synchronize() - for o in self.objects: - o.synchronize() - except oops: - pass - - def cb_save(self, *args): - try: - pycode = self.module.gencode('m', self.objects) - except oops: - return - - fn = askfile('Python file name: ') - if not fn: - return - - fp = open(fn, 'w') - - fp.write(pycode) - fp.close() - - def cb_gencode(self, *args): - try: - pycode = self.module.gencode('m', self.objects) - except oops: - pass - - fn = askfile('C file name: ') - if not fn: - return - - fp = open(fn, 'w') - - try: - exec(pycode) - except: - message('An error occurred:-)') - return - genmodule.write(fp, m) - fp.close() - -class UI_module: - def __init__(self, parent): - self.parent = parent - self.frame = Frame(parent.objframe, {'relief':'raised', 'bd':'0.2m', - Pack:{'side':'top', - 'fill':'x'}}) - self.f1 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m', - 'fill':'x'}}) - self.f2 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m', - 'fill':'x'}}) - self.f3 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m', - 'fill':'x'}}) - self.f4 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m', - 'fill':'x'}}) - - self.l1 = Label(self.f1, {'text':'Module:', Pack:{'side':'left', - 'padx':'0.5m'}}) - self.name_entry = Entry(self.f1, {'relief':'sunken', - Pack:{'side':'left', 'padx':'0.5m', 'expand':1}}) - self.l2 = Label(self.f1, {'text':'Abbrev:', Pack:{'side':'left', - 'padx':'0.5m'}}) - self.abbrev_entry = Entry(self.f1, {'relief':'sunken', 'width':5, - Pack:{'side':'left', 'padx':'0.5m'}}) - - self.l3 = Label(self.f2, {'text':'Methods:', Pack:{'side':'left', - 'padx':'0.5m'}}) - self.method_list = ScrolledListbox(self.f2, {'relief':'sunken','bd':2, - Pack:{'side':'left', 'expand':1, - 'padx':'0.5m', 'fill':'both'}}) - - self.l4 = Label(self.f3, {'text':'Add method:', Pack:{'side':'left', - 'padx':'0.5m'}}) - self.method_entry = Entry(self.f3, {'relief':'sunken', - Pack:{'side':'left', 'padx':'0.5m', 'expand':1}}) - self.method_entry.bind('<Return>', self.cb_method) - self.delete_button = Button(self.f3, {'text':'Delete method', - 'command':self.cb_delmethod, - Pack:{'side':'left', - 'padx':'0.5m'}}) - - self.newobj_button = Button(self.f4, {'text':'new object', - 'command':self.cb_newobj, - Pack:{'side':'left', - 'padx':'0.5m'}}) - - def cb_delmethod(self, *args): - list = self.method_list.curselection() - for i in list: - self.method_list.delete(i) - - def cb_newobj(self, *arg): - self.parent.objects.append(UI_object(self.parent)) - - def cb_method(self, *arg): - name = self.method_entry.get() - if not name: - return - self.method_entry.delete('0', 'end') - self.method_list.insert('end', name) - - def synchronize(self): - n = self.name_entry.get() - if not n: - message('Module name not set') - raise oops - if not checkid(n): - message('Module name not an identifier:\n'+n) - raise oops - if not self.abbrev_entry.get(): - self.abbrev_entry.insert('end', n) - m = getlistlist(self.method_list) - for n in m: - if not checkid(n): - message('Method name not an identifier:\n'+n) - raise oops - - def gencode(self, name, objects): - rv = '' - self.synchronize() - for o in objects: - o.synchronize() - onames = [] - for i in range(len(objects)): - oname = 'o%d' % (i+1) - rv = rv + objects[i].gencode(oname) - onames.append(oname) - rv = rv + '%s = genmodule.module()\n' % (name,) - rv = rv + '%s.name = %r\n' % (name, self.name_entry.get()) - rv = rv + '%s.abbrev = %r\n' % (name, self.abbrev_entry.get()) - rv = rv + '%s.methodlist = %r\n' % (name, getlistlist(self.method_list)) - rv = rv + '%s.objects = [%s]\n' % (name, ','.join(onames)) - rv = rv + '\n' - return rv - -object_number = 0 - -class UI_object: - def __init__(self, parent): - global object_number - - object_number = object_number + 1 - self.num = object_number - self.vpref = 'o%r_' % self.num - self.frame = Toplevel(parent.objframe) -# self.frame.pack() - self.frame.title('Modulator: object view') -# self.frame = Frame(parent.objframe, {'relief':'raised', 'bd':'0.2m', -# Pack:{'side':'top', -# 'fill':'x'}}) - self.f1 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m', - 'fill':'x'}}) - self.f2 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m', - 'fill':'x'}}) - self.f3 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m', - 'fill':'x'}}) - self.f4 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m', - 'fill':'x'}}) - - - self.l1 = Label(self.f1, {'text':'Object:', Pack:{'side':'left', - 'padx':'0.5m'}}) - self.name_entry = Entry(self.f1, {'relief':'sunken', - Pack:{'side':'left', 'padx':'0.5m', 'expand':1}}) - self.l2 = Label(self.f1, {'text':'Abbrev:', Pack:{'side':'left', - 'padx':'0.5m'}}) - self.abbrev_entry = Entry(self.f1, {'relief':'sunken', 'width':5, - Pack:{'side':'left', 'padx':'0.5m'}}) - - self.l3 = Label(self.f2, {'text':'Methods:', Pack:{'side':'left', - 'padx':'0.5m'}}) - self.method_list = ScrolledListbox(self.f2, {'relief':'sunken','bd':2, - Pack:{'side':'left', 'expand':1, - 'padx':'0.5m', 'fill':'both'}}) - - self.l4 = Label(self.f3, {'text':'Add method:', Pack:{'side':'left', - 'padx':'0.5m'}}) - self.method_entry = Entry(self.f3, {'relief':'sunken', - Pack:{'side':'left', 'padx':'0.5m', 'expand':1}}) - self.method_entry.bind('<Return>', self.cb_method) - self.delete_button = Button(self.f3, {'text':'Delete method', - 'command':self.cb_delmethod, - Pack:{'side':'left', - 'padx':'0.5m'}}) - - - self.l5 = Label(self.f4, {'text':'functions:', - Pack:{'side':'left', - 'padx':'0.5m'}}) - self.f5 = Frame(self.f4, {Pack:{'side':'left', 'pady':'0.5m', - 'fill':'both'}}) - self.l6 = Label(self.f4, {'text':'Types:', - Pack:{'side':'left', 'padx':'0.5m'}}) - self.f6 = Frame(self.f4, {Pack:{'side':'left', 'pady':'0.5m', - 'fill':'x'}}) - self.funcs = {} - for i in genmodule.FUNCLIST: - vname = self.vpref+i - self.f5.setvar(vname, 0) - b = Checkbutton(self.f5, {'variable':vname, 'text':i, - Pack:{'side':'top', 'pady':'0.5m', - 'anchor':'w','expand':1}}) - self.funcs[i] = b - self.f5.setvar(self.vpref+'new', 1) - - self.types = {} - for i in genmodule.TYPELIST: - vname = self.vpref + i - self.f6.setvar(vname, 0) - b = Checkbutton(self.f6, {'variable':vname, 'text':i, - Pack:{'side':'top', 'pady':'0.5m', - 'anchor':'w'}}) - self.types[i] = b - - def cb_method(self, *arg): - name = self.method_entry.get() - if not name: - return - self.method_entry.delete('0', 'end') - self.method_list.insert('end', name) - - def cb_delmethod(self, *args): - list = self.method_list.curselection() - for i in list: - self.method_list.delete(i) - - def synchronize(self): - n = self.name_entry.get() - if not n: - message('Object name not set') - raise oops - if not self.abbrev_entry.get(): - self.abbrev_entry.insert('end', n) - n = self.abbrev_entry.get() - if not checkid(n): - message('Abbreviation not an identifier:\n'+n) - raise oops - m = getlistlist(self.method_list) - for n in m: - if not checkid(n): - message('Method name not an identifier:\n'+n) - raise oops - if m: - self.f5.setvar(self.vpref+'tp_getattr', 1) - pass - - def gencode(self, name): - rv = '' - rv = rv + '%s = genmodule.object()\n' % (name,) - rv = rv + '%s.name = %r\n' % (name, self.name_entry.get()) - rv = rv + '%s.abbrev = %r\n' % (name, self.abbrev_entry.get()) - rv = rv + '%s.methodlist = %r\n' % (name, getlistlist(self.method_list)) - fl = [] - for fn in genmodule.FUNCLIST: - vname = self.vpref + fn - if self.f5.getvar(vname) == '1': - fl.append(fn) - rv = rv + '%s.funclist = %r\n' % (name, fl) - - fl = [] - for fn in genmodule.TYPELIST: - vname = self.vpref + fn - if self.f5.getvar(vname) == '1': - fl.append(fn) - - rv = rv + '%s.typelist = %r\n' % (name, fl) - - rv = rv + '\n' - return rv - - -def main(): - if len(sys.argv) < 2: - ui = UI() - ui.run() - elif len(sys.argv) == 2: - fp = open(sys.argv[1]) - pycode = fp.read() - try: - exec(pycode) - except: - sys.stderr.write('An error occurred:-)\n') - sys.exit(1) - ##genmodule.write(sys.stdout, m) - else: - sys.stderr.write('Usage: modulator [file]\n') - sys.exit(1) - -main() diff --git a/Tools/modulator/varsubst.py b/Tools/modulator/varsubst.py deleted file mode 100644 index 4b68512..0000000 --- a/Tools/modulator/varsubst.py +++ /dev/null @@ -1,56 +0,0 @@ -# -# Variable substitution. Variables are $delimited$ -# -import re - -error = 'varsubst.error' - -class Varsubst: - def __init__(self, dict): - self.dict = dict - self.prog = re.compile('\$([a-zA-Z0-9_]*)\$') - self.do_useindent = 0 - - def useindent(self, onoff): - self.do_useindent = onoff - - def subst(self, s): - rv = '' - while 1: - m = self.prog.search(s) - if not m: - return rv + s - rv = rv + s[:m.start()] - s = s[m.end():] - if m.end() - m.start() == 2: - # Escaped dollar - rv = rv + '$' - s = s[2:] - continue - name = m.group(1) - if name not in self.dict: - raise error('No such variable: '+name) - value = self.dict[name] - if self.do_useindent and '\n' in value: - value = self._modindent(value, rv) - rv = rv + value - - def _modindent(self, value, old): - lastnl = old.rfind('\n', 0) + 1 - lastnl = len(old) - lastnl - sub = '\n' + (' '*lastnl) - return re.sub('\n', sub, value) - -def _test(): - import sys - import os - - sys.stderr.write('-- Copying stdin to stdout with environment map --\n') - c = Varsubst(os.environ) - c.useindent(1) - d = sys.stdin.read() - sys.stdout.write(c.subst(d)) - sys.exit(1) - -if __name__ == '__main__': - _test() |