win32: emulating select() on pipes

2008-03-17 Thread gangesmaster
hi i'm trying to figure out if a pipe on win32 has data for me to read. this is the code i've come up with: def poll(self, timeout, interval = 0.2): """a poor man's version of select() on win32""" from win32pipe import PeekNamedPipe from msvcrt import g

abusing exceptions for continuations

2007-12-10 Thread gangesmaster
i've had this strange idea of using the exception's traceback (which holds the stack frame) to enable functional continuations, meaning, raise some special exception which will be caught by a reactor/ scheduler/framework, which could later revive it by restoring the frame. i'm thinking of using th

Re: free variables /cell objects question

2007-01-25 Thread gangesmaster
how i manage to optimize my code from here. -tomer On Jan 25, 4:51 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Thu, 25 Jan 2007 04:29:35 -0800, Paul Rubin wrote: > > "gangesmaster" <[EMAIL PROTECTED]> writes: > >> what i see as a bug is thi

Re: free variables /cell objects question

2007-01-25 Thread gangesmaster
print "my name is", name ... return foo ... >>> def make_foos(names): ... return [make_foo(n) for n in names] ... >>> foos = make_foos(["hello", "world", "spam", "bacon"]) >>> foos[0]() my name is hello >>> f

Re: free variables /cell objects question

2007-01-23 Thread gangesmaster
ugliness :) so this is why [lambda: i for i in range(10)] will always return 9. imho that's a bug, not a feature. thanks. -tomer Duncan Booth wrote: > "gangesmaster" <[EMAIL PROTECTED]> wrote: > > > what problem does the cell object solve? > > The c

free variables /cell objects question

2007-01-23 Thread gangesmaster
why does CPython require to wrap the free variables if closure functions by a cell objects? why can't it just pass the object itself? >>> def f(x): ... def g(): ... return x+2 ... return g ... >>> g5 = f(5) >>> dis(g5) 3 0 LOAD_DEREF 0 (x)

inline metaclasses

2006-07-03 Thread gangesmaster
just something i thought looked nice and wanted to share with the rest of you: >>> class x(object): ... def __metaclass__(name, bases, dict): ... print "hello" ... return type(name, bases, dict) ... hello >>> instead of defining a separate metaclass function/class, you

suggestion: adding weakattr to stdlib

