Commit Graph

6609 Commits

Author SHA1 Message Date
Tim Peters 334b4a5c39 Gave __xor__/symmetric_difference a factor of 2-5 speed boost. 2002-08-25 19:47:54 +00:00
Tim Peters 37faed2532 Sped union by a factor of 3-4. 2002-08-25 19:21:27 +00:00
Tim Peters d33e6be59d Sped intersection by large factors (3-5x faster than before on sets of
cardinality 500; and the smaller the intersection, the bigger the speedup).
2002-08-25 19:12:45 +00:00
Tim Peters 4a2f91e302 Added a clue about why xyz_update isn't the same as __xyz__. 2002-08-25 18:59:04 +00:00
Tim Peters ea76c98014 Implemented <, <=, >, >= for sets, giving subset and proper-subset
meanings.  I did not add new, e.g., ispropersubset() methods; we're
going nuts on those, and, e.g., there was no "friendly name" for
== either.
2002-08-25 18:43:10 +00:00
Tim Peters 93d8d48c15 TestSubset(): Generalized the framework to support testing upcoming
<, <=, etc methods too.
2002-08-25 18:21:47 +00:00
Tim Peters 4127e91d20 Rewrote all remaining assert stmts. 2002-08-25 18:02:29 +00:00
Tim Peters 62c62438ff Simplified construction of the test suite. 2002-08-25 17:49:04 +00:00
Tim Peters de830ca4eb Simplified code building sets of characters. 2002-08-25 17:40:29 +00:00
Tim Peters a777799040 Ack! Virtually every test here relied on an assert stmt. assert stmts
should never be used in tests.  Repaired dozens, but more is needed.
2002-08-25 17:38:49 +00:00
Tim Peters 0bbb30830c Simplified the setup for is-subset testing. 2002-08-25 17:22:23 +00:00
Tim Peters 4924db176b Record a clue about why __or__ is not union, etc. 2002-08-25 17:10:17 +00:00
Raymond Hettinger c8f8034512 Replace 0 with False to match working in documentation. SF 599681. 2002-08-25 16:36:49 +00:00
Kurt B. Kaiser adc63847e4 1. Revert subprocess environment clearing, will restart subprocess
instead.
2. Preserve the Idle client's listening socket for reuse with the
   fresh subprocess.
3. Remove some unused rpc code, comment out additional unused code.

Modified Files:
ScriptBinding.py rpc.py run.py
2002-08-25 14:08:07 +00:00
Kurt B. Kaiser a552e3a0c9 Improve exception handling across rpc interface
Modified Files:
 	rpc.py
2002-08-24 23:57:17 +00:00
Raymond Hettinger e87ab3fefe Removed < <= > >= from the API. Implemented as comparisons of the
underlying dictionaries, there were no reasonable use cases (lexicographic
sorting of a list of sets is somewhat esoteric).  Frees the operators
for other uses (such as strict subset and superset comparisons).

Updated documentation and test suite accordingly.
2002-08-24 07:33:06 +00:00
Guido van Rossum 9d6897accc Speed up the most egregious "if token in (long tuple)" cases by using
a dict instead.  (Alas, using a Set would be slower instead of
faster.)
2002-08-24 06:54:19 +00:00
Raymond Hettinger 1b9f5d4c1a At Tim Peter's suggestion, propagated GvR's binary operator changes to
the inplace operators.  The strategy is to have the operator overloading
code do the work and then to define equivalent method calls which rely on
the operators.  The changes facilitate proper application of TypeError
and NonImplementedErrors.

Added corresponding tests to the test suite to make sure both the operator
and method call versions get exercised.

Add missing tests for difference_update().
2002-08-24 06:19:02 +00:00
Raymond Hettinger d50185127f Since instances of _TemporarilyImmutableSet are always thrown away
immediately after the comparison, there in no use in caching the hashcode.
The test, 'if self._hashcode is None', never fails.  Removing the caching
saves a few lines and a little time.
2002-08-24 04:47:42 +00:00
Raymond Hettinger 045e51a9a5 Expanded tests for sets of sets. 2002-08-24 02:56:01 +00:00
Raymond Hettinger fa1480f686 1. Removed module self test in favor of unittests -- Timbot's suggestion.
2. Replaced calls to Set([]) with Set() -- Timbot's suggestion
3. Fixed subtle bug in sets of sets:

