As the doc string for _lookupName() explains:
This routine uses a list instead of a dictionary, because a
dictionary can't store two different keys if the keys have the
same value but different types, e.g. 2 and 2L. The compiler
must treat these two separately, so it does an explicit type
comparison before comparing the values.
Avoid if/elif/elif/else tests where the final else is supposed to
handle exactly one case instead of all other cases. When the list of
operators is extended, the catchall else treats all new operators as
the last operator in the set of tests. Instead, raise an exception if
an unexpected operator occurs.
Use a dictionary instead of a list to map objects to their offsets in
a const/name tuple of a code object.
XXX The conversion is perhaps incomplete, in that we shouldn't have to
do the list2dict to start.
Add support for floor division (// and //=)
The implementation of getChildren() and getChildNodes() is intended to
be faster, because it avoids calling flatten() on every return value.
But it's not clear that it is a lot faster, because constructing a
tuple with just the right values ends up being slow. (Too many
attribute lookups probably.)
The ast.txt file is much more complicated, with funny characters at
the ends of names (*, &, !) to indicate the types of each child node.
The astgen script is also much more complex, making me wonder if it's
still useful.
64-bit INTs on 32-bit boxes (where they become longs). Also exploit that
int(str) and long(str) will ignore a trailing newline (saves creating a
new string at the Python level).
pickletester.py: Simulate reading a pickle produced by a 64-bit box.
varnames should list all the local variables (with arguments first).
The XXX_NAME ops typically occur at the module level and assignment
ops should create locals.
(Hard to believe these were never handled before)
Add misc.mangle() that mangles based on the rules in compile.c.
XXX Need to test the corner cases
Update CodeGenerator with a class_name attribute bound to None. If a
particular instance is created within a class scope, the instance's
class_name is bound to that class's name.
Add mangle() method to CodeGenerator that mangles if the class_name
has a class_name in it.
Modify the FunctionCodeGenerator family to handle an extra argument--
the class_name.
Wrap all name ops and attrnames in calls to self.mangle()
Make nested scopes enabled by default
Add is_constant_false() helper so that compiled code and symbols are
consistent with builtin compiler's handling of "if 0:"
Fix doc string handling to be consistent with recent change that
eliminates the doc string from the Module's node attribute.
Add fix to print handling from Evan & Shane.
Track change to visitor api by making "verbose" explicit.
Comment out setting CO_NESTED flag (it's unnecessary in 2.2).
Evan Simpson's fix. And his explanation:
If you defined two nested functions in a row that refer to the
same non-global variable, the second one will be generated as
though the variable were global.
The use of com_node() introduces a lot of extra stack frames, enough
to cause a stack overflow compiling test.test_parser with the standard
interpreter recursionlimit. The com_node() is a convenience function
that hides the dispatch details, but comes at a very high cost. It is
more efficient to dispatch directly in the callers. In these cases,
use lookup_node() and call the dispatched node directly.
Also handle yield_stmt in a way that will work with Python 2.1
(suggested by Shane Hathaway)
Remove _preorder as alias for dispatch and call dispatch directly.
Add an extra optional argument to walk()
XXX Also comment out some code that does debugging prints.
Modify rfc822.formatdate() to always generate English names,
regardless of locale. This is required by RFC 1123.
In open_local_file() of urllib and urllib2, use new formatdate() from
rfc822.
recent classobject.c change. When calling an unbound method with no
instances as first argument, the error message has changed. The
message now contains the class name, but the output text being
compared to is too generic, so skip printing it.
lambda (anonymous functions?), function, xrange, buffer, cell (need to
fill in), and (some) descriptor types.
Also added a new test case for testing repr truncation fixes.
modules and extensions on Windows is now $PREFIX/Lib/site-packages.
Includes backwards compatibility code for pre-2.2 Pythons. Contributed
by Paul Moore.
- file URL now starts with "file://" (standard) rather than "file:"
- new optional argument 'context' to enable()
- repeated variable names don't have their values shown twice
- dotted attributes are shown; missing attributes handled reasonably
- highlight the whole logical line even if it has multiple physical lines
- use nice generator interface to tokenize
- formatting fixed so that it looks good in lynx, links, and w3m too
flag, which specifies external or resource intensive tests to
perform. This is used by test_largefile and test_socket_ssl.
-u/--use takes a comma separated list of flags, currently supported:
largefile, network.
usage(): New function. Note that the semantics of main() have changed
slightly; instead of returning an error code, it raises a
SystemExit (via sys.exit()) with the given error code.
main(): use_large_resources => use_resources
Also, added support for long-option alternative to the short
options.
_expectations: Added test_socket_ssl to the list of expectedly skipped
tests.
requires(): New function which can be used to `assert' that a specific
-u/--use resource flag is present. Raises a TestSkipped if not.
This is used in test_largefile and test_socket_ssl to enable
external or resource consumptive tests that are normally
disabled.
to stdout. Repaired by not printing at all except in verbose mode.
Made the test about 6x faster -- envelope analysis showed it took time
proportional to the square of the # of tasks. Now it's linear.
module has to deal with "class" HTML-as-deployed as well as XHTML, so we
cannot be as strict as XHTML allows.
This closes SF bug #453059, but uses a different fix than suggested in
the bug comments.
right way"). Fiddle __future__.py to use them.
Jeremy's pyassem.py may also want to use them (by-hand duplication of
magic numbers is brittle), but leaving that to his judgment.
Beef up __future__'s test to verify the exported feature names appear
correct.
For the HTTPS class (when available), ensure that the x509 certificate data
gets passed through to the HTTPSConnection class. Create a new
HTTPS.__init__ to do this, and refactor the HTTP.__init__ into a new _setup
method for both init's to call.
Note: this is solved differently from the patch, which advocated a new
**x509 parameter on the base HTTPConnection class. But that would open
HTTPConnection to arbitrary (ignored) parameters, so was not as desirable.
somewhat less horrid hack <wink>: if a module does
from __future__ import X
then the module dict D is left in a state such that (viewing X as a
string)
D[X] is getattr(__future__, X)
So by examining D for all the names of future features, and making that
test for each, we can make a darned good guess as to which future-features
were imported by the module. The appropriate flags are then sucked out
of the __future__ module, and passed on to compile()'s new optional
arguments (PEP 264).
Also gave doctest a meaningful __all__, removed the history of changes
(CVS serves that purpose now), and removed the __version__ vrbl (similarly;
before CVS, it was a reasonable clue, but not anymore).
builtin_eval wasn't merging in the compiler flags from the current frame;
I suppose we never noticed this before because future division is the
first future-feature that can affect expressions (nested_scopes and
generators had only statement-level effects).
specified in the uu header already exists. No additional
workaround is provided since out_file=pathname is a deprecated
interface, so it is better to simply pass a file-like object into
out_file anyway. This closes SF bug #438083.
Use isinstance() tests instead of type comparisons.
#449043 supporting __future__ in simulated shells
in support of PEP 264.
Much has changed from the patch version:
+ Repaired bad hex constant for nested_scopes.
+ Defined symbolic CO_xxx names so global search will find these uses.
+ Made the exported list of feature names explicit, instead of abusing
__all__ for this purpose (and redefined __all__ accordingly).
+ Added gross .compiler_flag verification to test___future__.py, and
reworked it a little to make use of the newly exported explicit list
of feature names.
is pickled as a global must now exist by the name under which it is
pickled, otherwise the pickling fails. Previously, such things would
fail on unpickling, or unpickle as the wrong global object. I'm
hoping that this won't break existing code that is playing tricks with
this.
I need a volunteer to do this for cPickle too.
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled
- check for Py_USING_UNICODE in all places that use Unicode functions
- disables unicode literals, and the builtin functions
- add the types.StringTypes list
- remove Unicode literals from most tests.
expression. This is needed for certain servers that (in violation of
the standard) don't return the parentheses in the response.
This fixes SF bug #441712 by Henrik Weber (not exactly using his
patch).
when an unbound method of class A is stored as a class variable of
class B, and class B is *not* a subclass of class A, that method
should *not* get bound to B instances.
+ test_compare. While None compares less than anything else, it's not
always the case that None has the smallest id().
+ test_descr. The output of %p (pointer) formats varies across platforms.
In particular, on Windows it doesn't produce a leading "0x".
parameter, but did not. This was found because it can create failures
elsewhere based on the presence of mime.types files in some common locations
the module searches by default.
(I will be writing a test for this module shortly!)
that class should compare the id() of those instances. Add a test
that verifies this. This test currently fails; I believe this is
caused by object.c:2.132 (Patch #424475 by loewis).
attribute. Deleting it, or setting it to a non-dictionary result in a
TypeError. Note that getting it the first time magically initializes
it to an empty dict so that func.__dict__ will always appear to be a
dictionary (never None).
Closes SF bug #446645.
- Remove various 'global' directives and move some global definitions
inside the test functions that use them -- we have nested scopes so
the old hacks using globals are no longer needed.
libraries. This is done by adding a .get_source_files() method,
contributed by Rene Liebscher and slightly modified.
Remove an unused local variable spotted by PyChecker
though 'licence' is still supported for backward-compatibility
(Should I add a warning to get_licence(), or not bother?)
Also fixes an UnboundLocalError noticed by PyChecker
bug #449000, "re.sub(r'\n', ...) broke". This was Fredrik's
suggestion -- he's on vacation and said he wouldn't be able to work on
this until next week.
For local files urllib.py doesn't return the MIME
headers that the documentation says it does:
http://www.python.org/doc/current/lib/module-
urllib.html#l2h-2187 states that "When the method is
local-file, returned headers will include a Date
representing the file's last-modified time, a Content-
Length giving file size, and a Content-Type containing
a guess at the file's type"
But in Python 2.1 the only header that gets returned
is the Content-Type:
>>> import urllib
>>> f = urllib.urlopen("gurk.txt")
>>> f.info().headers
['Content-Type: text/plain\n']
Python's logolike module turtle.py did not display
the turtle except when actually drawing lines.
This patch changes the turtle.py module so that
it displays the turtle at all times when tracing is
on. This is similar to the the way that logo works.
When tracing is off the turtle will not be displayed.
If 'unittest.py' was run from the command line with the name of a test
case class as a parameter, it failed with an ugly error. (Which was a
shame, because the documentation says you can do that.)
The problem was the old 'is the class X that you imported from me the same
as my class X?' gotcha.
This introduces:
- A new operator // that means floor division (the kind of division
where 1/2 is 0).
- The "future division" statement ("from __future__ import division)
which changes the meaning of the / operator to implement "true
division" (where 1/2 is 0.5).
- New overloadable operators __truediv__ and __floordiv__.
- New slots in the PyNumberMethods struct for true and floor division,
new abstract APIs for them, new opcodes, and so on.
I emphasize that without the future division statement, the semantics
of / will remain unchanged until Python 3.0.
Not yet implemented are warnings (default off) when / is used with int
or long arguments.
This has been on display since 7/31 as SF patch #443474.
Flames to /dev/null.
Also fix another bug caught by pychecker-- HTTPError() raised when
redirect limit exceed did not pass an fp object. Had to change method
to keep fp object around until it's certain that the error won't be
raised.
Remove useless line in do_proxy().
attribute values. Just using escape() can (and always has) led to broken
XML being generated. This makes sure it always produces the right thing.
This actually closes SF bug #440351.
break old code (in extreme cases). See SF bug #448153.
Add a new subclass IterableUserDict that has the __iter__ method.
Note that for new projects, unless backwards compatibility with
pre-2.2 Python is required, subclassing 'dictionary' is recommended;
UserDict might become deprecated.
__all__, to indicate these are implied as part of the public API.
IDLE's "Check Module" command uses this, and it broke once already
because the reset_globals() and tokeneater() functions were deleted
when Neil converted this to using the generator API of tokenizer.
(See SF bug #448835.)
starting the test suite proper. If _socket fails to build, that will
make this test fail with an ImportError -- handled by the test harness
as "no such module _socket" -- instead of an AttributeError deep in
CGIHTTPServer.
names of the test methods were not changed from the Zope-standard "check"
names to the Python-standard "test_" names, so the tests were not actually
being run.
Added test of hexadecimal character references as a regression check for
SF bug #445196.
Fix handling of hexadecimal character references (legal in XHTML) so that
they are properly interpreted as character references.
This fixes SF bug #445196.
If pyexpat is not available and more than one attempt is made to load
an expat-based xml parser, an empty xml.parser.expat module will be
created. This empty module will confuse xml.sax.expatreader into
thinking that pyexpat is available.
The ugly fix is to verify that the expat module actually defines the
names that are imported from pyexpat.
d:/whatever instead of /whatever. While I'm afraid changing isabs()
to be *consistent* with this would break lots of code, it makes
best sense for join() to do it this way. Thanks to Alex Martelli for
pushing back on this one!
to the current Python interpreter (ie. the one used for
building/installation), even (especially!) if "/usr/bin/env" appears in
the #! line.
Rationale: installing scripts with "#!/usr/bin/env python" is asking for
trouble, because
1) it might pick the wrong interpreter (not the one used to
build/install the script)
2) it doesn't work on all platforms (try it on IRIX 5, or on Linux
with command-line options for python)
3) "env" might not be in /usr/bin
+ test_quopri.py relied on significant trailing spaces. Fixed.
+ test_dircache.py (still) doesn't work on Windows (directory mtime on
Windows doesn't work like it does on Unix).
is complete: recompute _dirs_in_sys_path each time these functions are
entered after module initialization is complete, and reset before
returning to user code.
This closes SF patch #442983.
Fix showstopper SF bug #442983: use of site.addsitedir() was broken
because it references the global dirs_in_sys_path which is deleted.
The fix avoids deleting that global.
(My email through python.org or digicool.com is non-functional at the
moment; use gvanrossum@home.com to reach me.)
This is a Windows-specific glitch that's really due to that, e.g.,
ntpath.join("c:", "/abc") returned "/abc" instead of "c:/abc". Made
join smarter.
Bugfix candidate.
Reorganize so the initialization sequences does not bite us in the foot.
(There is no good reason to discard classes that clients may want to
subclass.)
****************
PyShell: Added functionality:
usage: idle.py [-c command] [-d] [-i] [-r script] [-s] [-t title] [arg] ...
idle file(s) (without options) edit the file(s)
-c cmd run the command in a shell
-d enable the debugger
-i open an interactive shell
-i file(s) open a shell and also an editor window for each file
-r script run a file as a script in a shell
-s run $IDLESTARTUP or $PYTHONSTARTUP before anything else
-t title set title of shell window
Remaining arguments are applied to the command (-c) or script (-r).
******************
idles: Removed the idles script, not needed
******************
idle: Removed the IdleConf references, not required anymore
was already correctly parsed (contrary to a comment in Mailman).
test_rfc2822_phrases(): RFC 2822 now requires that we allow `.' in
phrases, which means we must accept dots in unquoted realname parts.
Add a test to check the change in rfc822.py 1.58.
now allowed in unquoted RealName areas (technically, they are defined
as "obsolete syntax" we MUST accept in phrases, as part of the
obs-phrase production). Thus, parsing
To: User J. Person <person@dom.ain>
correctly returns "User J. Person" as the RealName.
AddrlistClass.__init__(): Add definition of self.phraseends which is
just self.atomends with `.' removed.
getatom(): Add an optional argument `atomends' which, if None (the
default) means use self.atomends.
getphraselist(): Pass self.phraseends to getatom() and break out of
the loop only when the current character is in phraseends instead of
atomends. This allows dots to continue to serve as atom delimiters in
all contexts except phrases.
Also, loads of docstring updates to document RFC 2822 conformance
(sorry, this should have been two separate patches).
Added a patch which modifies idlefork so that it can co-exist with
"official" IDLE in the site-packages directory. This patch is not
necessary if only idlefork IDLE is installed. See INSTALLATION for further
details.
The default behaviour of idlefork idle is to open an editor window instead
of a shell. Complex expressions may be run in a fresh environment by
selecting "run". There are times, however, when a shell is desired.
Though one can be started by "idle -t 'foo'", this script is more
convenient. In addition, a shell and an editor window can be started
in parallel by "idles -e foo.py".
that 'yield' is a keyword. This doesn't help test_generators at all! I
don't know why not. These things do work now (and didn't before this
patch):
1. "from __future__ import generators" now works in a native shell.
2. Similarly "python -i xxx.py" now has generators enabled in the
shell if xxx.py had them enabled.
3. This program (which was my doctest proxy) works fine:
from __future__ import generators
source = """\
def f():
yield 1
"""
exec compile(source, "", "single") in globals()
print type(f())
The default behaviour of idlefork idle is to open an editor window instead
of a shell. Complex expressions may be run in a fresh environment by
selecting "run". There are times, however, when a shell is desired.
Though one can be started by "idle -t 'foo'", this script is more
convenient. In addition, a shell and an editor window can be started
in parallel by "idles -e foo.py".
that info to code dynamically compiled *by* code compiled with generators
enabled. Doesn't yet work because there's still no way to tell the parser
that "yield" is OK (unlike nested_scopes, the parser has its fingers in
this too).
Replaced PyEval_GetNestedScopes by a more-general
PyEval_MergeCompilerFlags. Perhaps I should not have? I doubted it was
*intended* to be part of the public API, so just did.
the yield statement. I figure we have to have this in before I can
release 2.2a1 on Wednesday.
Note: test_generators is currently broken, I'm counting on Tim to fix
this.
"Move the action of loading the configuration to the IdleConf module
rather than the idle.py script. This has advantages and
disadvantages; the biggest advantage being that we can more easily
have an alternative main program." --GvR
"Amazing. A very subtle change in policy in descr-branch actually
found a bug here. Here's the deal: Class PyShell derives from class
OutputWindow. Method PyShell.close()
wants to invoke its parent method, but because PyShell long ago was
inherited from class PyShellEditorWindow, it invokes
PyShelEditorWindow.close(self). Now, class PyShellEditorWindow itself
derives from class OutputWindow, and inherits the close() method from
there without overriding it. Under the old rules,
PyShellEditorWindow.close would return an unbound method restricted to
the class that defined the implementation of close(), which was
OutputWindow.close. Under the new rules, the unbound method is
restricted to the class whose method was requested, that is
PyShellEditorWindow, and this was correctly trapped as an error." --GvR
"Taught IDLE's autoident parser that "yield" is a keyword that begins a
stmt. Along w/ the preceding change to keyword.py, making all this
work w/ a future-stmt just looks harder and harder." --tim_one
(From Rel 1.8: "Hack to make this still work with Python 1.5.2. ;-( "
--fdrake)
"Move the action of loading the configuration to the IdleConf module
rather than the idle.py script. This has advantages and
disadvantages; the biggest advantage being that we can more easily
have an alternative main program." --GvR
"Delete goodname() method, which is unused. Add gotofileline(), a
convenience method which I intend to use in a
variant. Rename test() to _test()." --GvR
This was an interesting merge. The join completely missed removing
goodname(), which was adjacent, but outside of, a small conflict.
I only caught it by comparing the 1.1.3.2/1.1.3.3 diff. CVS ain't
infallible.
"Remove legacy support for the BrowserControl module; the webbrowser
module has been included since Python 2.0, and that is the preferred
interface." --fdrake
Merged the following py-cvs revs without conflict:
1.29 Reduce copyright text output at startup
1.30 Delay setting sys.args until Tkinter is fully initialized
1.31 Whitespace normalization
1.32 Turn syntax warning into error when interactive
1.33 Fix warning initialization bug
Note that module is extensively modified wrt py-cvs
VP IDLE version depended on VP's ExecBinding.py and spawn.py to get the
path to the Windows Doc directory (relative to python.exe). Removed this
conflicting code in favor of py-cvs updates which on Windows use a hard
coded path relative to the location of this module. py-cvs updates include
support for webbrowser.py. Module still has BrowserControl.py for 1.5.2
support.
At this point, the differences wrt py-cvs relate to menu functionality.
decode(): While writing tests for uu.py, Nick Mathewson discovered
that the 'Truncated input file' exception could never get raised,
because its "if not str:" test was actually testing the builtin
function "str", not the local string vrbl "s" as intended.
Bugfix candidate.
fixed. Regrettably, this must be run manually -- somehow the I/O
redirection of the regression test breaks the test. When run under
the regression test, this raises ImportError with a warning to that
effect.
Bugfix candidate!
Fix various serious problems:
- The ThreadingTCPServer class and its derived classes were completely
broken because the main thread would close the request before the
handler thread had time to look at it. This was introduced by
Ping's close_request() patch. The fix moves the close_request()
calls to after the handler has run to completion in the BaseServer
class and the ForkingMixIn class; when using the ThreadingMixIn,
closing the request is the handler's responsibility.
- The ForkingUDPServer class has always been been broken because the
socket was closed in the child before calling the handler. I fixed
this by simply not calling server_close() in the child at all.
- I cannot get the UnixDatagramServer class to work at all. The
recvfrom() call doesn't return a meaningful client address. I added
a comment to this effect. Maybe it works on other Unix versions.
- The __all__ variable was missing ThreadingMixIn and ForkingMixIn.
- Bumped __version__ to "0.4".
- Added a note about the test suite (to be checked in shortly).
solver. In conjunction, they easily found a tour of a 200x200 board:
that's 200**2 == 40,000 levels of backtracking. Explicitly resumable
generators allow that to be coded as easily as a recursive solver (easier,
actually, because different levels can use level-customized algorithms
without pain), but without blowing the stack. Indeed, I've never written
an exhaustive Tour solver in any language before that can handle boards so
large ("exhaustive" == guaranteed to find a solution if one exists, as
opposed to probabilistic heuristic approaches; of course, the age of the
universe may be a blip in the time needed!).
We should not depend on two spaces between words, so use the white
space after the to-be-encoded word only as lookahead and don't
actually consume it in the regular expression.
committed.
tokenize.py: I like these changes, and have tested them extensively
without even realizing it, so I just updated the docstring and the docs.
tabnanny.py: Also liked this, but did a little code fiddling. I should
really rewrite this to *exploit* generators, but that's near the bottom
of my effort/benefit scale so doubt I'll get to it anytime soon (it
would be most useful as a non-trivial example of ideal use of generators;
but test_generators.py has already grown plenty of food-for-thought
examples).
inspect.py: I'm sure Ping intended for this to continue running even
under 1.5.2, so I reverted this to the last pre-gen-branch version. The
"bugfix" I checked in in-between was actually repairing a bug *introduced*
by the conversion to generators, so it's OK that the reverted version
doesn't reflect that checkin.
class FieldStorage: this patch changes read_lines() and co. to use a
StringIO() instead of a real file. The write() calls are redirected
to a private method that replaces it with a real, external file only
when it gets too big (> 1000 bytes).
This avoids problems in forms using the multipart/form-data encoding
with many fields. The original code created a temporary file for
*every* field (not just for file upload fields), thereby sometimes
exceeding the open file limit of some systems.
Note that the simpler solution "use a real file only for file uploads"
can't be used because the form field parser has no way to tell which
fields correspond to file uploads.
It's *possible* but extremely unlikely that this would break someone's
code; they would have to be stepping way outside the documented
interface for FieldStorage and use f.file.fileno(), or depend on
overriding make_file() to return a file-like object with additional
known properties.
examples of use. These poke stuff not specifically targeted before, incl.
recursive local generators relying on nested scopes, ditto but also
inside class methods and rebinding instance vars, and anonymous
partially-evaluated generators (the N-Queens solver creates a different
column-generator for each row -- AFAIK this is my invention, and it's
really pretty <wink>). No problems, not even a new leak.
"return expr" instances in generators (which latter may be generators
due to otherwise invisible "yield" stmts hiding in "if 0" blocks).
This was fun the first time, but this has gotten truly ugly now.
that required explicitly calling LazyList.clear() in the two tests that
use LazyList (I added a LazyList Fibonacci generator too).
A real bitch: the extremely inefficient first version of the 2-3-5 test
*looked* like a slow leak on Win98SE, but it wasn't "really": it generated
so many results that the heap grew over 4Mb (tons of frames! the number
of frames grows exponentially in that test). Then Win98SE malloc() starts
fragmenting address space allocating more and more heaps, and the visible
memory use grew very slowly while the disk was thrashing like mad.
Printing fewer results (i.e., keeping the heap burden under 4Mb) made
that illusion vanish.
Looks like there's no hope for plugging the LazyList leaks automatically
short of adding frameobjects and genobjects to gc. OTOH, they're very
easy to break by hand, and they're the only *kind* of plausibly realistic
leaks I've been able to provoke.
Dilemma.
Implement sys.maxunicode.
Explicitly wrap around upper/lower computations for wide Py_UNICODE.
When decoding large characters with UTF-8, represent expected test
results using the \U notation.