Creating instances of untrusted new-style classes

2006-05-25 Thread Devan L
Is there any safe way to create an instance of an untrusted class without consulting the class in any way? With old-style classes, I can recreate an instance from another one without worrying about malicious code (ignoring, for now, malicious code involving attribute access) as shown below.

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Devan L
Ben Finney wrote: Devan L [EMAIL PROTECTED] writes: Is there any safe way to create an instance of an untrusted class Why are you instantiating classes you don't trust? without consulting the class in any way? If you don't consult the class, how can the instance be created properly

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Devan L
Michael Spencer wrote: Devan L wrote: Is there any safe way to create an instance of an untrusted class without consulting the class in any way? With old-style classes, I can recreate an instance from another one without worrying about malicious code (ignoring, for now, malicious code

Re: Safe Python Execution

2006-02-15 Thread Devan L
Graham wrote: I've been messing around with trying to get a small sandbox like environment where i could execute python code in a safe way. Basically what the old restricted execution module attempted to do. I've written a small amount of code to get custom interpreter running, but i'm not

(Different) Try Python Update

2006-01-14 Thread Devan L
It's been a while since I've done anything, and I have finals, so if anyone wants to look at some of the source, here's the somewhat cleaned up source for bastille and modjelly. Bastille is just a sort-of-more-secure equivalent of what the code module is, in case you have no clue what it does

Re: Try Python update

2006-01-07 Thread Devan L
Mike Meyer wrote: Xavier Morel [EMAIL PROTECTED] writes: [Old message and Xavier's question] [Mike's reply to Xavier] Since Python doesn't have any way to secure the interface built-in, i'd be interrested in that. Devan apparently doesn't have as cooperative an ISP, and is working on

Re: Try Python update

2006-01-03 Thread Devan L
[EMAIL PROTECTED] wrote: I like the form, no matter what its limitations may be. Three notes: It might be a good way to catch newbi mistakes (those are the kind I make :P, thereby providing a feedback loop to improved error messages. I had no trouble with from math import * followed by

Re: Try Python update

2006-01-03 Thread Devan L
Mike Meyer wrote: [EMAIL PROTECTED] writes: [comments about Mike Meyer's try python, I think] I had no trouble with from math import * followed by print pi, but there was no prompt after the result appeared .. is that part of the 'closures' thing mentioned earlier? Hmm. Are you looking

Re: Try Python update

2006-01-01 Thread Devan L
Mike Meyer wrote: After spending time I should have been sleeping working on it, the try python site is much more functional. It now allows statements, including multi-line statements and expressions. You can't create code objects yet, so it's still more a programmable calculator than

Re: Try Python update

2006-01-01 Thread Devan L
Mike Meyer wrote: Devan L [EMAIL PROTECTED] writes: If you want to try an online P{ython tool that lets you save code, try Devan L's at http://www.datamech.com/devan/trypython/trypython.py. My code uses one of the recipes from the Python Cookbook, 7.6 Pickling Code Objects. It's limited

ANN: (Different) Try Python Beta

2005-12-28 Thread Devan L
I've spent a while putting together a partially working Try Python which handles class and function definitions. It also (used to) work with imports, but my hacked version of jelly doesn't work with it anymore, so only import this works as far as I know. It won't play nice if you store the id of

Re: ANN: (Different) Try Python Beta

2005-12-28 Thread Devan L
Steve Holden wrote: Devan L wrote: [what I said] At first I thought 'the cgitb TypeError message from import os is impressively drastic :-)'. Then I realised in a later session that import os only gave an error message after I'd run import this. Thereafter, unfortunately, almost any input

Re: ANNOUNCE; Try python beta

2005-12-19 Thread Devan L
Mike Meyer wrote: Ok, I've given it the interface I want, and made it less of an attractive nuisance. http://www.mired.org/home/mwm/try_python/ is now ready for people to play with. There's no tutorial information on it yet, that's the next thing to do. However, I won't be able to work on it

Re: CGI module does not parse data

2005-12-16 Thread Devan L
amfr wrote: I am writing a webserver, and I want it to be able to run python scripts. But when I set sys.stdin to self.rfile (using the BaseHTTPServer class, self.rfile is a input stream containing the request), the cgi module does not parse the data. Example script: import cgi form =

Re: slice notation as values?

2005-12-10 Thread Devan L
Antoon Pardon wrote: On 2005-12-10, Duncan Booth [EMAIL PROTECTED] wrote: [snip] I also think that other functions could benefit. For instance suppose you want to iterate over every second element in a list. Sure you can use an extended slice or use some kind of while. But why not extend

Re: join dictionaries using keys from one values

2005-12-05 Thread Devan L
ProvoWallis wrote: Thanks so much. I never would have been able to figure this out on my own. def dictionary_join(one, two): dict2x = dict( ((dict2[k], k) for k in dict2.iterkeys())) dict3 = dict(((k, dict2x[v]) for k,v in dict1.iteritems())) print dict3 dict1 = {1:'bbb',

Re: what's wrong with lambda x : print x/60,x%60

2005-12-05 Thread Devan L
Steve Holden wrote: [EMAIL PROTECTED] wrote: Gary Herron [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] --snip-- So just use a def. It is constantly pointed out on this list that the lambda provides no extra expressive power, it is merely a shortcut No, it is not

Re: Recursion bug...

2005-11-30 Thread Devan L
ex_ottoyuhr wrote: To start with, I'm new at Python, so if this is something relatively ordinary or a symptom of thinking in C++, I apologize... Anyhow, I'm currently trying to write a means of generating genetic-programming functions in Python; the details would be a little much for a

Re: XUL behavior in Python via XPCOM, Mozilla

2005-11-12 Thread Devan L
Terry Hancock wrote: I recently saw a claim that Mozilla XUL behaviors (normally scripted in Javascript) can (or perhaps will) be scriptable in Python. Also, other languages such as Java or Python are supported through XPCOM, said about Mozilla (from Luxor website). Yes, I know several

Re: Command-line tool able to take multiple commands at one time?

2005-11-11 Thread Devan L
Peter A. Schott wrote: OK - I justed tested and may be doing something wrong, but it didn't work when I just tried it. I have something like this: X = Value1 Y = Value2 Z = Value3 etc at the top of my script. When I copy/paste those three lines all at once into IDLE's interactive

Re: Command-line tool able to take multiple commands at one time?

2005-11-10 Thread Devan L
Peter A. Schott wrote: Per subject - I realize I can copy/paste a line at a time into an interactive session when I'm trying to debug, but was wondering if there is any tool out there that allows me to copy sections of working Python scripts to paste into my interactive console and let

Re: Underscores in Python numbers

2005-11-07 Thread Devan L
Gustav HÃ¥llberg wrote: I tried finding a discussion around adding the possibility to have optional underscores inside numbers in Python. This is a popular option available in several competing scripting langauges, that I would love to see in Python. Examples: 1_234_567 0xdead_beef

Re: Cheapest pocket device to code python on

2005-11-03 Thread Devan L
[EMAIL PROTECTED] wrote: What is the cheapest/affordable pocket device that I can code python on? I think the closest I have seen is pocketpc from this page: http://www.murkworks.com/Research/Python/PocketPCPython/Overview I would not recommend trying to code on a handheld device. Small

Re: Importing Modules

2005-11-02 Thread Devan L
Sam Pointon wrote: On the second point, a combination of sys.path, os.listdir and __import__ should do what you're after, although sifting through the whole of sys.path and subfolders from Python, rather than the interpreter itself, could be slow. (And it'll be redundant as well -

Re: Importing at runtime

2005-10-24 Thread Devan L
http://www.python.org/doc/2.4.2/lib/built-in-funcs.html or, if you want an answer in code now and don't want to read the docs def my_import(name): module = __import__(name) globals()[name] = module #not a good idea Or, seeing as how you won't be directly accessing them by name, anyways

Re: execution order in list/generator expression

2005-10-23 Thread Devan L
[EMAIL PROTECTED] wrote: Hi, I am wondering how this is evaluated. a=(x for x in [1,2,3,4]) p=[4,5] c=[x for x in p if x in list(a)] c is [] but if I expand a first, like a = list(a) c is [4] So it seems that the if part don't get expanded ? Well, for every element in p it

Re: Character Sequence Generation

2005-09-22 Thread Devan L
Jeff Schwab wrote: [EMAIL PROTECTED] wrote: Jeff Schwab wrote: What's the best way to generate a sequence of characters in Python? I'm looking for something like this Perl code: 'a' .. 'z' . import string print string.ascii_lowercase abcdefghijklmnopqrstuvwxyz Thanks. Is

Re: Newbie - instanciating classes from other files

2005-09-14 Thread Devan L
[EMAIL PROTECTED] wrote: Hey guys, i just started learning python (i usually use java/C). this has got me stumped as its not mentioned in the documentation (unless im skimming it every time). How does one instanciate a class from another file import somefile foo =

Re: infinite loop

2005-09-06 Thread Devan L
LOPEZ GARCIA DE LOMANA, ADRIAN wrote: Hi all, I have a question with some code I'm writting: def main(): if option == 1: function_a() elif option == 2: function_b() else: raise 'option has to be either 1 or 2' if iteration == True:

Re: Python compiled?

2005-09-05 Thread Devan L
billiejoex wrote: Hi all. I'm sorry for a noob question like this but I'll try to ask it anyway. One of the greatest problem that may discourage a new user to choose Python language is it's interpreted nature. What? The instant gratification of immediate results is not discouraging. Another

Re: 'isa' keyword

2005-09-03 Thread Devan L
talin at acm dot org wrote: Thanks for all the respones :) I realized up front that this suggestion is unlikely to gain approval, for reasons eloquently stated above. However, there are still some interesting issues raised that I would like to discuss. Let me first respond to a few of the

Re: python logo

2005-09-03 Thread Devan L
Xah Lee wrote: what's the decision? any reference to the discussion? i thought it is better for Python to have one single recognizable logo. Perhaps python doesn't have a logo and the official python people decided it shouldn't or just doesn't have one currently? of course, a logo helps in

Re: Adding bound methods dynamically... CORRECTED

2005-08-30 Thread Devan L
Kevin Little wrote: I want to dynamically add or replace bound methods in a class. I want the modifications to be immediately effective across all instances, whether created before or after the class was modified. I need this to work for both old ('classic') and new style classes, at both

Re: aproximate a number

2005-08-29 Thread Devan L
Thomas Bartkus wrote: On Sun, 28 Aug 2005 23:11:09 +0200, billiejoex wrote: Hi all. I'd need to aproximate a given float number into the next (int) bigger one. Because of my bad english I try to explain it with some example: 5.7 -- 6 52.987 -- 53 3.34 -- 4 2.1 -- 3 The standard

Re: aproximate a number

2005-08-29 Thread Devan L
Grant Edwards wrote: On 2005-08-30, Devan L [EMAIL PROTECTED] wrote: RoundToInt(2.0) will give you 3. That's what the OP said he wanted. The next bigger integer after 2.0 is 3. -- Grant Edwards grante Yow! I'd like TRAINED

Re: Dictionary inheritance

2005-08-12 Thread Devan L
Talin wrote: I want to make a dictionary that acts like a class, in other words, supports inheritance: If you attempt to find a key that isn't present, it searches a base dictionary, which in turn searches its base, and so on. Now, I realize its fairly trivial to code something like this

Re: Regular expression to match a #

2005-08-11 Thread Devan L
John Machin wrote: Aahz wrote: In article [EMAIL PROTECTED], John Machin [EMAIL PROTECTED] wrote: Search for r'^something' can never be better/faster than match for r'something', and with a dopey implementation of search [which Python's re is NOT] it could be much worse. So please don't

Re: Regular expression to match a #

2005-08-11 Thread Devan L
John Machin wrote: Devan L wrote: John Machin wrote: Aahz wrote: In article [EMAIL PROTECTED], John Machin [EMAIL PROTECTED] wrote: Search for r'^something' can never be better/faster than match for r'something', and with a dopey implementation of search [which Python's re

Re: NEWB: General purpose list iteration?

2005-08-11 Thread Devan L
def descend(iterable): if hasattr(iterable, '__iter__'): for element in iterable: descend(element) else: do_something(iterable) This will just do_something(object) to anything that is not an iterable. Only use it if all of your nested structures are of the same

Re: Some newbie cgi form questions...

2005-08-07 Thread Devan L
googleboy wrote: for key in form.keys():Yes, I know which fields are hidden because I made them that way, but I am trying to figure out a way I can iterate over the fields and do one thing with hidden fields (assign them to variables that tell the form how to process) and a different thing

Re: Fat and happy Pythonistas (was Re: Replacement for keyword 'global' good idea? ...)

2005-08-06 Thread Devan L
you're not seeing. And Python is standing still in many of those same ways. Take another look then. -Devan L -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Program

2005-08-05 Thread Devan L
Eric wrote: I am reading a book on Python and ran across and exercise that I just can't seem to figure out. Its pretty simple, but I just can't get past a certain point. The task is to create a program that flips a coin 100 times and keeps track of the total of heads and tails which is

Re: Wheel-reinvention with Python

2005-08-01 Thread Devan L
Ed Leafe wrote: On Sunday 31 July 2005 22:39, Paul Rubin wrote: import dabo app = dabo.dApp() dApp.start() Sorry, I couldn't do it in 5. ;-) Oh, and that includes a full menu, too. I get an ImportError exception when I try that. Any suggestions? Note that I don't get

Re: [pygame]how to copy a surface to an other surface with alpha value?

2005-07-27 Thread Devan L
flyaflya wrote: I want to join some surfaces to a new big surface with alpha cannel, I want the new surface has same pixels(inclue r,g,b and alpha value) as the pixels on the source surfaces. my code as follow: surf = pygame.Surface((200,200)) surf.blit(surf1, (0,0)) surf.blit(surf2,

Re: searching string url

2005-07-27 Thread Devan L
Sounds somewhat like homework. So I won't just give you a code solution. Use the regular expression(re) module to match the urls. -- http://mail.python.org/mailman/listinfo/python-list

Re: A Module on Time Date

2005-07-26 Thread Devan L
Robert Maas, see http://tinyurl.com/uh3t wrote: From: Robert Kern [EMAIL PROTECTED] As you can see in the datetime documentation, the module was introduced in Python 2.3. I recommend updating your Python installation. What do you mean your?? I don't have any Python installation of my

Re: Problem loading a file of words

2005-07-24 Thread Devan L
teoryn wrote: I've been spending today learning python and as an exercise I've ported a program I wrote in java that unscrambles a word. Before describing the problem, here's the code: *--beginning of file--* #!/usr/bin/python # Filename: unscram.py def sort_string(word):

Re: Problem loading a file of words

2005-07-24 Thread Devan L
Robert Kern wrote: That's definitely not the kind of dictionary that he wants. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter Oh, I missed the part where he put values in a list. --

Re: Odd behaviour of regexp module

2005-07-13 Thread Devan L
Why doesn't group have an argument? group() or group(0) returns what the pattern matched, not what it returns. -- http://mail.python.org/mailman/listinfo/python-list

Re: question on input

2005-07-12 Thread Devan L
Use raw_input instead. It returns a string of whatever was typed. Input expects a valid python expression. -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with inverted dictionary

2005-07-12 Thread Devan L
import re name = Robert f = file('phonebook.txt','r') lines = [line.rstrip(\n) for line in f.readlines()] pat = re.compile(name, re.I) related_lines = [line for line in lines if pat.search(line)] And then you write the lines in related_lines to a file. I don't really write text to files much so,

Re: Creating anonymous functions using eval

2005-07-12 Thread Devan L
How is this different from a nested function? -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with inverted dictionary

2005-07-12 Thread Devan L
I think you need to get a database. Anyways, if anything, it should create no more than 5,000 files, since 5,000 facts shouldn't talk about 30,000 animals. There have been a few discussions about looking at files in directories though, if you want to look at those. --

Re: Help with inverted dictionary

2005-07-12 Thread Devan L
Oh, I seem to have missed the part saying 'or other word'. Are you doing this for every single word in the file? -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating anonymous functions using eval

2005-07-12 Thread Devan L
Well, the string that gets passed is more or less a function definition, which is then called with exec. I don't see why you'd need to write a string out with the function definition and then call it. You could just write the function. As for the nested functions, I had been presuming that it was

Re: automatically assigning names to indexes

2005-07-12 Thread Devan L
import math class Vector: def __init__(self, coordinates): self.coordinates = coordinates self.magnitude = sum([c**2 for c in coordinates])**0.5 self.direction = getangle(Vector([1]+[0 for i in range(len(coordinates)-1)])) def dotproduct(self, vector):

Re: Creating anonymous functions using eval

2005-07-12 Thread Devan L
You missed Steven's point which is to quote the message to which you are replying. Not everyone is reading this list in a conveniently threaded form, so you need to provide some context for them to be able to follow along. Ah, sorry, I didn't quite get what he was referring to. --

Re: Yet Another Python Web Programming Question

2005-07-09 Thread Devan L
Take some time to learn one of the web frameworks. If your host doesn't already have it, ask your host if they would consider adding it. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Forum

2005-07-09 Thread Devan L
I see a total of 12 posts and 8 users. -- http://mail.python.org/mailman/listinfo/python-list

Re: removing list comprehensions in Python 3.0

2005-07-08 Thread Devan L
List comprehensions are faster than generator comprehensions for iterating over smaller sequences. -- http://mail.python.org/mailman/listinfo/python-list

Re: removing list comprehensions in Python 3.0

2005-07-08 Thread Devan L
import timeit t1 = timeit.Timer('list(i for i in xrange(10))') t1.timeit() 27.267753024476576 t2 = timeit.Timer('[i for i in xrange(10)]') t2.timeit() 15.050426800054197 t3 = timeit.Timer('list(i for i in xrange(100))') t3.timeit() 117.61078097914682 t4 = timeit.Timer('[i for i in

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Devan L
Here's a couple of examples from my own code: # from a Banzhaf Power Index calculator # adds things that aren't numbers return reduce(operator.add, (VoteDistributionTable({0: 1, v: 1}) for v in electoral_votes)) return sum([VoteDistributionTable({0:1, v:1} for v in

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Devan L
def flatten(iterable): if not hasattr(iterable, '__iter__'): return [iterable] return sum([flatten(element) for element in iterable],[]) Recursion makes things so much shorter. -- http://mail.python.org/mailman/listinfo/python-list

Re: Favorite non-python language trick?

2005-07-03 Thread Devan L
Okay, maybe that was too restrictive, reduce can *usually* be replaced with sum. Sorry about that. -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-02 Thread Devan L
Claiming that sum etc. do the same job is the whimper of someone who doesn't want to openly disagree with Guido. Could you give an example where sum cannot do the job(besides the previously mentioned product situation? Also, map is easily replaced. map(f1, sequence) == [f1(element) for element

Re: Favorite non-python language trick?

2005-07-02 Thread Devan L
sum(sequence[0] + [1/element for element in sequence[1:]]) I think that should work. -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression for pattern substitution

2005-07-01 Thread Devan L
re.replace. I don't think there's any way to avoid it. Except maybe having an alias email address or a fake one. -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-01 Thread Devan L
None of them are really indispensible. Map and filter cab be replaced with list comprehensions. reduce is redundant except when multiplying a series; there's a sum function for a reason. Lambda looks cleaner in some cases, but you don't gain any functionality. What really struck me, though, is

Re: Regular Expression for pattern substitution

2005-07-01 Thread Devan L
Hrm, thought it had one. Guess it would help if I actually used regular expression for replacement. -- http://mail.python.org/mailman/listinfo/python-list

Re: class attribute to instance attribute

2005-07-01 Thread Devan L
Well, I've never heard of a method like that for assigning variables. I'd rather put it in the __init__ method. -- http://mail.python.org/mailman/listinfo/python-list

Re: Favorite non-python language trick?

2005-07-01 Thread Devan L
With the exception of reduce(lambda x,y:x*y, sequence), reduce can be replaced with sum, and Guido wants to add a product function. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python for everything?

2005-06-30 Thread Devan L
Python for everything except things that need to be ridiculously optimized for speed. Thats what C embedded in Python and Psyco enhanced Python code is for. Oh wait, thats still all Python... -- http://mail.python.org/mailman/listinfo/python-list

Re: class attribute to instance attribute

2005-06-30 Thread Devan L
Why make it an instance attribute? Couldn't you just look at the class attribute? If its something that depends on each instance's value assigned to the attribute, why not make it an instance attribute to start with? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to run commands in command line from a script

2005-06-30 Thread Devan L
The code module, perhaps? http://www.python.org/doc/2.4.1/lib/module-code.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Escaping commas within parens in CSV parsing?

2005-06-30 Thread Devan L
Try this. re.findall(r'(.+? \(.+?\))(?:,|$)',yourtexthere) -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting string into dictionary

2005-06-30 Thread Devan L
One line solution. dict(re.findall(r'(.+?)' \| '(.+?)'(?:\s\||$),yourtexthere)) -- http://mail.python.org/mailman/listinfo/python-list

Re: regulars expressions ?

2005-06-28 Thread Devan L
re.findall(r'?(.+?)?(?:,|$)', yourtexthere) -- http://mail.python.org/mailman/listinfo/python-list

Re: regulars expressions ?

2005-06-28 Thread Devan L
Oh, oops, sorry, that code doesn't respect the quotes. Use this code: re.findall(r'(.+?|\S+)(?:,|$)', yourtexthere) -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie: Help Figger Out My Problem

2005-06-28 Thread Devan L
import random flips = 100 results = [random.randint(0,1) for i in range(flips)] heads = results.count(0) tails = results.count(1) print Heads:%s % heads print Tails:%s % tails I think this is more compact. -- http://mail.python.org/mailman/listinfo/python-list

Re: When someone from Britain speaks, Americans hear a British accent...

2005-06-28 Thread Devan L
Thats like posting about Google here because the newsgroup is hosted on Google. -- http://mail.python.org/mailman/listinfo/python-list

Re: noob question

2005-06-26 Thread Devan L
To recognize variables that you have assigned, just look for assignment. If your code is readible, and you know it well, you shouldn't need the $ sign in front of everything. -- http://mail.python.org/mailman/listinfo/python-list

Re: Favorite non-python language trick?

2005-06-26 Thread Devan L
return a if a.value == true database.query(q) unless database.connect == error (etc) if a.value == True: return a if not database.connect == error: database.query(q) Trading two words for one word doesn't necessarily make the code better. unless false then print 1 # this prints 1

Re: Favorite non-python language trick?

2005-06-25 Thread Devan L
Why overload when you can use class methods? -- http://mail.python.org/mailman/listinfo/python-list

Re: what list comprehension can't

2005-06-24 Thread Devan L
I wasn't aware that python supported if then else. -- http://mail.python.org/mailman/listinfo/python-list