The following code did not work (will add to test suite):
    d = Set('d')
    s = Set([d])  # Stores inner set as an ImmutableSet
    s.remove(d)   # For comparison, wraps d in _TemporarilyImmutableSet

The comparison proceeds by computing the hash of the
_TemporarilyImmutableSet and finding it in the dictionary.
It then verifies equality by calling ImmutableSet.__eq__()
and crashes from the binary sanity check.

The problem is that the code assumed equality would be checked
with _TemporarilyImmutableSet.__eq__().

The solution is to let _TemporarilyImmutableSet derive from BaseSet
so it will pass the sanity check and then to provide it with the
._data element from the wrapped set so that ImmutableSet.__eq__()
will find ._data where it expects.

Since ._data is now provided and because BaseSet is the base class,
_TemporarilyImmutableSet no longer needs .__eq__() or .__ne__().

Note that inheriting all of BaseSet's methods is harmless because
none of those methods (except ones starting with an underscore)
can mutate the .data element.  Also _TemporarilyImmutableSet is only
used internally as is not otherwise visible.
2002-08-24 02:35:48 +00:00
Tim Peters 53506be258 pop() docstring: this isn't a randomly-chosen element, it's merely
arbitrary.  I already changed the docs for this.
2002-08-23 20:36:58 +00:00
Tim Peters d06d03041b Comment repair. 2002-08-23 20:06:42 +00:00
Guido van Rossum 2023c9b84a Fix SF bug 599128, submitted by Inyeol Lee: .replace() would do the
wrong thing for a unicode subclass when there were zero string
replacements.  The example given in the SF bug report was only one way
to trigger this; replacing a string of length >= 2 that's not found is
another.  The code would actually write outside allocated memory if
replacement string was longer than the search string.

(I wonder how many more of these are lurking?  The unicode code base
is full of wonders.)

