Commits

Armin Rigo committed 9b9a490 Merge

hg merge default

Comments (0)

Files changed (243)

     LineBreak-*.txt
     UnicodeData-*.txt
     UnihanNumeric-*.txt
+
+License for 'dotviewer/font/'
+=============================
+
+Copyright (C) 2008 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+  
+     http://www.apache.org/licenses/LICENSE-2.0
+  
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Detailled license information is contained in the NOTICE file in the
+directory.
+

dotviewer/VeraMoBd.ttf

Binary file removed.

dotviewer/cyrvetic.ttf

Binary file removed.

dotviewer/drawgraph.py

 from pygame.locals import *
 
 
+RAW_ENCODING = "utf-8"
 this_dir = os.path.dirname(os.path.abspath(__file__))
-FONT = os.path.join(this_dir, 'cyrvetic.ttf')
-FIXEDFONT = os.path.join(this_dir, 'VeraMoBd.ttf')
+FONT = os.path.join(this_dir, 'font', 'DroidSans.ttf')
+FIXEDFONT = os.path.join(this_dir, 'font', 'DroidSansMono.ttf')
 COLOR = {
     'black': (0,0,0),
     'white': (255,255,255),
     else:
         return default
 
+def forceunicode(name):
+    return name if isinstance(name, unicode) else name.decode(RAW_ENCODING)
+
+def forcestr(name):
+    return name if isinstance(name, str) else name.encode(RAW_ENCODING)
+
 
 class GraphLayout:
     fixedfont = False
 
 class Node:
     def __init__(self, name, x, y, w, h, label, style, shape, color, fillcolor):
-        self.name = name
+        self.name = forceunicode(name)
         self.x = float(x)
         self.y = float(y)
         self.w = float(w)
         self.h = float(h)
-        self.label = label
+        self.label = forceunicode(label)
         self.style = style
         self.shape = shape
         self.color = color
     label = None
     
     def __init__(self, nodes, tail, head, cnt, *rest):
-        self.tail = nodes[tail]
-        self.head = nodes[head]
+        self.tail = nodes[forceunicode(tail)]
+        self.head = nodes[forceunicode(head)]
         cnt = int(cnt)
         self.points = [(float(rest[i]), float(rest[i+1]))
                        for i in range(0, cnt*2, 2)]
             part = parts[i]
             word = part[0]
             try:
-                try:
-                    img = font.render(word, False, *part[1:])
-                except pygame.error, e:
-                    # Try *with* anti-aliasing to work around a bug in SDL
-                    img = font.render(word, True, *part[1:])
+                img = font.render(word, True, *part[1:])
             except pygame.error:
                 del parts[i]   # Text has zero width
             else:

dotviewer/font/DroidSans-Bold.ttf

Binary file added.

dotviewer/font/DroidSans.ttf

Binary file added.

dotviewer/font/DroidSansMono.ttf

Binary file added.

dotviewer/font/NOTICE

+
+   Copyright (c) 2005-2008, The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+

dotviewer/font/README.txt

+Copyright (C) 2008 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+  
+     http://www.apache.org/licenses/LICENSE-2.0
+  
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+##########
+
+This directory contains the fonts for the platform. They are licensed
+under the Apache 2 license.

dotviewer/graphclient.py

     def reload(graph_id):
         page = getpage(graph_id)
         if save_tmp_file:
+            from drawgraph import forcestr
             f = open(save_tmp_file, 'w')
-            f.write(page.source)
+            f.write(forcestr(page.source))
             f.close()
         messages.extend(page_messages(page, graph_id))
         send_graph_messages(io, messages)
 
 def page_messages(page, graph_id):
     import graphparse
-    return graphparse.parse_dot(graph_id, page.source, page.links,
+    from drawgraph import forcestr
+    return graphparse.parse_dot(graph_id, forcestr(page.source), page.links,
                                 getattr(page, 'fixedfont', False))
 
 def send_graph_messages(io, messages):

dotviewer/graphdisplay.py

 from pygame.locals import *
 from drawgraph import GraphRenderer, FIXEDFONT
 from drawgraph import Node, Edge
-from drawgraph import EventQueue, wait_for_events
+from drawgraph import EventQueue, wait_for_events, forceunicode, forcestr
 
 
 METAKEYS = dict([
                     if e.key == K_ESCAPE:
                         return None
                     elif e.key == K_RETURN:
-                        return text.encode('latin-1')   # XXX do better
+                        return forcestr(text) # return encoded unicode
                     elif e.key == K_BACKSPACE:
                         text = text[:-1]
                     elif e.unicode and ord(e.unicode) >= ord(' '):
         self.layout.request_reload()
 
     def setstatusbar(self, text, fgcolor=None, bgcolor=None):
-        info = (text, fgcolor or self.STATUSBAR_FGCOLOR, bgcolor or self.STATUSBAR_BGCOLOR)
+        info = (forceunicode(text), fgcolor or self.STATUSBAR_FGCOLOR, bgcolor or self.STATUSBAR_BGCOLOR)
         if info != self.statusbarinfo:
             self.statusbarinfo = info
             self.must_redraw = True
     lines = []
     while words:
         line = words.pop(0)
-        img = font.render(line or ' ', 1, fgcolor)
+        img = font.render(line or ' ', True, fgcolor)
         while words:
             longerline = line + ' ' + words[0]
             longerimg = font.render(longerline, 1, fgcolor)
             img = longerimg
         w, h = img.get_size()
         if h > maxheight:
-            img = font.render('...', 1, overflowcolor)
+            img = font.render('...', True, overflowcolor)
             w, h = img.get_size()
             while lines and h > maxheight:
                 maxheight += lines.pop().get_size()[1]

dotviewer/graphpage.py

 
 class DotFileGraphPage(GraphPage):
     def compute(self, dotfile):
-        f = open(dotfile, 'r')
+        import codecs
+        from drawgraph import RAW_ENCODING
+        f = codecs.open(dotfile, 'r', RAW_ENCODING)
         self.source = f.read()
         f.close()

dotviewer/test/test_interactive_unicode.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+import py
+import sys, os, signal, thread, time, codecs
+from dotviewer.conftest import option
+from dotviewer.drawgraph import RAW_ENCODING
+
+SOURCE1 = u"""digraph G{
+λ -> b
+b -> μ
+}
+"""
+
+FILENAME = 'graph1.dot'
+
+def setup_module(mod):
+    if not option.pygame:
+        py.test.skip("--pygame not enabled")
+    udir = py.path.local.make_numbered_dir(prefix='usession-dot-', keep=3)
+    f = codecs.open(str(udir.join(FILENAME)), 'wb', RAW_ENCODING)
+    f.write(SOURCE1)
+    f.close()
+
+    from dotviewer import graphclient
+    mod.pkgdir = py.path.local(graphclient.this_dir)
+    mod.udir = udir
+
+    try:
+        del os.environ['GRAPHSERVER']
+    except KeyError:
+        pass
+
+
+def test_dotviewer():
+    print "=== dotviewer.py %s" % FILENAME
+    err = os.system('"%s" "%s"' % (pkgdir.join('dotviewer.py'),
+                                   udir.join(FILENAME)))
+    assert err == 0
+
+    plain_name = FILENAME.replace('.dot','.plain')
+    
+    os.system('dot -Tplain "%s" > "%s"' % (udir.join(FILENAME),
+                                           udir.join(plain_name)))
+    print "=== dotviewer.py %s" % plain_name
+    err = os.system('"%s" "%s"' % (pkgdir.join('dotviewer.py'),
+                                   udir.join(plain_name)))
+    assert err == 0
+
+def test_display_dot_file():
+    from dotviewer.graphclient import display_dot_file
+    print "=== display_dot_file(%s) with GRAPHSERVER=%s" % (
+        FILENAME, os.environ.get('GRAPHSERVER', ''),)
+    display_dot_file(udir.join(FILENAME))
+    print "=== display_dot_file finished"
+
+
+def test_graphserver():
+    import socket
+    s = socket.socket()
+    s.listen(1)
+    host, port = s.getsockname()     # pick a random free port
+    s.close()
+
+    if hasattr(sys, 'pypy_objspaceclass'):
+        python = 'python'
+    else:
+        python = sys.executable
+
+    cmdargs = [python, str(pkgdir.join('graphserver.py')),
+               str(port)]
+    print '* starting:', ' '.join(cmdargs)
+    pid = os.spawnv(os.P_NOWAIT, cmdargs[0], cmdargs)
+    try:
+        time.sleep(1)    # hack - wait a bit to make sure the server is up
+        os.environ['GRAPHSERVER'] = '%s:%d' % (host, port)
+        try:
+            test_display_dot_file()
+        finally:
+            del os.environ['GRAPHSERVER']
+    finally:
+        os.kill(pid, signal.SIGTERM)
+
+def test_colors():
+    from dotviewer import graphpage, graphclient
+    class MyPage(graphpage.DotFileGraphPage):
+        def compute(self, dotfile):
+            super(MyPage, self).compute(dotfile)
+            self.links = {'v2721': 'Hello world',
+                          'v2720': ('Something green', (0, 192, 0)),
+                          }
+    dotfile = str(udir.join(FILENAME))
+    page = MyPage(dotfile)
+    graphclient.display_page(page)
+
+def test_fixedfont():
+    from dotviewer import graphpage, graphclient
+    class MyPage(graphpage.DotFileGraphPage):
+        fixedfont = True
+    dotfile = str(udir.join(FILENAME))
+    page = MyPage(dotfile)
+    page.fixedfont = True
+    graphclient.display_page(page)

dotviewer/test/test_translator.py

 
 def test_annotated():
     from rpython.translator.interactive import Translation
-    t = Translation(is_prime)
-    t.annotate([int])
+    t = Translation(is_prime, [int])
+    t.annotate()
     t.viewcg()

dotviewer/test/test_unicode_util.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+import py
+import codecs
+from dotviewer.drawgraph import RAW_ENCODING, forcestr, forceunicode
+
+SOURCE1 = u"""digraph G{
+λ -> b
+b -> μ
+}
+"""
+
+FILENAME = 'test.dot'
+
+class TestUnicodeUtil(object):
+
+    def test_idempotent(self):
+        x = u"a"
+        assert forceunicode(forcestr(x)) == x
+        
+        x = u"λ"
+        assert forceunicode(forcestr(x)) == x
+
+        assert forceunicode(forcestr(SOURCE1)) == SOURCE1
+
+        x = "a"
+        assert forcestr(forceunicode(x)) == x
+
+        # utf-8 encoded.
+        # fragile, does not consider RAW_ENCODING
+        # x = "\xef\xbb\xbf\xce\xbb"
+        # assert forcestr(forceunicode(x)) == x
+
+    def test_does_not_double_encode(self):
+        x = u"λ"
+        x_e = forcestr(x)
+        assert forcestr(x_e) == x_e
+
+        x_u = forceunicode(x_e)
+        assert forceunicode(x_u) == x_u
+
+    def test_file(self):       
+        udir = py.path.local.make_numbered_dir(prefix='usession-dot-', keep=3)
+        full_filename = str(udir.join(FILENAME))
+        f = codecs.open(full_filename, 'wb', RAW_ENCODING)
+        f.write(SOURCE1)
+        f.close()
+
+        with open(full_filename) as f1:
+            assert forceunicode(f1.read()) == SOURCE1
+
+        f3 = codecs.open(full_filename, 'r', RAW_ENCODING)
+        c = f3.read()
+        f3.close()
+        result = (c == SOURCE1)
+        assert result

lib-python/2.7/collections.py

 __all__ += _abcoll.__all__
 
 from _collections import deque, defaultdict
-from operator import itemgetter as _itemgetter
+from operator import itemgetter as _itemgetter, eq as _eq
 from keyword import iskeyword as _iskeyword
 import sys as _sys
 import heapq as _heapq
 from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
+from itertools import imap as _imap
 
 try:
     from thread import get_ident as _get_ident
             self.__map = {}
         self.__update(*args, **kwds)
 
-    def __setitem__(self, key, value, PREV=0, NEXT=1, dict_setitem=dict.__setitem__):
+    def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
         'od.__setitem__(i, y) <==> od[i]=y'
         # Setting a new item creates a new link at the end of the linked list,
         # and the inherited dictionary is updated with the new key/value pair.
         if key not in self:
             root = self.__root
-            last = root[PREV]
-            last[NEXT] = root[PREV] = self.__map[key] = [last, root, key]
-        dict_setitem(self, key, value)
+            last = root[0]
+            last[1] = root[0] = self.__map[key] = [last, root, key]
+        return dict_setitem(self, key, value)
 
-    def __delitem__(self, key, PREV=0, NEXT=1, dict_delitem=dict.__delitem__):
+    def __delitem__(self, key, dict_delitem=dict.__delitem__):
         'od.__delitem__(y) <==> del od[y]'
         # Deleting an existing item uses self.__map to find the link which gets
         # removed by updating the links in the predecessor and successor nodes.
         dict_delitem(self, key)
         link_prev, link_next, key = self.__map.pop(key)
-        link_prev[NEXT] = link_next
-        link_next[PREV] = link_prev
+        link_prev[1] = link_next                        # update link_prev[NEXT]
+        link_next[0] = link_prev                        # update link_next[PREV]
 
     def __iter__(self):
         'od.__iter__() <==> iter(od)'
         # Traverse the linked list in order.
-        NEXT, KEY = 1, 2
         root = self.__root
-        curr = root[NEXT]
+        curr = root[1]                                  # start at the first node
         while curr is not root:
-            yield curr[KEY]
-            curr = curr[NEXT]
+            yield curr[2]                               # yield the curr[KEY]
+            curr = curr[1]                              # move to next node
 
     def __reversed__(self):
         'od.__reversed__() <==> reversed(od)'
         # Traverse the linked list in reverse order.
-        PREV, KEY = 0, 2
         root = self.__root
-        curr = root[PREV]
+        curr = root[0]                                  # start at the last node
         while curr is not root:
-            yield curr[KEY]
-            curr = curr[PREV]
+            yield curr[2]                               # yield the curr[KEY]
+            curr = curr[0]                              # move to previous node
 
     def clear(self):
         'od.clear() -> None.  Remove all items from od.'
-        for node in self.__map.itervalues():
-            del node[:]
         root = self.__root
         root[:] = [root, root, None]
         self.__map.clear()
 
         '''
         if isinstance(other, OrderedDict):
-            return len(self)==len(other) and self.items() == other.items()
+            return dict.__eq__(self, other) and all(_imap(_eq, self, other))
         return dict.__eq__(self, other)
 
     def __ne__(self, other):
             'Return self as a plain tuple.  Used by copy and pickle.'
             return tuple(self) \n\n''' % locals()
     for i, name in enumerate(field_names):
-        template += "        %s = _property(_itemgetter(%d), doc='Alias for field number %d')\n" % (name, i, i)
+        template += "        %s = _property(lambda self: self[%d], doc='Alias for field number %d')\n" % (name, i, i)
     if verbose:
         print template
 
     # Execute the template string in a temporary namespace and
     # support tracing utilities by setting a value for frame.f_globals['__name__']
-    namespace = dict(_itemgetter=_itemgetter, __name__='namedtuple_%s' % typename,
+    namespace = dict(__name__='namedtuple_%s' % typename,
                      OrderedDict=OrderedDict, _property=property, _tuple=tuple)
     try:
         exec template in namespace

lib-python/2.7/json/encoder.py

         self.skipkeys = skipkeys
         self.ensure_ascii = ensure_ascii
         if ensure_ascii:
-            self.encoder = raw_encode_basestring_ascii
+            self.__encoder = raw_encode_basestring_ascii
         else:
-            self.encoder = raw_encode_basestring
+            self.__encoder = raw_encode_basestring
         if encoding != 'utf-8':
-            orig_encoder = self.encoder
+            orig_encoder = self.__encoder
             def encoder(o):
                 if isinstance(o, str):
                     o = o.decode(encoding)
                 return orig_encoder(o)
-            self.encoder = encoder
+            self.__encoder = encoder
         self.check_circular = check_circular
         self.allow_nan = allow_nan
         self.sort_keys = sort_keys
             builder = StringBuilder()
         else:
             builder = UnicodeBuilder()
-        self._encode(o, markers, builder, 0)
+        self.__encode(o, markers, builder, 0)
         return builder.build()
 
-    def _emit_indent(self, builder, _current_indent_level):
+    def __emit_indent(self, builder, _current_indent_level):
         if self.indent is not None:
             _current_indent_level += 1
             newline_indent = '\n' + (' ' * (self.indent *
             separator = self.item_separator
         return separator, _current_indent_level
 
-    def _emit_unindent(self, builder, _current_indent_level):
+    def __emit_unindent(self, builder, _current_indent_level):
         if self.indent is not None:
             builder.append('\n')
             builder.append(' ' * (self.indent * (_current_indent_level - 1)))
 
-    def _encode(self, o, markers, builder, _current_indent_level):
+    def __encode(self, o, markers, builder, _current_indent_level):
         if isinstance(o, basestring):
             builder.append('"')
-            builder.append(self.encoder(o))
+            builder.append(self.__encoder(o))
             builder.append('"')
         elif o is None:
             builder.append('null')
         elif isinstance(o, (int, long)):
             builder.append(str(o))
         elif isinstance(o, float):
-            builder.append(self._floatstr(o))
+            builder.append(self.__floatstr(o))
         elif isinstance(o, (list, tuple)):
             if not o:
                 builder.append('[]')
                 return
-            self._encode_list(o, markers, builder, _current_indent_level)
+            self.__encode_list(o, markers, builder, _current_indent_level)
         elif isinstance(o, dict):
             if not o:
                 builder.append('{}')
                 return
-            self._encode_dict(o, markers, builder, _current_indent_level)
+            self.__encode_dict(o, markers, builder, _current_indent_level)
         else:
-            self._mark_markers(markers, o)
+            self.__mark_markers(markers, o)
             res = self.default(o)
-            self._encode(res, markers, builder, _current_indent_level)
-            self._remove_markers(markers, o)
+            self.__encode(res, markers, builder, _current_indent_level)
+            self.__remove_markers(markers, o)
             return res
 
-    def _encode_list(self, l, markers, builder, _current_indent_level):
-        self._mark_markers(markers, l)
+    def __encode_list(self, l, markers, builder, _current_indent_level):
+        self.__mark_markers(markers, l)
         builder.append('[')
         first = True
-        separator, _current_indent_level = self._emit_indent(builder,
+        separator, _current_indent_level = self.__emit_indent(builder,
                                                       _current_indent_level)
         for elem in l:
             if first:
                 first = False
             else:
                 builder.append(separator)
-            self._encode(elem, markers, builder, _current_indent_level)
+            self.__encode(elem, markers, builder, _current_indent_level)
             del elem # XXX grumble
-        self._emit_unindent(builder, _current_indent_level)
+        self.__emit_unindent(builder, _current_indent_level)
         builder.append(']')
-        self._remove_markers(markers, l)
+        self.__remove_markers(markers, l)
 
-    def _encode_dict(self, d, markers, builder, _current_indent_level):
-        self._mark_markers(markers, d)
+    def __encode_dict(self, d, markers, builder, _current_indent_level):
+        self.__mark_markers(markers, d)
         first = True
         builder.append('{')
-        separator, _current_indent_level = self._emit_indent(builder,
+        separator, _current_indent_level = self.__emit_indent(builder,
                                                          _current_indent_level)
         if self.sort_keys:
             items = sorted(d.items(), key=lambda kv: kv[0])
             # JavaScript is weakly typed for these, so it makes sense to
             # also allow them.  Many encoders seem to do something like this.
             elif isinstance(key, float):
-                key = self._floatstr(key)
+                key = self.__floatstr(key)
             elif key is True:
                 key = 'true'
             elif key is False:
             else:
                 raise TypeError("key " + repr(key) + " is not a string")
             builder.append('"')
-            builder.append(self.encoder(key))
+            builder.append(self.__encoder(key))
             builder.append('"')
             builder.append(self.key_separator)
-            self._encode(v, markers, builder, _current_indent_level)
+            self.__encode(v, markers, builder, _current_indent_level)
             del key
             del v # XXX grumble
-        self._emit_unindent(builder, _current_indent_level)
+        self.__emit_unindent(builder, _current_indent_level)
         builder.append('}')
-        self._remove_markers(markers, d)
+        self.__remove_markers(markers, d)
 
     def iterencode(self, o, _one_shot=False):
         """Encode the given object and yield each string
             markers = {}
         else:
             markers = None
-        return self._iterencode(o, markers, 0)
+        return self.__iterencode(o, markers, 0)
 
-    def _floatstr(self, o):
+    def __floatstr(self, o):
         # Check for specials.  Note that this type of test is processor
         # and/or platform-specific, so do tests which don't depend on the
         # internals.
 
         return text
 
-    def _mark_markers(self, markers, o):
+    def __mark_markers(self, markers, o):
         if markers is not None:
             if id(o) in markers:
                 raise ValueError("Circular reference detected")
             markers[id(o)] = None
 
-    def _remove_markers(self, markers, o):
+    def __remove_markers(self, markers, o):
         if markers is not None:
             del markers[id(o)]
 
-    def _iterencode_list(self, lst, markers, _current_indent_level):
+    def __iterencode_list(self, lst, markers, _current_indent_level):
         if not lst:
             yield '[]'
             return
-        self._mark_markers(markers, lst)
+        self.__mark_markers(markers, lst)
         buf = '['
         if self.indent is not None:
             _current_indent_level += 1
             else:
                 buf = separator
             if isinstance(value, basestring):
-                yield buf + '"' + self.encoder(value) + '"'
+                yield buf + '"' + self.__encoder(value) + '"'
             elif value is None:
                 yield buf + 'null'
             elif value is True:
             elif isinstance(value, (int, long)):
                 yield buf + str(value)
             elif isinstance(value, float):
-                yield buf + self._floatstr(value)
+                yield buf + self.__floatstr(value)
             else:
                 yield buf
                 if isinstance(value, (list, tuple)):
-                    chunks = self._iterencode_list(value, markers,
+                    chunks = self.__iterencode_list(value, markers,
                                                    _current_indent_level)
                 elif isinstance(value, dict):
-                    chunks = self._iterencode_dict(value, markers,
+                    chunks = self.__iterencode_dict(value, markers,
                                                    _current_indent_level)
                 else:
-                    chunks = self._iterencode(value, markers,
+                    chunks = self.__iterencode(value, markers,
                                               _current_indent_level)
                 for chunk in chunks:
                     yield chunk
             _current_indent_level -= 1
             yield '\n' + (' ' * (self.indent * _current_indent_level))
         yield ']'
-        self._remove_markers(markers, lst)
+        self.__remove_markers(markers, lst)
 
-    def _iterencode_dict(self, dct, markers, _current_indent_level):
+    def __iterencode_dict(self, dct, markers, _current_indent_level):
         if not dct:
             yield '{}'
             return
-        self._mark_markers(markers, dct)
+        self.__mark_markers(markers, dct)
         yield '{'
         if self.indent is not None:
             _current_indent_level += 1
             # JavaScript is weakly typed for these, so it makes sense to
             # also allow them.  Many encoders seem to do something like this.
             elif isinstance(key, float):
-                key = self._floatstr(key)
+                key = self.__floatstr(key)
             elif key is True:
                 key = 'true'
             elif key is False:
                 first = False
             else:
                 yield item_separator
-            yield '"' + self.encoder(key) + '"'
+            yield '"' + self.__encoder(key) + '"'
             yield self.key_separator
             if isinstance(value, basestring):
-                yield '"' + self.encoder(value) + '"'
+                yield '"' + self.__encoder(value) + '"'
             elif value is None:
                 yield 'null'
             elif value is True:
             elif isinstance(value, (int, long)):
                 yield str(value)
             elif isinstance(value, float):
-                yield self._floatstr(value)
+                yield self.__floatstr(value)
             else:
                 if isinstance(value, (list, tuple)):
-                    chunks = self._iterencode_list(value, markers,
+                    chunks = self.__iterencode_list(value, markers,
                                                    _current_indent_level)
                 elif isinstance(value, dict):
-                    chunks = self._iterencode_dict(value, markers,
+                    chunks = self.__iterencode_dict(value, markers,
                                                    _current_indent_level)
                 else:
-                    chunks = self._iterencode(value, markers,
+                    chunks = self.__iterencode(value, markers,
                                               _current_indent_level)
                 for chunk in chunks:
                     yield chunk
             _current_indent_level -= 1
             yield '\n' + (' ' * (self.indent * _current_indent_level))
         yield '}'
-        self._remove_markers(markers, dct)
+        self.__remove_markers(markers, dct)
 
-    def _iterencode(self, o, markers, _current_indent_level):
+    def __iterencode(self, o, markers, _current_indent_level):
         if isinstance(o, basestring):
-            yield '"' + self.encoder(o) + '"'
+            yield '"' + self.__encoder(o) + '"'
         elif o is None:
             yield 'null'
         elif o is True:
         elif isinstance(o, (int, long)):
             yield str(o)
         elif isinstance(o, float):
-            yield self._floatstr(o)
+            yield self.__floatstr(o)
         elif isinstance(o, (list, tuple)):
-            for chunk in self._iterencode_list(o, markers,
+            for chunk in self.__iterencode_list(o, markers,
                                                _current_indent_level):
                 yield chunk
         elif isinstance(o, dict):
-            for chunk in self._iterencode_dict(o, markers,
+            for chunk in self.__iterencode_dict(o, markers,
                                                _current_indent_level):
                 yield chunk
         else:
-            self._mark_markers(markers, o)
+            self.__mark_markers(markers, o)
             obj = self.default(o)
-            for chunk in self._iterencode(obj, markers,
+            for chunk in self.__iterencode(obj, markers,
                                           _current_indent_level):
                 yield chunk
-            self._remove_markers(markers, o)
+            self.__remove_markers(markers, o)

lib-python/2.7/test/test_generators.py

 """
 
 coroutine_tests = """\
-A helper function to call gc.collect() without printing
->>> import gc
->>> def gc_collect(): gc.collect()
+>>> from test.test_support import gc_collect
 
 Sending a value into a started generator:
 
 references. We add it to the standard suite so the routine refleak-tests
 would trigger if it starts being uncleanable again.
 
->>> import gc
->>> def gc_collect(): gc.collect()
+>>> from test.test_support import gc_collect
 
 >>> import itertools
 >>> def leak():

lib-python/2.7/test/test_modulefinder.py

 # library.
 
 TEST_DIR = tempfile.mkdtemp()
-TEST_PATH = [TEST_DIR, os.path.dirname(__future__.__file__)]
+TEST_PATH = [TEST_DIR, os.path.dirname(tempfile.__file__)]
 
 # Each test description is a list of 5 items:
 #

lib-python/2.7/urllib.py

     # fastpath
     if len(res) == 1:
         return s
-    s = res[0]
-    for item in res[1:]:
+    res_list = [res[0]]
+    for j in xrange(1, len(res)):
+        item = res[j]
         try:
-            s += _hextochr[item[:2]] + item[2:]
+            x = _hextochr[item[:2]] + item[2:]
         except KeyError:
-            s += '%' + item
+            x = '%' + item
         except UnicodeDecodeError:
-            s += unichr(int(item[:2], 16)) + item[2:]
-    return s
+            x = unichr(int(item[:2], 16)) + item[2:]
+        res_list.append(x)
+    return ''.join(res_list)
 
 def unquote_plus(s):
     """unquote('%7e/abc+def') -> '~/abc def'"""

lib-python/2.7/urlparse.py

     # fastpath
     if len(res) == 1:
         return s
-    s = res[0]
-    for item in res[1:]:
+    res_list = [res[0]]
+    for j in xrange(1, len(res)):
+        item = res[j]
         try:
-            s += _hextochr[item[:2]] + item[2:]
+            x = _hextochr[item[:2]] + item[2:]
         except KeyError:
-            s += '%' + item
+            x = '%' + item
         except UnicodeDecodeError:
-            s += unichr(int(item[:2], 16)) + item[2:]
-    return s
+            x = unichr(int(item[:2], 16)) + item[2:]
+        res_list.append(x)
+    return ''.join(res_list)
 
 def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
     """Parse a query given as a string argument.

lib-python/conftest.py

     RegrTest('test_codeop.py', core=True),
     RegrTest('test_coding.py', core=True),
     RegrTest('test_coercion.py', core=True),
-    RegrTest('test_collections.py'),
+    RegrTest('test_collections.py', usemodules='binascii struct'),
     RegrTest('test_colorsys.py'),
     RegrTest('test_commands.py'),
     RegrTest('test_compare.py', core=True),
     RegrTest('test_csv.py', usemodules='_csv'),
     RegrTest('test_ctypes.py', usemodules="_rawffi thread"),
     RegrTest('test_curses.py'),
-    RegrTest('test_datetime.py'),
+    RegrTest('test_datetime.py', usemodules='binascii struct'),
     RegrTest('test_dbm.py'),
     RegrTest('test_decimal.py'),
     RegrTest('test_decorators.py', core=True),
     RegrTest('test_inspect.py'),
     RegrTest('test_int.py', core=True),
     RegrTest('test_int_literal.py', core=True),
-    RegrTest('test_io.py'),
+    RegrTest('test_io.py', usemodules='array binascii'),
     RegrTest('test_ioctl.py'),
     RegrTest('test_isinstance.py', core=True),
     RegrTest('test_iter.py', core=True),

lib_pypy/_collections.py

         return c
 
     def remove(self, value):
-        # Need to be defensive for mutating comparisons
-        for i in range(len(self)):
-            if self[i] == value:
-                del self[i]
-                return
-        raise ValueError("deque.remove(x): x not in deque")
+        # Need to defend mutating or failing comparisons
+        i = 0
+        try:
+            for i in range(len(self)):
+                if self[0] == value:
+                    self.popleft()
+                    return
+                self.append(self.popleft())
+            i += 1
+            raise ValueError("deque.remove(x): x not in deque")
+        finally:
+            self.rotate(i)
 
     def rotate(self, n=1):
         length = len(self)
-        if length == 0:
+        if length <= 1:
             return
-        halflen = (length+1) >> 1
+        halflen = length >> 1
         if n > halflen or n < -halflen:
             n %= length
             if n > halflen:

lib_pypy/cPickle.py

 #
-# One-liner implementation of cPickle
+# Reimplementation of cPickle, mostly as a copy of pickle.py
 #
 
 from pickle import Pickler, dump, dumps, PickleError, PicklingError, UnpicklingError, _EmptyClass
 
 # Unpickling machinery
 
+class _Stack(list):
+    def pop(self, index=-1):
+        try:
+            return list.pop(self, index)
+        except IndexError:
+            raise UnpicklingError("unpickling stack underflow")
+
 class Unpickler(object):
 
     def __init__(self, file):
         Return the reconstituted object hierarchy specified in the file.
         """
         self.mark = object() # any new unique object
-        self.stack = []
+        self.stack = _Stack()
         self.append = self.stack.append
         try:
             key = ord(self.read(1))

lib_pypy/conftest.py

-
-from pypy.conftest import *

lib_pypy/ctypes_config_cache/test/test_cache.py

-import py
-import sys, os
-from rpython.tool.udir import udir
-
-dirpath = py.path.local(__file__).dirpath().dirpath()
-
-
-def run(filename, outputname):
-    filepath = dirpath.join(filename)
-    tmpdir = udir.ensure('testcache-' + os.path.splitext(filename)[0],
-                         dir=True)
-    tmpdir.join('dumpcache.py').write(dirpath.join('dumpcache.py').read())
-    path = sys.path[:]
-    sys.modules.pop('dumpcache', None)
-    try:
-        sys.path.insert(0, str(tmpdir))
-        execfile(str(filepath), {})
-    finally:
-        sys.path[:] = path
-        sys.modules.pop('dumpcache', None)
-    #
-    outputpath = tmpdir.join(outputname)
-    assert outputpath.check(exists=1)
-    modname = os.path.splitext(outputname)[0]
-    try:
-        sys.path.insert(0, str(tmpdir))
-        d = {}
-        execfile(str(outputpath), d)
-    finally:
-        sys.path[:] = path
-    return d
-
-
-def test_syslog():
-    d = run('syslog.ctc.py', '_syslog_cache.py')
-    assert 'LOG_NOTICE' in d
-
-def test_resource():
-    d = run('resource.ctc.py', '_resource_cache.py')
-    assert 'RLIM_NLIMITS' in d
-
-def test_locale():
-    d = run('locale.ctc.py', '_locale_cache.py')
-    assert 'LC_ALL' in d
-    assert 'CHAR_MAX' in d

lib_pypy/ctypes_support.py

 
 if sys.platform == 'win32':
     standard_c_lib._errno.restype = ctypes.POINTER(ctypes.c_int)
+    standard_c_lib._errno.argtypes = None
     def _where_is_errno():
         return standard_c_lib._errno()
     
 elif sys.platform in ('linux2', 'freebsd6'):
     standard_c_lib.__errno_location.restype = ctypes.POINTER(ctypes.c_int)
+    standard_c_lib.__errno_location.argtypes = None
     def _where_is_errno():
         return standard_c_lib.__errno_location()
 
 elif sys.platform in ('darwin', 'freebsd7', 'freebsd8', 'freebsd9'):
     standard_c_lib.__error.restype = ctypes.POINTER(ctypes.c_int)
+    standard_c_lib.__error.argtypes = None
     def _where_is_errno():
         return standard_c_lib.__error()
 

lib_pypy/datetime.py

         return offset
     raise ValueError("%s()=%d, must be in -1439..1439" % (name, offset))
 
+def _check_int_field(value):
+    if not isinstance(value, float):
+        try:
+            value = value.__int__()
+        except AttributeError:
+            pass
+        else:
+            if isinstance(value, (int, long)):
+                return value
+    raise TypeError('integer argument expected')
+
 def _check_date_fields(year, month, day):
-    for value in [year, day]:
-        if not isinstance(value, (int, long)):
-            raise TypeError('int expected')
+    year = _check_int_field(year)
+    month = _check_int_field(month)
+    day = _check_int_field(day)
     if not MINYEAR <= year <= MAXYEAR:
         raise ValueError('year must be in %d..%d' % (MINYEAR, MAXYEAR), year)
     if not 1 <= month <= 12:
     dim = _days_in_month(year, month)
     if not 1 <= day <= dim:
         raise ValueError('day must be in 1..%d' % dim, day)
+    return year, month, day
 
 def _check_time_fields(hour, minute, second, microsecond):
-    for value in [hour, minute, second, microsecond]:
-        if not isinstance(value, (int, long)):
-            raise TypeError('int expected')
+    hour = _check_int_field(hour)
+    minute = _check_int_field(minute)
+    second = _check_int_field(second)
+    microsecond = _check_int_field(microsecond)
     if not 0 <= hour <= 23:
         raise ValueError('hour must be in 0..23', hour)
     if not 0 <= minute <= 59:
         raise ValueError('second must be in 0..59', second)
     if not 0 <= microsecond <= 999999:
         raise ValueError('microsecond must be in 0..999999', microsecond)
+    return hour, minute, second, microsecond
 
 def _check_tzinfo_arg(tz):
     if tz is not None and not isinstance(tz, tzinfo):
             self = object.__new__(cls)
             self.__setstate(year)
             return self
-        _check_date_fields(year, month, day)
+        year, month, day = _check_date_fields(year, month, day)
         self = object.__new__(cls)
         self._year = year
         self._month = month
             month = self._month
         if day is None:
             day = self._day
-        _check_date_fields(year, month, day)
+        year, month, day = _check_date_fields(year, month, day)
         return date(year, month, day)
 
     # Comparisons of date objects with other.
         second, microsecond (default to zero)
         tzinfo (default to None)
         """
-        self = object.__new__(cls)
         if isinstance(hour, str):
             # Pickle support
+            self = object.__new__(cls)
             self.__setstate(hour, minute or None)
             return self
+        hour, minute, second, microsecond = _check_time_fields(hour, minute, second, microsecond)
         _check_tzinfo_arg(tzinfo)
-        _check_time_fields(hour, minute, second, microsecond)
+        self = object.__new__(cls)
         self._hour = hour
         self._minute = minute
         self._second = second
             microsecond = self.microsecond
         if tzinfo is True:
             tzinfo = self.tzinfo
-        _check_time_fields(hour, minute, second, microsecond)
+        hour, minute, second, microsecond = _check_time_fields(hour, minute, second, microsecond)
         _check_tzinfo_arg(tzinfo)
         return time(hour, minute, second, microsecond, tzinfo)
 
             self = date.__new__(cls, year[:4])
             self.__setstate(year, month)
             return self
+        year, month, day = _check_date_fields(year, month, day)
+        hour, minute, second, microsecond = _check_time_fields(hour, minute, second, microsecond)
         _check_tzinfo_arg(tzinfo)
-        _check_time_fields(hour, minute, second, microsecond)
-        self = date.__new__(cls, year, month, day)
-        # XXX This duplicates __year, __month, __day for convenience :-(
+        self = object.__new__(cls)
         self._year = year
         self._month = month
         self._day = day
             microsecond = self.microsecond
         if tzinfo is True:
             tzinfo = self.tzinfo
-        _check_date_fields(year, month, day)
-        _check_time_fields(hour, minute, second, microsecond)
+        year, month, day = _check_date_fields(year, month, day)
+        hour, minute, second, microsecond = _check_time_fields(hour, minute, second, microsecond)
         _check_tzinfo_arg(tzinfo)
         return datetime(year, month, day, hour, minute, second,
                           microsecond, tzinfo)
-from ctypes import Structure, c_char_p, c_int, c_void_p, CDLL
+from ctypes import Structure, c_char_p, c_int, c_void_p, CDLL, POINTER, c_char
 import ctypes.util
 import os, sys
 
 
 class datum(Structure):
     _fields_ = [
-    ('dptr', c_char_p),
+    ('dptr', POINTER(c_char)),
     ('dsize', c_int),
     ]
 
     libpath = ctypes.util.find_library('db')
     if not libpath:
         # XXX this is hopeless...
-        for c in '56789':
-            libpath = ctypes.util.find_library('db-4.%s' % c)
+        for c in ['5.3', '5.2', '5.1', '5.0', '4.9', '4.8', '4.7', '4.6', '4.5']:
+            libpath = ctypes.util.find_library('db-%s' % c)
             if libpath:
                 break
         else:

lib_pypy/greenlet.py

 import _continuation, sys
 
+__version__ = "0.4.0"
 
 # ____________________________________________________________
 # Exceptions
     def __switch(target, methodname, *args):
         current = getcurrent()
         #
-        while not target:
+        while not (target.__main or _continulet.is_pending(target)):
+            # inlined __nonzero__ ^^^ in case it's overridden
             if not target.__started:
                 if methodname == 'switch':
                     greenlet_func = _greenlet_start

lib_pypy/numpypy/core/__init__.py

 from .fromnumeric import *
 from .numeric import *
+from .shape_base import *

lib_pypy/numpypy/core/numeric.py

 True_ = bool_(True)
 e = math.e
 pi = math.pi
+
+def outer(a,b):
+    """
+    Compute the outer product of two vectors.
+
+    Given two vectors, ``a = [a0, a1, ..., aM]`` and
+    ``b = [b0, b1, ..., bN]``,
+    the outer product [1]_ is::
+
+      [[a0*b0  a0*b1 ... a0*bN ]
+       [a1*b0    .
+       [ ...          .
+       [aM*b0            aM*bN ]]
+
+    Parameters
+    ----------
+    a, b : array_like, shape (M,), (N,)
+        First and second input vectors.  Inputs are flattened if they
+        are not already 1-dimensional.
+
+    Returns
+    -------
+    out : ndarray, shape (M, N)
+        ``out[i, j] = a[i] * b[j]``
+
+    See also
+    --------
+    inner, einsum
+
+    References
+    ----------
+    .. [1] : G. H. Golub and C. F. van Loan, *Matrix Computations*, 3rd
+             ed., Baltimore, MD, Johns Hopkins University Press, 1996,
+             pg. 8.
+
+    Examples
+    --------
+    Make a (*very* coarse) grid for computing a Mandelbrot set:
+
+    >>> rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5))
+    >>> rl
+    array([[-2., -1.,  0.,  1.,  2.],
+           [-2., -1.,  0.,  1.,  2.],
+           [-2., -1.,  0.,  1.,  2.],
+           [-2., -1.,  0.,  1.,  2.],
+           [-2., -1.,  0.,  1.,  2.]])
+    >>> im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,)))
+    >>> im
+    array([[ 0.+2.j,  0.+2.j,  0.+2.j,  0.+2.j,  0.+2.j],
+           [ 0.+1.j,  0.+1.j,  0.+1.j,  0.+1.j,  0.+1.j],
+           [ 0.+0.j,  0.+0.j,  0.+0.j,  0.+0.j,  0.+0.j],
+           [ 0.-1.j,  0.-1.j,  0.-1.j,  0.-1.j,  0.-1.j],
+           [ 0.-2.j,  0.-2.j,  0.-2.j,  0.-2.j,  0.-2.j]])
+    >>> grid = rl + im
+    >>> grid
+    array([[-2.+2.j, -1.+2.j,  0.+2.j,  1.+2.j,  2.+2.j],
+           [-2.+1.j, -1.+1.j,  0.+1.j,  1.+1.j,  2.+1.j],
+           [-2.+0.j, -1.+0.j,  0.+0.j,  1.+0.j,  2.+0.j],
+           [-2.-1.j, -1.-1.j,  0.-1.j,  1.-1.j,  2.-1.j],
+           [-2.-2.j, -1.-2.j,  0.-2.j,  1.-2.j,  2.-2.j]])
+
+    An example using a "vector" of letters:
+
+    >>> x = np.array(['a', 'b', 'c'], dtype=object)
+    >>> np.outer(x, [1, 2, 3])
+    array([[a, aa, aaa],
+           [b, bb, bbb],
+           [c, cc, ccc]], dtype=object)
+
+    """
+    a = asarray(a)
+    b = asarray(b)
+    return a.ravel()[:,newaxis]*b.ravel()[newaxis,:]

lib_pypy/numpypy/core/shape_base.py

+import _numpypy
+from numeric import array, asanyarray, newaxis
+
+def atleast_1d(*arys):
+    """
+    Convert inputs to arrays with at least one dimension.
+
+    Scalar inputs are converted to 1-dimensional arrays, whilst
+    higher-dimensional inputs are preserved.
+
+    Parameters
+    ----------
+    arys1, arys2, ... : array_like
+        One or more input arrays.
+
+    Returns
+    -------
+    ret : ndarray
+        An array, or sequence of arrays, each with ``a.ndim >= 1``.
+        Copies are made only if necessary.
+
+    See Also
+    --------
+    atleast_2d, atleast_3d
+
+    Examples
+    --------
+    >>> np.atleast_1d(1.0)
+    array([ 1.])
+
+    >>> x = np.arange(9.0).reshape(3,3)
+    >>> np.atleast_1d(x)
+    array([[ 0.,  1.,  2.],
+           [ 3.,  4.,  5.],
+           [ 6.,  7.,  8.]])
+    >>> np.atleast_1d(x) is x
+    True
+
+    >>> np.atleast_1d(1, [3, 4])
+    [array([1]), array([3, 4])]
+
+    """
+    res = []
+    for ary in arys:
+        ary = asanyarray(ary)
+        if len(ary.shape) == 0 :
+            result = ary.reshape(1)
+        else :
+            result = ary
+        res.append(result)
+    if len(res) == 1:
+        return res[0]
+    else:
+        return res
+
+
+def atleast_2d(*arys):
+    """
+    View inputs as arrays with at least two dimensions.
+
+    Parameters
+    ----------
+    arys1, arys2, ... : array_like
+        One or more array-like sequences.  Non-array inputs are converted
+        to arrays.  Arrays that already have two or more dimensions are
+        preserved.
+
+    Returns
+    -------
+    res, res2, ... : ndarray
+        An array, or tuple of arrays, each with ``a.ndim >= 2``.
+        Copies are avoided where possible, and views with two or more
+        dimensions are returned.
+
+    See Also
+    --------
+    atleast_1d, atleast_3d
+
+    Examples
+    --------
+    >>> np.atleast_2d(3.0)
+    array([[ 3.]])
+
+    >>> x = np.arange(3.0)
+    >>> np.atleast_2d(x)
+    array([[ 0.,  1.,  2.]])
+    >>> np.atleast_2d(x).base is x
+    True
+
+    >>> np.atleast_2d(1, [1, 2], [[1, 2]])
+    [array([[1]]), array([[1, 2]]), array([[1, 2]])]
+
+    """
+    res = []
+    for ary in arys:
+        ary = asanyarray(ary)
+        if len(ary.shape) == 0 :
+            result = ary.reshape(1, 1)
+        elif len(ary.shape) == 1 :
+            result = ary[newaxis, :]
+        else :
+            result = ary
+        res.append(result)
+    if len(res) == 1:
+        return res[0]
+    else:
+        return res
+
+def atleast_3d(*arys):
+    """
+    View inputs as arrays with at least three dimensions.
+
+    Parameters
+    ----------
+    arys1, arys2, ... : array_like
+        One or more array-like sequences.  Non-array inputs are converted to
+        arrays.  Arrays that already have three or more dimensions are
+        preserved.
+
+    Returns
+    -------
+    res1, res2, ... : ndarray
+        An array, or tuple of arrays, each with ``a.ndim >= 3``.  Copies are
+        avoided where possible, and views with three or more dimensions are
+        returned.  For example, a 1-D array of shape ``(N,)`` becomes a view
+        of shape ``(1, N, 1)``, and a 2-D array of shape ``(M, N)`` becomes a
+        view of shape ``(M, N, 1)``.
+
+    See Also
+    --------
+    atleast_1d, atleast_2d
+
+    Examples
+    --------
+    >>> np.atleast_3d(3.0)
+    array([[[ 3.]]])
+
+    >>> x = np.arange(3.0)
+    >>> np.atleast_3d(x).shape
+    (1, 3, 1)
+
+    >>> x = np.arange(12.0).reshape(4,3)
+    >>> np.atleast_3d(x).shape
+    (4, 3, 1)
+    >>> np.atleast_3d(x).base is x
+    True
+
+    >>> for arr in np.atleast_3d([1, 2], [[1, 2]], [[[1, 2]]]):
+    ...     print arr, arr.shape
+    ...
+    [[[1]
+      [2]]] (1, 2, 1)
+    [[[1]
+      [2]]] (1, 2, 1)
+    [[[1 2]]] (1, 1, 2)
+
+    """
+    res = []
+    for ary in arys:
+        ary = asanyarray(ary)
+        if len(ary.shape) == 0:
+            result = ary.reshape(1,1,1)
+        elif len(ary.shape) == 1:
+            result = ary[newaxis,:,newaxis]
+        elif len(ary.shape) == 2:
+            result = ary[:,:,newaxis]
+        else:
+            result = ary
+        res.append(result)
+    if len(res) == 1:
+        return res[0]
+    else:
+        return res
+
+def vstack(tup):
+    """
+    Stack arrays in sequence vertically (row wise).
+
+    Take a sequence of arrays and stack them vertically to make a single
+    array. Rebuild arrays divided by `vsplit`.
+
+    Parameters
+    ----------
+    tup : sequence of ndarrays
+        Tuple containing arrays to be stacked. The arrays must have the same
+        shape along all but the first axis.
+
+    Returns
+    -------
+    stacked : ndarray
+        The array formed by stacking the given arrays.
+
+    See Also
+    --------
+    hstack : Stack arrays in sequence horizontally (column wise).
+    dstack : Stack arrays in sequence depth wise (along third dimension).
+    concatenate : Join a sequence of arrays together.
+    vsplit : Split array into a list of multiple sub-arrays vertically.
+
+    Notes
+    -----
+    Equivalent to ``np.concatenate(tup, axis=0)`` if `tup` contains arrays that
+    are at least 2-dimensional.
+
+    Examples
+    --------
+    >>> a = np.array([1, 2, 3])
+    >>> b = np.array([2, 3, 4])
+    >>> np.vstack((a,b))
+    array([[1, 2, 3],
+           [2, 3, 4]])
+
+    >>> a = np.array([[1], [2], [3]])
+    >>> b = np.array([[2], [3], [4]])
+    >>> np.vstack((a,b))
+    array([[1],
+           [2],
+           [3],
+           [2],
+           [3],
+           [4]])
+
+    """
+    return _numpypy.concatenate(map(atleast_2d,tup),0)
+
+def hstack(tup):
+    """