pypy

Unicode, regular expressions and PyPy

不打扰是莪最后的温柔 提交于 2019-12-07 01:02:36
问题 I wrote a program to add (limited) unicode support to Python regexes, and while it's working fine on CPython 2.5.2 it's not working on PyPy ( 1.5.0-alpha0 1.8.0, implementing Python 2.7.1 2.7.2), both running on Windows XP ( Edit: as seen in the comments, @dbaupp could run it fine on Linux). I have no idea why, but I suspect it has something to do with my uses of u" and ur" . The full source is here, and the relevant bits are: # -*- coding:utf-8 -*- import re # Regexps to match characters in

interpolate number sequence

蹲街弑〆低调 提交于 2019-12-06 13:55:49
I am trying to complete an uncomplete list of numbers, I couldn't find any pythonic way to do it. I have a sequence of days from 1 to 31, and for each day, I have a float value. #dictionnary{day: value} monthvalues = {1: 1.12, 2: 3.24, 3: 2.23, 5: 2.10, 7: 4.97} etc.. to 31st day but my data is uncomplete, and some days are missing! therefore I want to fill the missing picture mathematically this way: sample month1: {16: 2.00, 18: 4.00} #==> I want to add to the dictionnary 17: 3.00 sample month2: {10: 2.00, 14: 4.00} #==> I want to add to the dictionnary 11: 2.25, 12: 2.50, 13: 2.75 sounds

Unable to install Pip for Pypy on Debian

99封情书 提交于 2019-12-06 12:14:09
I'm currently trying to use pypy but unfortunately unable to use pip the python package manager. I added the following mirror to my source.list: deb http://ftp.de.debian.org/debian jessie main I installed then the pypy package using apt-get: apt-get install pypy Then I followed the steps given by the pypy documentation to install pip : curl -O http://python-distribute.org/distribute_setup.py curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py pypy distribute_setup.py pypy get-pip.py but i'm unable to find the pip executable for pypy. The only trace of pip for pypy is this one :

How can I embed a Python function that returns a string in C using cffi?

拜拜、爱过 提交于 2019-12-06 07:02:13
I'm trying to embed a Python function in C using PyPy and cffi. I'm following this guide from the PyPy documentation. The problem is, all the examples I've found operate on ints, and my function takes a string and returns a string. I can't seem to figure out how to embed this function in C, as C doesn't seem to really have strings, rather making do with arrays of chars. Here's what I've tried: # interface.py import cffi ffi = cffi.FFI() ffi.cdef(''' struct API { char (*generate_cool_page)(char url[]); }; ''') ... @ffi.callback("char[] (char[])") def generate_cool_page(url): # do some

Can I embed CPython inside PyPy?

吃可爱长大的小学妹 提交于 2019-12-06 04:23:22
问题 I'd like to write a performance-sensitive application in Python, so executing it under PyPy is a natural choice. However, a significant portion of my code depends on numpy, scipy, and scikit-learn. Would it be possible to embed a CPython instance within a running PyPy program in order to call array-oriented code? If not, what's the easiest way to make PyPy and CPython talk to each other? 回答1: No, you can't embed CPython inside PyPy AFAIK. You can, however, use distributed/parallel execution

Disabling std. and file I/O in Python sandbox implementation

两盒软妹~` 提交于 2019-12-06 02:33:47
问题 I'm trying to set up a Python sandbox and want to forbid access to standard and file I/O. I am running the sandbox inside of a running Python server. I've already looked at modules like RestrictedPython and PyPy ; however, I want to be able to compile the sandbox code inside of my running Python server, not through an external process. Are there any alternative ways to prevent access to commands like print , raw_input , or open ? Could the aforementioned modules be used in a way where sandbox

Using the socket module in sandboxed Pypy

亡梦爱人 提交于 2019-12-06 01:38:43
问题 I'm attempting to allow a subprocess sandboxed with Pypy to communicate, using a limited protocol, with the parent process. After reviewing the source code of the pypy/pypy/translator/sandbox/sandlib.py included with Pypy, it appears that there is a VirtualizedSocketProc that allows os.open calls to open sockets. I've changed some functionality of the code (for example, allowing TCP connections on limited ports), but very little has been changed. However, I'm unable to actually import Pypy's

Running Scrapy on PyPy

陌路散爱 提交于 2019-12-05 06:24:18
问题 Is it possible to run Scrapy on PyPy ? I've looked through the documentation and the github project, but the only place where PyPy is mentioned is that there were some unit tests being executed on PyPy 2 years ago, see PyPy support. There is also Scrapy fails in PyPy long discussion happened 3 years ago without a concrete resolution or a follow-up. From what I understand, the main Scrapy's dependency Twisted is known to work on PyPy. Scrapy also uses lxml for HTML parsing, which has a PyPy

Is there a way to avoid this memory error?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 01:53:53
I'm currently working through the problems on Project Euler, and so far I've come up with this code for a problem. from itertools import combinations import time def findanums(n): l = [] for i in range(1, n + 1): s = [] for j in range(1, i): if i % j == 0: s.append(j) if sum(s) > i: l.append(i) return l start = time.time() #start time limit = 28123 anums = findanums(limit + 1) #abundant numbers (1..limit) print "done finding abundants", time.time() - start pairs = combinations(anums, 2) print "done finding combinations", time.time() - start sums = map(lambda x: x[0]+x[1], pairs) print "done

easy_install with pypy while Python is installed

心不动则不痛 提交于 2019-12-04 20:13:25
问题 I installed PyPy while still having Python 2.7 on my system. How do I install and then use easy_install with PyPy? What is the syntax for distinguishing where I want to install to with easy_install ? Should I set any environment variables for ease of use? I'm on Windows, but these questions seem relevant for all platform... 回答1: You need to install easy_install for pypy manually. It's explained in the answer to this question : Installing Python eggs under PyPy 回答2: An alternative solution is