Bugfix candidate; this same bug is present in 2.2.1.
2002-08-23 18:50:21 +00:00
Guido van Rossum 8b1a6d694f Code by Inyeol Lee, submitted to SF bug 595350, to implement
the string/unicode method .replace() with a zero-lengt first argument.
Inyeol contributed tests for this too.
2002-08-23 18:21:28 +00:00
Tim Peters 280488b9a3 Whitespace normalization. 2002-08-23 18:19:30 +00:00
Tim Peters 7c7efe9073 Got rid of the toy _Set class, in favor of sets.Set. 2002-08-23 17:55:54 +00:00
Guido van Rossum e399d08a4a RH pointed out that discard(element) doesn't do the transformation on
the element if necessary.  Fixed by calling self.remove(element).
2002-08-23 14:45:02 +00:00
Jack Jansen b2628b0f37 Added the standard MacOSX location for documentation inside a framework
to the list of places where pydoc looks for HTML documents.
2002-08-23 08:40:42 +00:00
Guido van Rossum 040d7ca498 Rewritten using the tokenize module, which gives us a real tokenizer
rather than a number of approximating regular expressions.
Alas, it is 3-4 times slower.  Let that be a challenge for the
tokenize module.
2002-08-23 01:36:01 +00:00
Greg Ward e3bd104aa7 Tweak wordsep_re again: this time to recognize an em-dash with
any non-whitespace characters adjacent, not just \w.
2002-08-22 21:28:00 +00:00
Greg Ward c6edb37268 Test an em-dash with adjacent punctuation. 2002-08-22 21:27:05 +00:00
Greg Ward 715debd3d1 Factored out BaseTestCase.check_split() method -- use it wherever
we need to test TextWrapper._split().
2002-08-22 21:16:25 +00:00
Greg Ward 24a1c9cff5 Test _split() method in test_unix_options(). 2002-08-22 21:12:54 +00:00
Greg Ward 34f995b3c1 Add test_unix_options() to WrapTestCase to test for SF bug #596434. 2002-08-22 21:10:07 +00:00
Greg Ward cce4d67fc4 Fix SF bug #596434: tweak wordsep_re so "--foo-bar" now splits
into /--foo-/bar/ rather than /--/foo-/bar/.  Needed for Optik and
Docutils to handle Unix-style command-line options properly.
2002-08-22 21:04:21 +00:00
Guido van Rossum ae4693129a Standardize behavior: no docstrings in test functions. 2002-08-22 20:22:16 +00:00
Guido van Rossum 9eee554bd9 Standardize behavior: no docstrings in test functions. Also use
unittest.makeSuite() rather than loader.loadTestsFromTestCase().
2002-08-22 20:21:30 +00:00
Guido van Rossum 327af775b8 Standardize behavior: no docstrings in test functions. Also strip
trailing whitespace.
2002-08-22 20:13:47 +00:00
Guido van Rossum 1c48654e01 Document that docstrings are verboten for test functions.
Expand the example to show some actual test functions, and a setUp()
and tearDown() method.
2002-08-22 20:08:14 +00:00
Guido van Rossum 8ccd9b63cc Standardize behavior: no docstrings in test functions. Also get rid
of dummy_test_TemporaryFile class; when NamedTemporaryFile and
TemporaryFile are the same, simply don't add a test suite for
TemporaryFile.
2002-08-22 20:02:03 +00:00
Guido van Rossum a5ce2e8c17 Standardize behavior: no docstrings in test functions; add a proper
test_main() that creates a suite and runs it.  Don't mess with sys.path!!!
2002-08-22 19:57:50 +00:00
Greg Ward 9ad15a3dff Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
em-dashes -- like this -- properly.  (Also--like this.  Although this
usage may be incompatible with fixing bug #596434; we shall see.)
2002-08-22 19:47:27 +00:00
Guido van Rossum 32c2ae7f4a Standardize behavior: no docstrings in test functions. 2002-08-22 19:45:32 +00:00
Guido van Rossum 2e8bba5c21 Standardize behavior: create a single suite merging all test cases. 2002-08-22 19:40:33 +00:00
Guido van Rossum 7e8fdba01c Standardize behavior: no docstrings in test functions; create a single
suite merging all test cases.
2002-08-22 19:38:14 +00:00
Guido van Rossum cb682584a3 Made it more readable. 2002-08-22 19:18:56 +00:00
Greg Ward f69d3c9849 Simplification/cleanup in IndentTestCases. 2002-08-22 19:06:45 +00:00
Greg Ward fd030e46a7 Factor LongWordTestCase out of WrapTestCase, and rename its methods
(tests) from test_funky_punc() to test_break_long() and
test_long_words() to test_nobreak_long().
2002-08-22 19:02:37 +00:00
Greg Ward 13c53c64db Rename base test case class to (yawn) BaseTestCase. 2002-08-22 18:57:26 +00:00
Greg Ward ee413849b5 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
base class (WrapperTestCase) instead, and call it repeatedly in the
methods that used to have a loop-over-subcases.  Much simpler.

Rename perennial temp variable 't' to 'text'.
2002-08-22 18:55:38 +00:00
Greg Ward 9ebba9ace3 Simplify and reformat the use of 'subcases' lists (and following
for-loops) in test_simple(), test_wrap_short() test_hyphenated(), and
test_funky_punc().
2002-08-22 18:45:02 +00:00
Greg Ward 3dc94e14c0 Add comment header block.
Remove some useless comments (redundant, or info presumably available in
  PyUnit docs).
2002-08-22 18:37:50 +00:00
Greg Ward f67657811c Conform to standards documented in README:
*  lowercase test*() methods
  * define test_main() and use it instead of unittest.main()
Kill #! line.
Improve some test names and docstrings.
2002-08-22 18:35:49 +00:00
Greg Ward 90c0b071ed Test script for the textwrap module. Kindly provided by Peter Hansen
<peter@engcorp.com> based on a test script that's been kicking around my
home directory for a couple of months now and only saw the light of day
because I included it when I sent textwrap.py to python-dev for review.
2002-08-22 18:11:10 +00:00
Guido van Rossum dbfb12148d On Windows, make sure SocketType is the same as socket. (SF bug
598097)
2002-08-22 17:31:16 +00:00
Guido van Rossum dc61cdf6c0 Change the binary operators |, &, ^, - to return NotImplemented rather
than raising TypeError when the other argument is not a BaseSet.  This
made it necessary to separate the implementation of e.g. __or__ from
the union method; the latter should not return NotImplemented but
raise TypeError.  This is accomplished by making union(self, other)
return self|other, etc.; Python's binary operator machinery will raise
TypeError.

The idea behind this change is to allow other set implementations with
an incompatible internal structure; these can provide union (etc.) with
standard sets by implementing __ror__ etc.

I wish I could do this for comparisons too, but the default comparison
implementation allows comparing anything to anything else (returning
false); we don't want that (at least the test suite makes sure
e.g. Set()==42 raises TypeError).  That's probably fine; otherwise
other set implementations would be constrained to implementing a hash
that's compatible with ours.
2002-08-22 17:23:33 +00:00
Fred Drake 61cf4407be Added a main() function and support to run this module as a script.
Closes SF feature request #588768.
2002-08-21 20:56:21 +00:00
Fred Drake a96f1a3c08 Refactor: Remove some code that was obsoleted when this module was
changed to use universal newlines.

           Remove all imports from the compile() function; these are
           now done at the top of the module ("Python normal form"),
           and define a helper based on the platform instead of
           testing the platform in the compile() function.
