[pypy-commit] pypy python-numpy: merge default into branch
mattip
noreply at buildbot.pypy.org
Wed Feb 13 23:05:22 CET 2013
Author: mattip <matti.picus at gmail.com>
Branch: python-numpy
Changeset: r61216:fba4e51443a9
Date: 2013-02-13 22:26 +0200
http://bitbucket.org/pypy/pypy/changeset/fba4e51443a9/
Log: merge default into branch
diff too long, truncating to 2000 out of 7204 lines
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -270,3 +270,24 @@
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.
+
diff --git a/dotviewer/VeraMoBd.ttf b/dotviewer/VeraMoBd.ttf
deleted file mode 100644
Binary file dotviewer/VeraMoBd.ttf has changed
diff --git a/dotviewer/cyrvetic.ttf b/dotviewer/cyrvetic.ttf
deleted file mode 100644
Binary file dotviewer/cyrvetic.ttf has changed
diff --git a/dotviewer/drawgraph.py b/dotviewer/drawgraph.py
--- a/dotviewer/drawgraph.py
+++ b/dotviewer/drawgraph.py
@@ -9,9 +9,10 @@
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),
@@ -51,6 +52,12 @@
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
@@ -106,12 +113,12 @@
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
@@ -125,8 +132,8 @@
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)]
@@ -655,11 +662,7 @@
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:
diff --git a/dotviewer/font/DroidSans-Bold.ttf b/dotviewer/font/DroidSans-Bold.ttf
new file mode 100644
index 0000000000000000000000000000000000000000..d065b64eb1863f83c2c982264f9442f2313a44a9
GIT binary patch
[cut]
diff --git a/dotviewer/font/DroidSans.ttf b/dotviewer/font/DroidSans.ttf
new file mode 100644
index 0000000000000000000000000000000000000000..ad1efca88aed8d9e2d179f27dd713e2a1562fe5f
GIT binary patch
[cut]
diff --git a/dotviewer/font/DroidSansMono.ttf b/dotviewer/font/DroidSansMono.ttf
new file mode 100644
index 0000000000000000000000000000000000000000..a007071944f7c90020e798eea53b10065e2b45a5
GIT binary patch
[cut]
diff --git a/dotviewer/font/NOTICE b/dotviewer/font/NOTICE
new file mode 100644
--- /dev/null
+++ b/dotviewer/font/NOTICE
@@ -0,0 +1,190 @@
+
+ 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
+
diff --git a/dotviewer/font/README.txt b/dotviewer/font/README.txt
new file mode 100644
--- /dev/null
+++ b/dotviewer/font/README.txt
@@ -0,0 +1,18 @@
+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.
diff --git a/dotviewer/graphclient.py b/dotviewer/graphclient.py
--- a/dotviewer/graphclient.py
+++ b/dotviewer/graphclient.py
@@ -33,8 +33,9 @@
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)
@@ -75,7 +76,8 @@
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):
diff --git a/dotviewer/graphdisplay.py b/dotviewer/graphdisplay.py
--- a/dotviewer/graphdisplay.py
+++ b/dotviewer/graphdisplay.py
@@ -4,7 +4,7 @@
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([
@@ -285,7 +285,7 @@
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(' '):
@@ -423,7 +423,7 @@
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
@@ -711,7 +711,7 @@
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)
@@ -723,7 +723,7 @@
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]
diff --git a/dotviewer/graphpage.py b/dotviewer/graphpage.py
--- a/dotviewer/graphpage.py
+++ b/dotviewer/graphpage.py
@@ -44,6 +44,8 @@
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()
diff --git a/dotviewer/test/test_interactive_unicode.py b/dotviewer/test/test_interactive_unicode.py
new file mode 100755
--- /dev/null
+++ b/dotviewer/test/test_interactive_unicode.py
@@ -0,0 +1,103 @@
+#!/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)
diff --git a/dotviewer/test/test_translator.py b/dotviewer/test/test_translator.py
--- a/dotviewer/test/test_translator.py
+++ b/dotviewer/test/test_translator.py
@@ -22,6 +22,6 @@
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()
diff --git a/dotviewer/test/test_unicode_util.py b/dotviewer/test/test_unicode_util.py
new file mode 100755
--- /dev/null
+++ b/dotviewer/test/test_unicode_util.py
@@ -0,0 +1,57 @@
+#!/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
diff --git a/lib-python/2.7/collections.py b/lib-python/2.7/collections.py
--- a/lib-python/2.7/collections.py
+++ b/lib-python/2.7/collections.py
@@ -295,7 +295,7 @@
_fields = %(field_names)r \n
def __new__(_cls, %(argtxt)s):
'Create new instance of %(typename)s(%(argtxt)s)'
- return tuple.__new__(_cls, (%(argtxt)s)) \n
+ return _tuple.__new__(_cls, (%(argtxt)s)) \n
@classmethod
def _make(cls, iterable, new=tuple.__new__, len=len):
'Make a new %(typename)s object from a sequence or iterable'
@@ -320,14 +320,14 @@
'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(lambda self: self[%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 = {'__name__': 'namedtuple_%s' % typename,
- 'OrderedDict': OrderedDict}
+ namespace = dict(__name__='namedtuple_%s' % typename,
+ OrderedDict=OrderedDict, _property=property, _tuple=tuple)
try:
exec template in namespace
except SyntaxError, e:
diff --git a/lib-python/2.7/json/encoder.py b/lib-python/2.7/json/encoder.py
--- a/lib-python/2.7/json/encoder.py
+++ b/lib-python/2.7/json/encoder.py
@@ -138,16 +138,16 @@
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
@@ -193,10 +193,10 @@
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 *
@@ -207,15 +207,15 @@
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')
@@ -226,46 +226,46 @@
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])
@@ -282,7 +282,7 @@
# 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:
@@ -296,15 +296,15 @@
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
@@ -320,9 +320,9 @@
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.
@@ -343,21 +343,21 @@
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
@@ -375,7 +375,7 @@
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:
@@ -385,17 +385,17 @@
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
@@ -403,13 +403,13 @@
_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
@@ -431,7 +431,7 @@
# 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:
@@ -448,10 +448,10 @@
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:
@@ -461,16 +461,16 @@
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
@@ -478,11 +478,11 @@
_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:
@@ -492,19 +492,19 @@
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)
diff --git a/lib-python/2.7/urllib.py b/lib-python/2.7/urllib.py
--- a/lib-python/2.7/urllib.py
+++ b/lib-python/2.7/urllib.py
@@ -1205,15 +1205,17 @@
# 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'"""
diff --git a/lib-python/2.7/urlparse.py b/lib-python/2.7/urlparse.py
--- a/lib-python/2.7/urlparse.py
+++ b/lib-python/2.7/urlparse.py
@@ -321,15 +321,17 @@
# 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.
diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -272,7 +272,7 @@
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),
diff --git a/lib_pypy/_collections.py b/lib_pypy/_collections.py
--- a/lib_pypy/_collections.py
+++ b/lib_pypy/_collections.py
@@ -142,18 +142,24 @@
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:
diff --git a/lib_pypy/conftest.py b/lib_pypy/conftest.py
deleted file mode 100644
--- a/lib_pypy/conftest.py
+++ /dev/null
@@ -1,2 +0,0 @@
-
-from pypy.conftest import *
diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py
--- a/lib_pypy/datetime.py
+++ b/lib_pypy/datetime.py
@@ -270,10 +270,21 @@
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:
@@ -281,11 +292,13 @@
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:
@@ -294,6 +307,7 @@
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):
@@ -768,7 +782,7 @@
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
@@ -889,7 +903,7 @@
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.
@@ -1150,13 +1164,14 @@
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
@@ -1387,7 +1402,7 @@
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)
@@ -1449,10 +1464,10 @@
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
@@ -1617,8 +1632,8 @@
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)
diff --git a/lib_pypy/dbm.py b/lib_pypy/dbm.py
--- a/lib_pypy/dbm.py
+++ b/lib_pypy/dbm.py
@@ -1,4 +1,4 @@
-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
@@ -11,7 +11,7 @@
class datum(Structure):
_fields_ = [
- ('dptr', c_char_p),
+ ('dptr', POINTER(c_char)),
('dsize', c_int),
]
@@ -126,8 +126,8 @@
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:
diff --git a/lib_pypy/numpypy/core/__init__.py b/lib_pypy/numpypy/core/__init__.py
--- a/lib_pypy/numpypy/core/__init__.py
+++ b/lib_pypy/numpypy/core/__init__.py
@@ -1,2 +1,3 @@
from .fromnumeric import *
from .numeric import *
+from .shape_base import *
diff --git a/lib_pypy/numpypy/core/numeric.py b/lib_pypy/numpypy/core/numeric.py
--- a/lib_pypy/numpypy/core/numeric.py
+++ b/lib_pypy/numpypy/core/numeric.py
@@ -428,3 +428,76 @@
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,:]
diff --git a/lib_pypy/numpypy/core/shape_base.py b/lib_pypy/numpypy/core/shape_base.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/core/shape_base.py
@@ -0,0 +1,323 @@
+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):
+ """
+ Stack arrays in sequence horizontally (column wise).
+
+ Take a sequence of arrays and stack them horizontally to make
+ a single array. Rebuild arrays divided by `hsplit`.
+
+ Parameters
+ ----------
+ tup : sequence of ndarrays
+ All arrays must have the same shape along all but the second axis.
+
+ Returns
+ -------
+ stacked : ndarray
+ The array formed by stacking the given arrays.
+
+ See Also
+ --------
+ vstack : Stack arrays in sequence vertically (row wise).
+ dstack : Stack arrays in sequence depth wise (along third axis).
+ concatenate : Join a sequence of arrays together.
+ hsplit : Split array along second axis.
+
+ Notes
+ -----
+ Equivalent to ``np.concatenate(tup, axis=1)``
+
+ Examples
+ --------
+ >>> a = np.array((1,2,3))
+ >>> b = np.array((2,3,4))
+ >>> np.hstack((a,b))
+ array([1, 2, 3, 2, 3, 4])
+ >>> a = np.array([[1],[2],[3]])
+ >>> b = np.array([[2],[3],[4]])
+ >>> np.hstack((a,b))
+ array([[1, 2],
+ [2, 3],
+ [3, 4]])
+
+ """
+ arrs = map(atleast_1d,tup)
+ # As a special case, dimension 0 of 1-dimensional arrays is "horizontal"
+ if arrs[0].ndim == 1:
+ return _numpypy.concatenate(arrs, 0)
+ else:
+ return _numpypy.concatenate(arrs, 1)
+
+def dstack(tup):
+ """
+ Stack arrays in sequence depth wise (along third axis).
+
+ Takes a sequence of arrays and stack them along the third axis
+ to make a single array. Rebuilds arrays divided by `dsplit`.
+ This is a simple way to stack 2D arrays (images) into a single
+ 3D array for processing.
+
+ Parameters
+ ----------
+ tup : sequence of arrays
+ Arrays to stack. All of them must have the same shape along all
+ but the third axis.
+
+ Returns
+ -------
+ stacked : ndarray
+ The array formed by stacking the given arrays.
+
+ See Also
+ --------
+ vstack : Stack along first axis.
+ hstack : Stack along second axis.
+ concatenate : Join arrays.
+ dsplit : Split array along third axis.
+
+ Notes
+ -----
+ Equivalent to ``np.concatenate(tup, axis=2)``.
+
+ Examples
+ --------
+ >>> a = np.array((1,2,3))
+ >>> b = np.array((2,3,4))
+ >>> np.dstack((a,b))
+ array([[[1, 2],
+ [2, 3],
+ [3, 4]]])
+
+ >>> a = np.array([[1],[2],[3]])
+ >>> b = np.array([[2],[3],[4]])
+ >>> np.dstack((a,b))
+ array([[[1, 2]],
+ [[2, 3]],
+ [[3, 4]]])
+
+ """
+ return _numpypy.concatenate(map(atleast_3d,tup),2)
diff --git a/lib_pypy/pypy_test/__init__.py b/lib_pypy/pypy_test/__init__.py
deleted file mode 100644
--- a/lib_pypy/pypy_test/__init__.py
+++ /dev/null
@@ -1,1 +0,0 @@
-#
diff --git a/lib_pypy/pypy_test/hack___pypy__.py b/lib_pypy/pypy_test/hack___pypy__.py
deleted file mode 100644
--- a/lib_pypy/pypy_test/hack___pypy__.py
+++ /dev/null
@@ -1,9 +0,0 @@
-# here only to make test runs work even if not running on top of PyPy
-import sys, new
-
-def builtinify(f):
- return f
-
-pypy = new.module('__pypy__')
-pypy.builtinify = builtinify
-sys.modules.setdefault('__pypy__', pypy)
diff --git a/lib_pypy/pypy_test/inprogress_test_binascii_extra.py b/lib_pypy/pypy_test/inprogress_test_binascii_extra.py
deleted file mode 100644
--- a/lib_pypy/pypy_test/inprogress_test_binascii_extra.py
+++ /dev/null
@@ -1,19 +0,0 @@
-from __future__ import absolute_import
-from lib_pypy import binascii
-
-def test_uu():
- assert binascii.b2a_uu('1234567') == "',3(S-#4V-P \n"
- assert binascii.b2a_uu('123456789012345678901234567890123456789012345') == 'M,3(S-#4V-S at Y,#$R,S0U-C<X.3 Q,C,T-38W.#DP,3(S-#4V-S at Y,#$R,S0U\n'
- try:
- assert binascii.b2a_uu('1234567890123456789012345678901234567890123456')
- except binascii.Error:
- pass
- else:
- assert False, "Expected binascii.Error on oversize input."
- assert binascii.b2a_uu('1234567') == "',3(S-#4V-P \n"
- assert binascii.b2a_uu('123456789012345678901234567890123456789012345') == 'M,3(S-#4V-S at Y,#$R,S0U-C<X.3 Q,C,T-38W.#DP,3(S-#4V-S at Y,#$R,S0U\n'
-
-
-def test_base64():
- assert binascii.b2a_base64('xxxx') == 'eHh4eA==\n'
-
diff --git a/lib_pypy/pypy_test/test_collections.py b/lib_pypy/pypy_test/test_collections.py
deleted file mode 100644
--- a/lib_pypy/pypy_test/test_collections.py
+++ /dev/null
@@ -1,53 +0,0 @@
-from __future__ import absolute_import
-from lib_pypy import _collections as collections
-import py
-
-class TestDeque:
- def test_remove_empty(self):
- d = collections.deque([])
- py.test.raises(ValueError, d.remove, 1)
-
- def test_remove_mutating(self):
- class MutatingCmp(object):
- def __eq__(self, other):
- d.clear()
- return True
-
- d = collections.deque([MutatingCmp()])
- py.test.raises(IndexError, d.remove, 1)
-
- def test_maxlen(self):
- d = collections.deque([], 3)
- d.append(1); d.append(2); d.append(3); d.append(4)
- assert list(d) == [2, 3, 4]
- assert repr(d) == "deque([2, 3, 4], maxlen=3)"
-
- import pickle
- d2 = pickle.loads(pickle.dumps(d))
- assert repr(d2) == "deque([2, 3, 4], maxlen=3)"
-
- import copy
- d3 = copy.copy(d)
- assert repr(d3) == "deque([2, 3, 4], maxlen=3)"
-
- def test_count(self):
- d = collections.deque([1, 2, 2, 3, 2])
- assert d.count(2) == 3
- assert d.count(4) == 0
-
- def test_reverse(self):
- d = collections.deque([1, 2, 2, 3, 2])
- d.reverse()
- assert list(d) == [2, 3, 2, 2, 1]
-
- d = collections.deque(range(100))
- d.reverse()
- assert list(d) == range(99, -1, -1)
-
- def test_subclass_with_kwargs(self):
- class SubclassWithKwargs(collections.deque):
- def __init__(self, newarg=1):
- collections.deque.__init__(self)
-
- # SF bug #1486663 -- this used to erroneously raise a TypeError
- SubclassWithKwargs(newarg=1)
diff --git a/lib_pypy/pypy_test/test_coroutine.py b/lib_pypy/pypy_test/test_coroutine.py
deleted file mode 100644
--- a/lib_pypy/pypy_test/test_coroutine.py
+++ /dev/null
@@ -1,206 +0,0 @@
-from __future__ import absolute_import
-from py.test import skip, raises
-
-try:
- from stackless import coroutine, CoroutineExit
-except ImportError, e:
- skip('cannot import stackless: %s' % (e,))
-
-
-class Test_Coroutine:
-
- def test_is_zombie(self):
- co = coroutine()
- def f():
- print 'in coro'
- assert not co.is_zombie
- co.bind(f)
- assert not co.is_zombie
- co.switch()
- assert not co.is_zombie
-
- def test_is_zombie_del_without_frame(self):
- import gc
- res = []
- class MyCoroutine(coroutine):
- def __del__(self):
- res.append(self.is_zombie)
- def f():
- print 'in coro'
- co = MyCoroutine()
- co.bind(f)
- co.switch()
- del co
- for i in range(10):
- gc.collect()
- if res:
- break
- co = coroutine()
- co.bind(f)
- co.switch()
- assert res[0], "is_zombie was False in __del__"
-
- def test_is_zombie_del_with_frame(self):
- import gc
- res = []
- class MyCoroutine(coroutine):
- def __del__(self):
- res.append(self.is_zombie)
- main = coroutine.getcurrent()
- def f():
- print 'in coro'
- main.switch()
- co = MyCoroutine()
- co.bind(f)
- co.switch()
- del co
- for i in range(10):
- gc.collect()
- if res:
- break
- co = coroutine()
- co.bind(f)
- co.switch()
- assert res[0], "is_zombie was False in __del__"
-
- def test_raise_propagate(self):
- co = coroutine()
- def f():
- return 1/0
- co.bind(f)
- try:
- co.switch()
- except ZeroDivisionError:
- pass
- else:
- raise AssertionError("exception not propagated")
-
- def test_strange_test(self):
- def f():
- return 42
- def create():
- b = coroutine()
- b.bind(f)
- b.switch()
- return b
- a = coroutine()
- a.bind(create)
- b = a.switch()
- def nothing():
- pass
- a.bind(nothing)
- def kill():
- a.kill()
- b.bind(kill)
- b.switch()
-
- def test_kill(self):
- co = coroutine()
- def f():
- pass
- assert not co.is_alive
- co.bind(f)
- assert co.is_alive
- co.kill()
- assert not co.is_alive
-
- def test_catch_coroutineexit(self):
- coroutineexit = []
- co_a = coroutine()
- co_test = coroutine.getcurrent()
-
- def a():
- try:
- co_test.switch()
- except CoroutineExit:
- coroutineexit.append(True)
- raise
-
- co_a.bind(a)
- co_a.switch()
- assert co_a.is_alive
-
- co_a.kill()
- assert coroutineexit == [True]
- assert not co_a.is_alive
-
- def test_throw(self):
- exceptions = []
- co = coroutine()
- def f(main):
- try:
- main.switch()
- except RuntimeError:
- exceptions.append(True)
-
- co.bind(f, coroutine.getcurrent())
- co.switch()
- co.throw(RuntimeError)
- assert exceptions == [True]
-
- def test_propagation(self):
- exceptions = []
- co = coroutine()
- co2 = coroutine()
- def f(main):
- main.switch()
-
- co.bind(f, coroutine.getcurrent())
- co.switch()
-
- try:
- co.throw(RuntimeError)
- except RuntimeError:
- exceptions.append(1)
-
- def f2():
- raise RuntimeError
-
- co2.bind(f2)
-
- try:
- co2.switch()
- except RuntimeError:
- exceptions.append(2)
-
- assert exceptions == [1,2]
-
- def test_bogus_bind(self):
- co = coroutine()
- def f():
- pass
- co.bind(f)
- raises(ValueError, co.bind, f)
-
- def test_simple_task(self):
- maintask = coroutine.getcurrent()
- def f():pass
- co = coroutine()
- co.bind(f)
- co.switch()
- assert not co.is_alive
- assert maintask is coroutine.getcurrent()
-
- def test_backto_main(self):
- maintask = coroutine.getcurrent()
- def f(task):
- task.switch()
- co = coroutine()
- co.bind(f,maintask)
- co.switch()
-
- def test_wrapped_main(self):
- class mwrap(object):
- def __init__(self, coro):
- self._coro = coro
-
- def __getattr__(self, attr):
- return getattr(self._coro, attr)
-
- maintask = mwrap(coroutine.getcurrent())
- def f(task):
- task.switch()
- co = coroutine()
- co.bind(f,maintask)
- co.switch()
-
diff --git a/lib_pypy/pypy_test/test_datetime.py b/lib_pypy/pypy_test/test_datetime.py
deleted file mode 100644
--- a/lib_pypy/pypy_test/test_datetime.py
+++ /dev/null
@@ -1,59 +0,0 @@
-from __future__ import absolute_import
-import py
-
-from lib_pypy import datetime
-
-def test_repr():
- print datetime
- expected = "datetime.datetime(1, 2, 3, 0, 0)"
- assert repr(datetime.datetime(1,2,3)) == expected
-
-def test_strptime():
- import time, sys
- if sys.version_info < (2, 6):
- py.test.skip("needs the _strptime module")
-
- string = '2004-12-01 13:02:47'
- format = '%Y-%m-%d %H:%M:%S'
- expected = datetime.datetime(*(time.strptime(string, format)[0:6]))
- got = datetime.datetime.strptime(string, format)
- assert expected == got
-
-def test_datetime_rounding():
- b = 0.0000001
- a = 0.9999994
-
- assert datetime.datetime.utcfromtimestamp(a).microsecond == 999999
- assert datetime.datetime.utcfromtimestamp(a).second == 0
- a += b
- assert datetime.datetime.utcfromtimestamp(a).microsecond == 999999
- assert datetime.datetime.utcfromtimestamp(a).second == 0
- a += b
- assert datetime.datetime.utcfromtimestamp(a).microsecond == 0
- assert datetime.datetime.utcfromtimestamp(a).second == 1
-
-def test_more_datetime_rounding():
- # this test verified on top of CPython 2.7 (using a plain
- # "import datetime" above)
- expected_results = {
- -1000.0: 'datetime.datetime(1970, 1, 1, 0, 43, 20)',
- -999.9999996: 'datetime.datetime(1970, 1, 1, 0, 43, 20)',
- -999.4: 'datetime.datetime(1970, 1, 1, 0, 43, 20, 600000)',
- -999.0000004: 'datetime.datetime(1970, 1, 1, 0, 43, 21)',
- -1.0: 'datetime.datetime(1970, 1, 1, 0, 59, 59)',
- -0.9999996: 'datetime.datetime(1970, 1, 1, 0, 59, 59)',
- -0.4: 'datetime.datetime(1970, 1, 1, 0, 59, 59, 600000)',
- -0.0000004: 'datetime.datetime(1970, 1, 1, 1, 0)',
- 0.0: 'datetime.datetime(1970, 1, 1, 1, 0)',
- 0.0000004: 'datetime.datetime(1970, 1, 1, 1, 0)',
- 0.4: 'datetime.datetime(1970, 1, 1, 1, 0, 0, 400000)',
- 0.9999996: 'datetime.datetime(1970, 1, 1, 1, 0, 1)',
- 1000.0: 'datetime.datetime(1970, 1, 1, 1, 16, 40)',
- 1000.0000004: 'datetime.datetime(1970, 1, 1, 1, 16, 40)',
- 1000.4: 'datetime.datetime(1970, 1, 1, 1, 16, 40, 400000)',
- 1000.9999996: 'datetime.datetime(1970, 1, 1, 1, 16, 41)',
- 1293843661.191: 'datetime.datetime(2011, 1, 1, 2, 1, 1, 191000)',
More information about the pypy-commit
mailing list