2006-07-03 Thread gangesmaster
three-liner: reposted from python-dev for more feedback. it suggests to add the weakattr class to the standard weakref.py module. comments are welcome. [ http://article.gmane.org/gmane.comp.python.devel/81875 ] From: tomer filiba gmail.com> Subject: weakattr Newsgroups: gmane.comp.python.devel D

windows and socket.dup

2006-06-23 Thread gangesmaster
what uses do you have to socket.dup? on *nixes it makes, to dup() the socket before forking, but how can that be useful on windows? -tomer -- http://mail.python.org/mailman/listinfo/python-list

carshing the interpreter in two lines

2006-06-03 Thread gangesmaster
the following (random) code crashes my interpreter (python 2.4.3/winxp): from types import CodeType as code exec code(0, 5, 8, 0, "hello moshe", (), (), (), "", "", 0, "") i would expect the interpreter to do some verifying, at least for sanity (valid opcodes, correct stack size, etc.) before exe

Re: PEP 3102 for review and comment

2006-05-24 Thread gangesmaster
None is not currently a keyword -- http://mail.python.org/mailman/listinfo/python-list

proposal: disambiguating type

2006-05-21 Thread gangesmaster
typing "help(type)" gives the following documentation: >>> help(type) Help on class type in module __builtin__: class type(object) | type(object) -> the object's type | type(name, bases, dict) -> a new type "type" behaves both as a function, that reports the type of an obje

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread gangesmaster
> Today you can archive the same effect (but not necessarily with the same > performance) with: > > for node in (x for x in tree if x.haschildren()): > true, but it has different semantic meanings -tomer -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP-xxx: Unification of for statement and list-comp syntax

2006-05-21 Thread gangesmaster
i wanted to suggest this myself. +1 -tomer -- http://mail.python.org/mailman/listinfo/python-list

sock2

2006-05-19 Thread gangesmaster
sock2 is an attempt to improve python's socket module, by a more pythonic version (options are properties, protocols are classes, etc.etc) you can get it here (including a small demo) http://iostack.wikispaces.com/download i would like to receive comments/bug reports, to improve it. just reply to

bitstream

2006-05-19 Thread gangesmaster
anyone has a good bit-stream reader and writer? (before i go to write my own) i.e. f = open(..) b = BitStream(f) b.write("10010010") b.read(5) # 10010 or something like that? -tomer -- http://mail.python.org/mailman/listinfo/python-list

Re: combining a C# GUI with Python code?

2006-05-19 Thread gangesmaster
see http://interpython.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list

released: RPyC 2.60

2006-05-19 Thread gangesmaster
Remote Python Call (RPyC) has been released. this release introduces delivering objects, reducing memory consumption with __slots__, and several other new/improved helper functions. see the release notes and changelog (on the site) for more info. home: http://rpyc.wikispaces.com -tomer -- htt

released: RPyC 2.55

2006-05-07 Thread gangesmaster
Remote Python Call (RPyC) - transparent and symmetrical python RPC and distributed computing library download and info: http://rpyc.wikispaces.com full changelog: http://rpyc.wikispaces.com/changelog release notes: http://rpyc.wikispaces.com/release+notes major changes: * added isinstance and iss

released: RPyC 2.50A

2006-04-25 Thread gangesmaster
Remote Python Call 2.50 release-candidate http://rpyc.wikispaces.com -tomer -- http://mail.python.org/mailman/listinfo/python-list

Announce: Construct has moved

2006-04-24 Thread gangesmaster
Construct, the "parsing made fun" library, has moved from it's sourceforge home to wikispaces: http://pyconstruct.wikispaces.com (the sf page redirects there) -tomer -- http://mail.python.org/mailman/listinfo/python-list

Re: threads and sys.exit()

2006-04-24 Thread gangesmaster
that's not a question of design. i just want a child-thread to kill the process. in a platform agnostic way. -- http://mail.python.org/mailman/listinfo/python-list

Re: threads and sys.exit()

2006-04-24 Thread gangesmaster
i can't make the main thread daemonic. the situation is this: * the main thread starts a thread * the new thread does sys.exit() * the new thread dies, but the process remains i can do os.kill(os.getpid()), or TerminateProcess(-1) but that's not what i want -tomer -- http://mail.python.org/mail

Re: threads and sys.exit()

2006-04-24 Thread gangesmaster
(i forgot to say it didn't work) -- http://mail.python.org/mailman/listinfo/python-list

Re: threads and sys.exit()

2006-04-24 Thread gangesmaster
>>> import threading >>> t=threading.Thread(target=sys.exit) >>> t.setDaemon(True) >>> t.start() >>> ? -- http://mail.python.org/mailman/listinfo/python-list

threads and sys.exit()

2006-04-24 Thread gangesmaster
calling sys.exit() from a thread does nothing... the thread dies, but the interpreter remains. i guess the interpreter just catches and ignore the SystemExit exception... does anybody know of a way to overcome this limitation? -tomer -- http://mail.python.org/mailman/listinfo/python-list

Re: Announce: RPyC's wiki!

2006-04-21 Thread gangesmaster
[for people who missed my previous posts] """RPyC is a transparent, symmetrical python library for distributed-computing. Pronounced "are-pie-see", it began as an RPC library (hence the name), but grew into something much more comprehensive with many use cases. It basically works by giving you ful

Announce: RPyC's wiki!

2006-04-21 Thread gangesmaster
the RPyC's project page has moved to http://rpyc.wikispaces.com the old site (http://rpyc.sourceforge.net) redirects there now. because it's the official site, i chose to limit changes to members only. it's so much easier to maintain the wiki that the crappy htmls at sourceforge :) anyway, the ne

Re: Property In Python

2006-04-21 Thread gangesmaster
class person(object): def _get_age(self): return self.__age age = property(_get_age) # a read-only property def _get_name(self): return self.__name def _set_name(self, value): self.__name = value name = property(_get_name, _set_name) -- http://mail.pyt

Re: How protect proprietary Python code? (bytecode obfuscation?, what better?)

2006-04-18 Thread gangesmaster
okay, i got the name wrong. i wasn't trying to provide production-level code, just a snippet. the function you want is PyRun_SimpleString( const char *command) #include char secret_code[] = "print 'moshe'"; int main() { return PyRun_SimpleString(secret_code); } and you need to link with py

a flattening operator?

2006-04-17 Thread gangesmaster
as we all know, * (asterisk) can be used to "inline" or "flatten" a tuple into an argument list, i.e.: def f(a, b, c): ... x = (1,2,3) f(*x) so... mainly for symmetry's sake, why not make a "flattening" operator that also works outside the context of function calls? for example: a = (1,2,3)

Re: How protect proprietary Python code? (bytecode obfuscation?, what better?)

2006-04-17 Thread gangesmaster
well, you can do something silly: create a c file into which you embed your code, ie., #include char code[] = "print 'hello moshe'"; void main(...) { Py_ExecString(code); } then you can compile the C file into an object file, and use regular obfuscators/anti-debuggers. of course people who

Re: PEP 359: The "make" Statement

2006-04-16 Thread gangesmaster
? i really liked it -tomer -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 359: The "make" Statement

2006-04-13 Thread gangesmaster
"make type" is uber leet -- http://mail.python.org/mailman/listinfo/python-list

Announce: Construct's wiki!

2006-04-13 Thread gangesmaster
finally, i opened a wiki for Construct, the "parsing made fun" library. the project's page: http://pyconstruct.sourceforge.net/ the project's wiki: http://pyconstruct.wikispaces.com/ (anyone can edit) so now we have one place where people can share inventory constructs, questions-and-answers, pat

Re: pondering about the essence of types in python

2006-03-26 Thread gangesmaster
i dont think it's possible, to create proxy classes, but even if i did, calling remote methods with a `self` that is not an instance of the remote class would blow up. -tomer -- http://mail.python.org/mailman/listinfo/python-list

Re: pondering about the essence of types in python

2006-03-25 Thread gangesmaster
i was taking about python... -- http://mail.python.org/mailman/listinfo/python-list

pondering about the essence of types in python

2006-03-25 Thread gangesmaster
let's start with a question: == >>> class z(object): ... def __init__(self): ... self.blah=5 ... >>> class x(object): ... def __init__(self): ... z.__init__(self) ... >>> y=x() Traceback (most recent call last): File "", line 1, in ? File "", line 3, in

Re: why use special config formats?

2006-03-11 Thread gangesmaster
>> Why is the first uglier than the second? YES THATS THE POINT. PYTHON CAN BE USED JUST LIKE A CONFIG FILE. and if your users did timeout = "300" instead of timeout = 300 then either your config parser must be uber-smart and all-knowing, and check the types of key-value pairs, or your server wou

Re: why use special config formats?

2006-03-11 Thread gangesmaster
> Huh? You think a competent sys admin can't learn enough Python to hack > your pickled file? > > Binary configs only keep out legitimate users who don't have the time or > ability to learn how to hack the binary format. Black hats and power users > will break your binary format and hack them anywa