2002-08-21 20:23:22 +00:00
Raymond Hettinger d9c9151a53 Now that __init__ transforms set elements, we know that all of the
elements are hashable, so we can use dict.update() or dict.copy()
for a C speed Set.copy().
2002-08-21 13:20:51 +00:00
Raymond Hettinger c3e61e5c52 Add regression test for proper construction of sets of sets. 2002-08-21 06:38:44 +00:00
Raymond Hettinger 80d21af614 Sped ._update() method by factoring try/except out of the inner loop. 2002-08-21 04:12:03 +00:00
Guido van Rossum 9f87293bf5 Ouch. The test suite *really* needs work!!!!! There were several
superficial errors and one deep one that aren't currently caught.  I'm
headed for bed after this checkin.

- Fixed several typos introduced by Raymond Hettinger (through
  cut-n-paste from my template): it's _as_temporarily_immutable, not
  _as_temporary_immutable, and moreover when the element is added, we
  should use _as_immutable.

- Made the seq argument to ImmutableSet.__init__ optional, so we can
  write ImmutableSet() to create an immutable empty set.

- Rename the seq argument to Set and ImmutableSet to iterable.

- Add a Set.__hash__ method that raises a TypeError.  We inherit a
  default __hash__ implementation from object, and we don't want that.
  We can then catch this in update(), so that
  e.g. s.update([Set([1])]) will transform the Set([1]) to
  ImmutableSet([1]).

- Added the dance to catch TypeError and try _as_immutable in the
  constructors too (by calling _update()).  This is needed so that
  Set([Set([1])]) is correctly interpreted as
  Set([ImmutableSet([1])]).  (I was puzzled by a side effect of this
  and the inherited __hash__ when comparing two sets of sets while
  testing different powerset implementations: the Set element passed
  to a Set constructor wasn't transformed to an ImmutableSet, and then
  the dictionary didn't believe the Set found in one dict it was the
  same as ImmutableSet in the other, because the hashes were
  different.)

- Refactored Set.update() and both __init__() methods; moved the body
  of update() into BaseSet as _update(), and call this from __init__()
  and update().

- Changed the NotImplementedError in BaseSet.__init__ to TypeError,
  both for consistency with basestring() and because we have to use
  TypeError when denying Set.__hash__.  Together those provide
  sufficient evidence that an unimplemented method needs to raise
  TypeError.
2002-08-21 03:20:44 +00:00
Guido van Rossum 26588222b3 Add Raymond H to the list of authors; add some XXX comments about
possible API improvements.
2002-08-21 02:44:04 +00:00
Raymond Hettinger 43db0d6a2c Fast size check for sub/super set tests 2002-08-21 02:22:08 +00:00
Raymond Hettinger de6d697987 Optimize try/except ordering in sets.py.
Gains a 5:1 speed-up for membership testing by
handling the most common case first (the case
where the element is hashable).

