most recently opened URL in self.openedurl of the URLopener instance.
This doesn't really work if multiple threads share the same opener
instance!
Fix: openedurl was actually simply the type prefix (e.g. "http:")
followed by the rest of the URL; since the rest of the URL is
available and the type is effectively determined by where you are in
the code, I can reconstruct the full URL easily, e.g. "http:" + url.
The main incompatibility is that the error reporting method is now
called as
parser.syntax_error(msg)
instead of
parser.syntax_error(lineno, msg)
This new version also has some code to deal with the <?xml?> and
<!DOCTYPE> tags at the start of an XML document.
The documentation has been updated, and a small test module has been
created.
Here's my suggested replacement for gzip.py for 1.5.1. I've
re-implemeted methods readline and readlines, added an _unread, and
tweaked read and _read.
I tried a more complicated buffer scheme for unread (using a list of
strings and string.join), but it was more complicated and slower.
This version is a lot faster than the current version and is still
pretty simple.
Fixed problems when unpickling in restricted execution environments.
These methods try to assign to an instance's __class__ attribute, or
access the instances __dict__, which are prohibited in REE. For the
first two methods, I re-implemented the old behavior when assignment
to value.__class__ fails.
For the load_build() I also re-implemented the old behavior when
inst.__dict__.update() fails but this means that unpickling in REE is
semantically different than unpickling in unrestricted mode.
input. When an EOF is read, break out of the loop instead of (by
default) writing an empty line (which doesn't do much good). Don't
close self when falling through the loop.
* The invoke methods of the three Tkinter widgets Button,
Checkbutton and Radiobutton should return the value returned by
the callback, (like the Menu widget does):
def invoke(self):
return self.tk.call(self._w, 'invoke')
* The select_from method of the Canvas widget should use 'from', not
'set':
def select_from(self, tagOrId, index):
self.tk.call(self._w, 'select', 'from', tagOrId, index)
Currently, if you use select_from, you get the error message:
'TclError: bad select option "set": must be adjust, clear, from, item, or to'
* The 'entrycget' and 'type' methods of the Tk menu widget are
missing from Tkinter.
* There is a bug in grid_columnconfigure and grid_rowconfigure. For
example, this should return the current value of the 'minsize'
option for column 0:
f.grid_columnconfigure(0, 'minsize')
Instead it returns the same as:
f.grid_columnconfigure(0)
I suggest that the hint given in the comment in the
Tkinter.Misc.configure method should be followed - "ought to
generalize this so tag_config etc. can use it". Repeating the
same configure code several times in Tkinter is inviting errors.
[I did not follow this advice --G]
* The grid_slaves method should handle options. Currently, to pass
options to the grid_slaves method, you have to do something like:
grid_slaves('-row', 1)
retrieving files from the same host and directory, you had to close
the previous instance before opening a new one; and retrieving a
non-existent file would return an empty file. (The latter fix relies
on maybe an undocumented property of NLST -- NLST of a file returns
just that file, while NLST of a non-existent file returns nothing. A
side effect, unfortunately, seems to be that now ftp-retrieving an
*empty* directory may fail. Ah well.)
The attached patch adds the following behavior to the handling
of REDUCE codes:
- A user-defined type may have a __reduce__ method that returns
a string rather than a tuple, in which case the object is
saved as a global object with a name given by the string returned
by reduce.
This was a feature added to cPickle a long time ago.
- User-defined types can now support unpickling without
executing a constructor.
The second value returned from '__reduce__' can now be None,
rather than an argument tuple. On unpickling, if the
second value returned from '__reduce__' during pickling was
None, then rather than calling the first value returned from
'__reduce__', directly, the '__basicnew__' method of the
first value returned from '__reduce__' is called without
arguments.
I also got rid of a few of Chris' extra ()s, which he used
to make python ifs look like C ifs.
__builtins__ for all calls to eval(). This still allows someone to
write string.atof("[1]*1000000") (which Jim Fulton worries about) but
effectively disables access to system modules and functions.
have been configured, string.atof() should not fail when "import re"
fails (usually because pcre is not there).
This opens up a tiny security hole: *if* an attacker can make "import
re" fail, they can also make string.atof(arbitrary_string) evaluate
the arbitrary string. Nothing to keep me awake at night...
mode. The pickler always uses base 10 so the default base should be
fine. (The base gets us in trouble when there's no strop module, as
the atoi() in string.py only supports base 10. This is for JPython.)
not define __getinitargs__, bypass the __init__ constructor
completely. This uses the trick of instantiating an empty dummy class
and then changing inst.__class__ to the real class. This is done in
two places: once for the INST and once for the OBJ format code.
Also replaced the much outdated long doc string with a short summary
of the module; the information of that doc string is already
incorporated in the library reference manual.
Tools/scripts/h2py.py. This file contains many useful streamio(7)
constants, especially the ones that support passing open file
descriptors through a pipe: I_RECVFD and I_SENDFD.
In string.splitfields(), ignore maxsplit if <= 0, rather than ignoring
maxsplit=0 but effectively treating negative numbers the same as
maxsplit=1. Also made the test for maxsplit slightly more efficient
(set it to the length of the string when <= 0 so the test for its
presence can be omitted from the loop).
the writing of filters.
Typical use is:
import fileinput
for line in fileinput.input():
process(line)
This iterates over the lines of all files listed in sys.argv[1:],
defaulting to sys.stdin if the list is empty or when a filename is
'-'.
There is also an option to use this to direct the output back to the
input files.
class from the standard base exception Exception. Otherwise define
Queue.Empty as a string exception.
(Queue): 8-space to 4-space indentation conversion. Also, basically
recast all method comments into docstrings.
format(), str(), atof(), and atoi(). The last three are locale
sensitive versions of the corresponding standard functions (only for
numbers though); format() does general %[efg] formatting taking the
locale into account, optionally with thousands grouping.
All geometry manager methods that apply to a master widget instead of
to a slave widget have been moved to the Misc class, which is
inherited by all of Tk(), Toplevel() and Widget(). They have been
renamed to have their geometry manager name as a prefix,
e.g. pack_propagate(); the short names can still be used where
ambiguities are resolved so that pack has priority over place has
priority over grid (since this was the old rule).
Also, the method definitions in the Pack, Place and Grid classes now
all have their respective geometry manager name as a prefix
(e.g. pack_configure); the shorter names are aliases defined through
assignment.
A similar renaming has been done for all config() methods found
elsewhere; these have been renamed to configure() with config being
the alias (instead of the other way around). (This may not make much
of a difference but the official Tk command name is now 'configure'
and it may help in debugging tracebacks.)
Finally, a new base class BaseWidget has been introduced, which
implements the methods common between Widget and Toplevel (the
difference between those two classes is that Toplevel has a different
__init__() but also that Toplevel doesn't inherit from Pack, Place or
Grid.
methods. Using None causes problems if the destructor is called after
the __builtin__ module has already been destroyed (unfortunately, this
can happen!). I can't just delete the object because it is actually
tested for (if self._sock: ...). Setting it to 0 is a bit weird but
works.
There are two ways to use this -- as a filter (e.g. using C-U M-| on a
regex string literal in an Emacs buffer) or from a Python program
which imports this as a module. Read the doc string for more info,
and also some caveats (some cases aren't handled right).
Also change all occurrences of "x == None" to "x is None" (not that it
matters much, these functions are all reimplemented in strop -- but
count() is not).
The new re module was written by Andrew Kuchling and uses the pcre
code in ../Modules/. The old re module has been renamed to re1,
just in case you need it for comparison.
with an instance of a derived class B would really raise an A, not a
B. Since Barry fixed this anomalous behaviour, I though I might as
well fix the test! (Hmm, Barry, did you not run the tests or did you
miss that test_opcodes failed?)
os.fdopen() calls unbuffered. I presume that it's enough if we can
make all three of them (for stdin, stdout, and stderr) unbuffered and
don't need to specify different buffer sizes per file -- that would
complicate the interface more than I care for.
Apparently the traceback object doesn't contains the right linenumber
when -O is used. Rather than guessing whether -O is on or off, use
tb_lineno() unconditionally.
When completing a simple identifier, it completes keywords, built-ins
and globals in __main__; when completing NAME.NAME..., it evaluates
(!) the expression up to the last dot and completes its attributes.
It's very cool to do "import string" type "string.", hit the
completion key (twice), and see the list of names defined by the
string module!
Tip: to use the tab key as the completion key, call
readline.parse_and_bind("tab: complete")
- Don't use "from copy_reg import *".
- Use cls.__module__ instead of calling whichobject(cls, cls.__name__);
also try __module__ in whichmodule(), just in case.
- After calling save_reduce(), add the object to the memo.
instance, use inst.__dict__.update(value) instead of a for loop with
setattr() over the value.keys(). This is more consistent (the
pickling doesn't use getattr() either but pickles inst.__dict__) and
avoids problems with instances that have a __setattr__ hook.
But it *is* a semantic change (because the setattr hook is no longer
used). So beware!
errors are handled (these gave ``TypeError: not enough arguments'').
Also changed its __str__() to correct a typo (missing self.) and
return str(self.msg) to ensure the result is always string.
Also changed the default __str__ to simply return str(self.args).
(though some type names are undefined in that case, e.g. CodeType
(inaccessible), FileType (not always accessible), and TracebackType
and FrameType (inaccessible).
Sjoerd: add separate administration of temporary files created y
URLopener.retrieve() so cleanup can properly remove them. The old
code removed everything in tempcache which was a bad idea if the user
had passed a non-temp file into it. (I added a line to delete the
tempcache in cleanup() -- it still seems to make sense.)
Jack: in basejoin(), interpret relative paths starting in "../". This
is necessary if the server uses symbolic links.
that multiple retrievals using the same connection will work.
This leaves open the more general problem that after
f = urlopen("ftp://...")
f must be closed before another retrieval from the same host should be
attempted.
the memo) to avoid a certain kind of nasty crash. (Not easily
reproducable because it requires a later call to __getinitargs__() to
return a tuple that happens to be allocated at the same address.)
default and -v. In default mode, the name of each test is printed.
-v is the same as the old -vv. -q is more quiet than the old default
mode; that's fine I think.
Also moved %c and %Z out of there, even though they are standard,
because these are locale dependent (and e.g. on Windows and Mac they
return different strings). Finally, sorted the tables slightly
different, to match my standard docs better (%a before %A).
(1) No longer close self.sock; close it on close(). (Guido)
(2) Don't use regular expressions for what can be done simply with
string.split() -- regex is thread unsafe. (Jeremy)
(3) Delete unused imports. (Jeremy)