diff options
author | Georg Brandl <georg@python.org> | 2013-03-25 06:01:37 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2013-03-25 06:01:37 (GMT) |
commit | a809e4a54007303efb084b85ba53605adaa41b64 (patch) | |
tree | d038bc1b85b83594b29f00ae5bc10b5290ffdf71 /Lib | |
parent | d08d0b1c69b19c58afb998e30eadfc7b9de26378 (diff) | |
parent | 153866ea9ab80323d247a9c49d1fdf50e07e7330 (diff) | |
download | cpython-a809e4a54007303efb084b85ba53605adaa41b64.zip cpython-a809e4a54007303efb084b85ba53605adaa41b64.tar.gz cpython-a809e4a54007303efb084b85ba53605adaa41b64.tar.bz2 |
merge with upstream 3.3 branchv3.3.1rc1
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/collections/abc.py | 68 | ||||
-rw-r--r-- | Lib/subprocess.py | 18 | ||||
-rw-r--r-- | Lib/test/test_queue.py | 5 | ||||
-rw-r--r-- | Lib/test/test_subprocess.py | 28 | ||||
-rw-r--r-- | Lib/unittest/mock.py | 3 | ||||
-rw-r--r-- | Lib/webbrowser.py | 6 |
6 files changed, 115 insertions, 13 deletions
diff --git a/Lib/collections/abc.py b/Lib/collections/abc.py index c23b7dd..7939268 100644 --- a/Lib/collections/abc.py +++ b/Lib/collections/abc.py @@ -90,6 +90,7 @@ class Iterator(Iterable): @abstractmethod def __next__(self): + 'Return the next item from the iterator. When exhausted, raise StopIteration' raise StopIteration def __iter__(self): @@ -230,6 +231,7 @@ class Set(Sized, Iterable, Container): return self._from_iterable(value for value in other if value in self) def isdisjoint(self, other): + 'Return True if two sets have a null intersection.' for value in other: if value in self: return False @@ -292,6 +294,16 @@ Set.register(frozenset) class MutableSet(Set): + """A mutable set is a finite, iterable container. + + This class provides concrete generic implementations of all + methods except for __contains__, __iter__, __len__, + add(), and discard(). + + To override the comparisons (presumably for speed, as the + semantics are fixed), all you have to do is redefine __le__ and + then the other operations will automatically follow suit. + """ __slots__ = () @@ -370,11 +382,20 @@ class Mapping(Sized, Iterable, Container): __slots__ = () + """A Mapping is a generic container for associating key/value + pairs. + + This class provides concrete generic implementations of all + methods except for __getitem__, __iter__, and __len__. + + """ + @abstractmethod def __getitem__(self, key): raise KeyError def get(self, key, default=None): + 'D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.' try: return self[key] except KeyError: @@ -389,12 +410,15 @@ class Mapping(Sized, Iterable, Container): return True def keys(self): + "D.keys() -> a set-like object providing a view on D's keys" return KeysView(self) def items(self): + "D.items() -> a set-like object providing a view on D's items" return ItemsView(self) def values(self): + "D.values() -> an object providing a view on D's values" return ValuesView(self) def __eq__(self, other): @@ -477,6 +501,15 @@ class MutableMapping(Mapping): __slots__ = () + """A MutableMapping is a generic container for associating + key/value pairs. + + This class provides concrete generic implementations of all + methods except for __getitem__, __setitem__, __delitem__, + __iter__, and __len__. + + """ + @abstractmethod def __setitem__(self, key, value): raise KeyError @@ -488,6 +521,9 @@ class MutableMapping(Mapping): __marker = object() def pop(self, key, default=__marker): + '''D.pop(k[,d]) -> v, remove specified key and return the corresponding value. + If key is not found, d is returned if given, otherwise KeyError is raised. + ''' try: value = self[key] except KeyError: @@ -499,6 +535,9 @@ class MutableMapping(Mapping): return value def popitem(self): + '''D.popitem() -> (k, v), remove and return some (key, value) pair + as a 2-tuple; but raise KeyError if D is empty. + ''' try: key = next(iter(self)) except StopIteration: @@ -508,6 +547,7 @@ class MutableMapping(Mapping): return key, value def clear(self): + 'D.clear() -> None. Remove all items from D.' try: while True: self.popitem() @@ -515,6 +555,11 @@ class MutableMapping(Mapping): pass def update(*args, **kwds): + ''' D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. + If E present and has a .keys() method, does: for k in E: D[k] = E[k] + If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v + In either case, this is followed by: for k, v in F.items(): D[k] = v + ''' if len(args) > 2: raise TypeError("update() takes at most 2 positional " "arguments ({} given)".format(len(args))) @@ -536,6 +581,7 @@ class MutableMapping(Mapping): self[key] = value def setdefault(self, key, default=None): + 'D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D' try: return self[key] except KeyError: @@ -583,12 +629,16 @@ class Sequence(Sized, Iterable, Container): yield self[i] def index(self, value): + '''S.index(value) -> integer -- return first index of value. + Raises ValueError if the value is not present. + ''' for i, v in enumerate(self): if v == value: return i raise ValueError def count(self, value): + 'S.count(value) -> integer -- return number of occurrences of value' return sum(1 for v in self if v == value) Sequence.register(tuple) @@ -613,6 +663,13 @@ class MutableSequence(Sequence): __slots__ = () + """All the operations on a read-only sequence. + + Concrete subclasses must provide __new__ or __init__, + __getitem__, __setitem__, __delitem__, __len__, and insert(). + + """ + @abstractmethod def __setitem__(self, index, value): raise IndexError @@ -623,12 +680,15 @@ class MutableSequence(Sequence): @abstractmethod def insert(self, index, value): + 'S.insert(index, value) -- insert value before index' raise IndexError def append(self, value): + 'S.append(value) -- append value to the end of the sequence' self.insert(len(self), value) def clear(self): + 'S.clear() -> None -- remove all items from S' try: while True: self.pop() @@ -636,20 +696,28 @@ class MutableSequence(Sequence): pass def reverse(self): + 'S.reverse() -- reverse *IN PLACE*' n = len(self) for i in range(n//2): self[i], self[n-i-1] = self[n-i-1], self[i] def extend(self, values): + 'S.extend(iterable) -- extend sequence by appending elements from the iterable' for v in values: self.append(v) def pop(self, index=-1): + '''S.pop([index]) -> item -- remove and return item at index (default last). + Raise IndexError if list is empty or index is out of range. + ''' v = self[index] del self[index] return v def remove(self, value): + '''S.remove(value) -- remove first occurrence of value. + Raise ValueError if the value is not present. + ''' del self[self.index(value)] def __iadd__(self, values): diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 773f3e8..689046e 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -25,7 +25,7 @@ Using the subprocess module =========================== This module defines one class called Popen: -class Popen(args, bufsize=0, executable=None, +class Popen(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=False, cwd=None, env=None, universal_newlines=False, @@ -56,12 +56,12 @@ not all MS Windows applications interpret the command line the same way: The list2cmdline is designed for applications using the same rules as the MS C runtime. -bufsize, if given, has the same meaning as the corresponding argument -to the built-in open() function: 0 means unbuffered, 1 means line -buffered, any other positive value means use a buffer of -(approximately) that size. A negative bufsize means to use the system -default, which usually means fully buffered. The default value for -bufsize is 0 (unbuffered). +bufsize will be supplied as the corresponding argument to the io.open() +function when creating the stdin/stdout/stderr pipe file objects: +0 means unbuffered (read & write are one system call and can return short), +1 means line buffered, any other positive value means use a buffer of +approximately that size. A negative bufsize, the default, means the system +default of io.DEFAULT_BUFFER_SIZE will be used. stdin, stdout and stderr specify the executed programs' standard input, standard output and standard error file handles, respectively. @@ -711,7 +711,7 @@ _PLATFORM_DEFAULT_CLOSE_FDS = object() class Popen(object): - def __init__(self, args, bufsize=0, executable=None, + def __init__(self, args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS, shell=False, cwd=None, env=None, universal_newlines=False, @@ -725,7 +725,7 @@ class Popen(object): self._input = None self._communication_started = False if bufsize is None: - bufsize = 0 # Restore default + bufsize = -1 # Restore default if not isinstance(bufsize, int): raise TypeError("bufsize must be an integer") diff --git a/Lib/test/test_queue.py b/Lib/test/test_queue.py index 86ad9c0..2cdfee4 100644 --- a/Lib/test/test_queue.py +++ b/Lib/test/test_queue.py @@ -46,6 +46,9 @@ class _TriggerThread(threading.Thread): class BlockingTestMixin: + def tearDown(self): + self.t = None + def do_blocking_test(self, block_func, block_args, trigger_func, trigger_args): self.t = _TriggerThread(trigger_func, trigger_args) self.t.start() @@ -260,7 +263,7 @@ class FailingQueue(queue.Queue): raise FailingQueueException("You Lose") return queue.Queue._get(self) -class FailingQueueTest(unittest.TestCase, BlockingTestMixin): +class FailingQueueTest(BlockingTestMixin, unittest.TestCase): def failing_queue_test(self, q): if q.qsize(): diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index e8e74ed..dd720fe 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -82,6 +82,34 @@ class PopenExecuteChildRaises(subprocess.Popen): class ProcessTestCase(BaseTestCase): + def test_io_buffered_by_default(self): + p = subprocess.Popen([sys.executable, "-c", "import sys; sys.exit(0)"], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + try: + self.assertIsInstance(p.stdin, io.BufferedIOBase) + self.assertIsInstance(p.stdout, io.BufferedIOBase) + self.assertIsInstance(p.stderr, io.BufferedIOBase) + finally: + p.stdin.close() + p.stdout.close() + p.stderr.close() + p.wait() + + def test_io_unbuffered_works(self): + p = subprocess.Popen([sys.executable, "-c", "import sys; sys.exit(0)"], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, bufsize=0) + try: + self.assertIsInstance(p.stdin, io.RawIOBase) + self.assertIsInstance(p.stdout, io.RawIOBase) + self.assertIsInstance(p.stderr, io.RawIOBase) + finally: + p.stdin.close() + p.stdout.close() + p.stderr.close() + p.wait() + def test_call_seq(self): # call() function with sequence argument rc = subprocess.call([sys.executable, "-c", diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 8361fde..57bf957 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -948,9 +948,6 @@ class Mock(CallableMixin, NonCallableMock): the next value from the iterable. If any of the members of the iterable are exceptions they will be raised instead of returned. - If `side_effect` is an iterable then each call to the mock will return - the next value from the iterable. - * `return_value`: The value returned when the mock is called. By default this is a new Mock (created on first access). See the `return_value` attribute. diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py index 94d4ad4..945eda4 100644 --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -468,9 +468,13 @@ def register_X_browsers(): if "KDE_FULL_SESSION" in os.environ and _iscommand("kfmclient"): register("kfmclient", Konqueror, Konqueror("kfmclient")) + if _iscommand("x-www-browser"): + register("x-www-browser", None, BackgroundBrowser("x-www-browser")) + # The Mozilla/Netscape browsers for browser in ("mozilla-firefox", "firefox", "mozilla-firebird", "firebird", + "iceweasel", "iceape", "seamonkey", "mozilla", "netscape"): if _iscommand(browser): register(browser, None, Mozilla(browser)) @@ -513,6 +517,8 @@ if os.environ.get("DISPLAY"): # Also try console browsers if os.environ.get("TERM"): + if _iscommand("www-browser"): + register("www-browser", None, GenericBrowser("www-browser")) # The Links/elinks browsers <http://artax.karlin.mff.cuni.cz/~mikulas/links/> if _iscommand("links"): register("links", None, GenericBrowser("links")) |