Closes SF Patch 597444.
2002-08-21 01:35:29 +00:00
Raymond Hettinger ede3a0da8b Minor typo 2002-08-20 23:34:01 +00:00
Guido van Rossum c9196bc88d Rename popitem() to pop(). (An idea from SF patch 597444.) 2002-08-20 21:51:59 +00:00
Guido van Rossum 5033b36c44 Move __init__ from BaseSet into Set and ImmutableSet. This causes a
tiny amount of code duplication, but makes it possible to give BaseSet
an __init__ that raises an exception.
2002-08-20 21:38:37 +00:00
Guido van Rossum e3ec296df8 Typo repair. Please include in any backports. 2002-08-20 20:07:10 +00:00
Guido van Rossum 290f1870f1 Add a note reminding the reader that sets are not sequences. I
received feedback that was based in the misunderstanding that sets
were sequences.
2002-08-20 20:05:23 +00:00
Guido van Rossum 0bd7832285 SF patch 595846 by Brett Cannon: Update environ for CGIHTTPServer.py
This patch causes CGIHTTPServer to update os.environ regardless of how
it tries to handle calls (fork, popen*, etc.).

Backport bugfix candidate.
2002-08-20 19:55:06 +00:00
Guido van Rossum 76afbd9aa4 Fix some endcase bugs in unicode rfind()/rindex() and endswith().
These were reported and fixed by Inyeol Lee in SF bug 595350.  The
endswith() bug was already fixed in 2.3, but this adds some more test
cases.
2002-08-20 17:29:29 +00:00
Barry Warsaw 4d5ef6aed6 Bump version number to 2.3 2002-08-20 14:51:34 +00:00
Barry Warsaw 3328136e3c Added tests for SF patch #597593, syntactically invalid Content-Type: headers. 2002-08-20 14:51:10 +00:00
Barry Warsaw f36d804b3b get_content_type(), get_content_maintype(), get_content_subtype(): RFC
2045, section 5.2 states that if the Content-Type: header is
syntactically invalid, the default type should be text/plain.
Implement minimal sanity checking of the header -- it must have
exactly one slash in it.  This closes SF patch #597593 by Skip, but in
a different way.

Note that these methods used to raise ValueError for invalid ctypes,
but now they won't.
2002-08-20 14:50:09 +00:00
Barry Warsaw dfea3b3963 _dispatch(): Use get_content_maintype() and get_content_subtype() to
get the MIME main and sub types, instead of getting the whole ctype
and splitting it here.   The two more specific methods now correctly
implement RFC 2045, section 5.2.
2002-08-20 14:47:30 +00:00
Barry Warsaw b404bb7813 test_three_lines(): Test case reported by Andrew McNamara. Works in
email 2.2 but fails in email 1.0.
2002-08-20 12:54:07 +00:00
Guido van Rossum 0b650d7565 Fix typo in __slots__ of ImmutableSet. 2002-08-19 16:29:58 +00:00
Guido van Rossum d6cf3af8f7 Set classes and their unit tests, from sandbox. 2002-08-19 16:19:15 +00:00
Raymond Hettinger 5959c559df Added __pow__(a,b) to the operator module. Completes the pattern of
all operators having a counterpart in the operator module.

Closes SF bug #577513.
2002-08-19 03:19:09 +00:00
Raymond Hettinger f2e45dd9dd Modify splituser() method to allow an @ in the userinfo field.
Jeremy reported that this is not allowed by RFC 2396; however,
other tools support unescaped @'s so we should also.

Apply SF patch 596581 closing bug 581529.
2002-08-18 20:08:56 +00:00
Andrew MacIntyre 1d0eeec279 OS/2 EMX behaves like Windows where file permissions are concerned 2002-08-18 06:47:19 +00:00
Guido van Rossum e888cdc683 Get rid of _once(); inlining it takes less code. :-)
Also, don't call gettempdir() in the default expression for the 'dir'
argument to various functions; use 'dir=None' for the default and
insert 'if dir is None: dir = gettemptir()' in the bodies.  That way
the work done by gettempdir is postponed until needed.
2002-08-17 14:50:24 +00:00
Guido van Rossum 787410680b Patch by Zack W to make test_noinherit() more robust: spawn a Python
subprocess that does the right checks.  This now works on Windows as
well.
2002-08-17 11:41:01 +00:00
Neal Norwitz 68ee0128a2 Drop the number of test files to 100 for all the tests 2002-08-16 19:28:59 +00:00
Tim Peters 9146f27b77 SF bug 594996: OverflowError in random.randrange
Loosened the acceptable 'start' and 'stop' arguments so that any
Python (bounded) ints can be used.  So, e.g., randrange(-sys.maxint-1,
sys.maxint) no longer blows up.
2002-08-16 03:41:39 +00:00
Tim Peters 80703c8930 check_events(): This was failing under -O, due to not expecting any
LINE events when not __debug__.  But we get them anyway under -O now,
so just stop special-casing non-__debug__ mode.
2002-08-16 02:27:15 +00:00
Barry Warsaw 0a51b58e6b base64.decodestring('') should return '' instead of raising an
exception.  The bug fix for SF #430849 wasn't quite right.  This
closes SF bug #595671.  I'll backport this to Python 2.2.
2002-08-15 22:14:24 +00:00
Michael W. Hudson dd32a91cc0 This is my patch
[ 587993 ] SET_LINENO killer

Remove SET_LINENO.  Tracing is now supported by inspecting co_lnotab.

Many sundry changes to document and adapt to this change.
2002-08-15 14:59:02 +00:00
Skip Montanaro 8c91337221 forgot the best part - the new tests...
see patch 586561
2002-08-15 01:28:54 +00:00
Jeremy Hylton 92bb6e7b96 Docstring nits: The module is neither proposed nor new. 2002-08-14 19:25:42 +00:00
Guido van Rossum 54df53a352 More changes of DeprecationWarning to FutureWarning. 2002-08-14 18:38:27 +00:00
Jeremy Hylton 29c2106465 Explain use of currentThread() in _Condition methods. 2002-08-14 17:56:13 +00:00
Guido van Rossum 88b1defb6f The filterwarnings() call here should be updated to filter out
FutureWarning.
2002-08-14 17:54:48 +00:00
Jeremy Hylton 39c12bfba1 Explain a little more. 2002-08-14 17:46:40 +00:00
Jeremy Hylton af7fde7f34 Explain a minor mystery. 2002-08-14 17:43:59 +00:00
Tim Peters 04490bf225 tempfile's mkstemp(): Changed last argument from
binary=True
to
    text=False

by BDFL Pronouncement.  All other changes follow from this.  The change
to the docs is ready to go, but blocked by another JackMacLock in the
doc directory.
2002-08-14 15:41:26 +00:00
Jason Tishler 80c02af345 Patch #595014: Cygwin tempfile patch
Although Cygwin attempts to be as Posix compliant
as possible, it has difficulties unlinking open
files. This is not surprising given that Cygwin is
dependent on Win32 which in turn has this problem
itself.

The attached tempfile patch acknowledges this
Cygwin limitation. Without this patch, Cygwin
fails test_tempfile (i.e., test_has_no_name) as
follows:

$ ./python -E -tt ../Lib/test/regrtest.py -l test_tempfile
test_tempfile
test test_tempfile failed -- Traceback (most recent call last):
  File "/home/jt/src/PythonCvs/Lib/test/test_tempfile.py", line 689, in test_has_no_name
    self.failOnException("rmdir", ei)
  File "/home/jt/src/PythonCvs/Lib/test/test_tempfile.py", line 33, in failOnException
    self.fail("%s raised %s: %s" % (what, ei[0], ei[1]))
  File "/home/jt/src/PythonCvs/Lib/unittest.py", line 260, in fail
    raise self.failureException, msg
AssertionError: rmdir raised exceptions.OSError: [Errno 90] Directory not empty: '/mnt/c/DOCUME~1/jatis/LOCALS~1/Temp/tmpM_z8nj'
2002-08-14 15:10:09 +00:00
Barry Warsaw 09707e3637 Patch by Tim to shut up the compiler's DeprecationWarnings on the
high-bit-set hex constants.
2002-08-14 15:09:12 +00:00