Re: [pygame] pygame for portable python

2009-04-11 Thread Lenard Lindstrom
Quoting Marcus von Appen :

> On, Sat Apr 11, 2009, Rene Dudfield wrote:
> 
> > Yeah cool.
> > 
> > I think it will give me a good push to finish off more tests as we change
> > towards py3k.
> > 
> > The sprite module is missing tests for a lot of the older sprite
> > functionality.  So that's the major one of the .py files I think.  Our
> build
> > scripts, and tests are the other major .py files.
> > 
> > If we start back porting some of the pgreloaded py3k stuff, then I think
> we
> > can have a pygame 1.9 prerelease for py3k within 4 weeks time(in time for
> > the course).  Remember, it only took Marcus a few days to port pgreloaded.
> 
> It has a less messy internal API, though :-).
> 
I think we could get a minimal Pygame ready: base, surface, mixer, image,
gfxdraw. I have access to an XP box for the next few days so will fork off a
python3 branch and see if I can get something to work for Windows. But don't let
that stop anyone else from adapting Pygame to Python 3. We can merge things back
later.

Lenard 


-- 
Lenard Lindstrom




Re: [pygame] Networking library

2009-04-11 Thread Nicholas Dudfield

Meh,  thunderbird always ruins formatting ... safe_eval.py attached
import compiler

class Unsafe_Source_Error(Exception):
def __init__(self,error,descr = None,node = None):
self.error = error
self.descr = descr
self.node = node
self.lineno = getattr(node,"lineno",None)

def __repr__(self):
return "Line %d.  %s: %s" % (self.lineno, self.error, self.descr)
__str__ = __repr__
   
class SafeEval(object):
def visit(self, node,**kw):
cls = node.__class__
meth = getattr(self,'visit'+cls.__name__,self.default)
return meth(node, **kw)

def default(self, node, **kw):
for child in node.getChildNodes():
return self.visit(child, **kw)

visitExpression = default

def visitConst(self, node, **kw):
return node.value

def visitDict(self,node,**kw):
return dict([(self.visit(k),self.visit(v)) for k,v in node.items])

def visitUnarySub(self, node, **kw):
return -self.visit(node.getChildNodes()[0])

def visitTuple(self,node, **kw):
return tuple(self.visit(i) for i in node.nodes)

def visitList(self,node, **kw):
return [self.visit(i) for i in node.nodes]

class SafeEvalWithErrors(SafeEval):
def default(self, node, **kw):
raise Unsafe_Source_Error("Unsupported source construct",
node.__class__,node)

def visitName(self,node, **kw):
if node.name == 'None':
return None

if node.name == 'True':
return True

if node.name == 'False':
return False

raise Unsafe_Source_Error("Strings must be quoted", 
 node.name, node)

# Add more specific errors if desired

def safe_eval(source, fail_on_error = True):
walker = fail_on_error and SafeEvalWithErrors() or SafeEval()
try:
ast = compiler.parse(source,"eval")
except SyntaxError, err:
raise
try:
return walker.visit(ast)
except Unsafe_Source_Error, err:
raise

Re: [pygame] Networking library

2009-04-11 Thread Nicholas Dudfield

Patrick Mullen wrote:

On Sat, Apr 11, 2009 at 2:55 AM, Chris McCormick  wrote:
  

Hi,

On Fri, Apr 10, 2009 at 04:44:30PM -0700, Patrick Mullen wrote:


Python2.6 comes with json.  Other than that, it is a small thing to include.

The library seems to be built around json, so removing it as a
dependency doesn't make much sense.
  

Actually I don't think it would be a huge job to change the serialisation
method to something else, optionally. I'll have a look it and see. My only
concern is about security - I chose JSON serialisation over something like
pickling because there's no way a client can inject malicious code using JSON.
I wonder if there's some other safe, built-in, pythonic way of serialising data
structures that I don't know about?



True. You could probably make the serialization abstract and allow
other methods, by plugging in a different Serializer class of some
sort.  Other than json, yaml, xml, etc I don't know any other good
serialization for python, and everything I can think of is a
dependency. Maybe for easy testing it could work with repr/eval, but
prefers json if it is there.  (Repr/eval can serialize the same
dictionaries that json can, and I think it's a bit faster too, its
just a bit more dangerous)

  
I'm not exactly sure how `safe` they really are but I found a recipe for 
`safe eval` (I think on activestate) using the built in compiler module
that I iirc works on >= 2.4 python.  Only about 70 lines of code or so. 
The eval only work on literals ala JSON


I wrote some tests somewhere but I can't seem to place them.  Anway,  in 
todays broadband world what's a few K for simpleson included.



import compiler

class Unsafe_Source_Error(Exception):
   def __init__(self,error,descr = None,node = None):
   self.error = error
   self.descr = descr
   self.node = node
   self.lineno = getattr(node,"lineno",None)
  
   def __repr__(self):

   return "Line %d.  %s: %s" % (self.lineno, self.error, self.descr)
   __str__ = __repr__   
 
class SafeEval(object):

   def visit(self, node,**kw):
   cls = node.__class__
   meth = getattr(self,'visit'+cls.__name__,self.default)
   return meth(node, **kw)
  
   def default(self, node, **kw):

   for child in node.getChildNodes():
   return self.visit(child, **kw)
  
   visitExpression = default
  
   def visitConst(self, node, **kw):

   return node.value

   def visitDict(self,node,**kw):
   return dict([(self.visit(k),self.visit(v)) for k,v in node.items])
  
   def visitUnarySub(self, node, **kw):

   return -self.visit(node.getChildNodes()[0])
  
   def visitTuple(self,node, **kw):

   return tuple(self.visit(i) for i in node.nodes)
  
   def visitList(self,node, **kw):

   return [self.visit(i) for i in node.nodes]

class SafeEvalWithErrors(SafeEval):
   def default(self, node, **kw):
   raise Unsafe_Source_Error("Unsupported source construct",
   node.__class__,node)

   def visitName(self,node, **kw):
   if node.name == 'None':
   return None

   if node.name == 'True':
   return True

   if node.name == 'False':
   return False
  
   raise Unsafe_Source_Error("Strings must be quoted",

node.name, node)

   # Add more specific errors if desired

def safe_eval(source, fail_on_error = True):
   walker = fail_on_error and SafeEvalWithErrors() or SafeEval()
   try:
   ast = compiler.parse(source,"eval")
   except SyntaxError, err:
   raise
   try:
   return walker.visit(ast)
   except Unsafe_Source_Error, err:
   raise










Re: [pygame] Networking library

2009-04-11 Thread René Dudfield
hi,

Just include simplejson with your library, but rename it so if someone has
their own version installed it will use that :)

try:
import json
except ImportError:
import mysimplejson as json


cheers,

On Sat, Apr 11, 2009 at 7:55 PM, Chris McCormick  wrote:

> Hi,
>
> On Fri, Apr 10, 2009 at 04:44:30PM -0700, Patrick Mullen wrote:
> > Python2.6 comes with json.  Other than that, it is a small thing to
> include.
> >
> > The library seems to be built around json, so removing it as a
> > dependency doesn't make much sense.
>
> Actually I don't think it would be a huge job to change the serialisation
> method to something else, optionally. I'll have a look it and see. My only
> concern is about security - I chose JSON serialisation over something like
> pickling because there's no way a client can inject malicious code using
> JSON.
> I wonder if there's some other safe, built-in, pythonic way of serialising
> data
> structures that I don't know about?
>
> > The whiteboard example is very impressive!  It looks a lot easier to
> > start working with than twisted.
>
> Thanks! My intention was for it to be extremely simple, and lightweight,
> which
> Twisted isn't (/me dons his flame retardant suit). Part of being
> lightweight
> and simple is probably removing dependencies on unneccesary third party
> libraries, so I think I will have a crack at removing the simplejson
> requirement, and also making the built-in JSON of 2.6 useable.
>
> Best,
>
> Chris.
>
> ---
> http://mccormick.cx
>


Re: [pygame] Networking library

2009-04-11 Thread Patrick Mullen
On Sat, Apr 11, 2009 at 2:55 AM, Chris McCormick  wrote:
> Hi,
>
> On Fri, Apr 10, 2009 at 04:44:30PM -0700, Patrick Mullen wrote:
>> Python2.6 comes with json.  Other than that, it is a small thing to include.
>>
>> The library seems to be built around json, so removing it as a
>> dependency doesn't make much sense.
>
> Actually I don't think it would be a huge job to change the serialisation
> method to something else, optionally. I'll have a look it and see. My only
> concern is about security - I chose JSON serialisation over something like
> pickling because there's no way a client can inject malicious code using JSON.
> I wonder if there's some other safe, built-in, pythonic way of serialising 
> data
> structures that I don't know about?

True. You could probably make the serialization abstract and allow
other methods, by plugging in a different Serializer class of some
sort.  Other than json, yaml, xml, etc I don't know any other good
serialization for python, and everything I can think of is a
dependency. Maybe for easy testing it could work with repr/eval, but
prefers json if it is there.  (Repr/eval can serialize the same
dictionaries that json can, and I think it's a bit faster too, its
just a bit more dangerous)


Re: [pygame] Networking library

2009-04-11 Thread Chris McCormick
Hi,

On Fri, Apr 10, 2009 at 04:44:30PM -0700, Patrick Mullen wrote:
> Python2.6 comes with json.  Other than that, it is a small thing to include.
> 
> The library seems to be built around json, so removing it as a
> dependency doesn't make much sense.

Actually I don't think it would be a huge job to change the serialisation
method to something else, optionally. I'll have a look it and see. My only
concern is about security - I chose JSON serialisation over something like
pickling because there's no way a client can inject malicious code using JSON.
I wonder if there's some other safe, built-in, pythonic way of serialising data
structures that I don't know about?

> The whiteboard example is very impressive!  It looks a lot easier to
> start working with than twisted.

Thanks! My intention was for it to be extremely simple, and lightweight, which
Twisted isn't (/me dons his flame retardant suit). Part of being lightweight
and simple is probably removing dependencies on unneccesary third party
libraries, so I think I will have a crack at removing the simplejson
requirement, and also making the built-in JSON of 2.6 useable.

Best,

Chris.

---
http://mccormick.cx


Re: [pygame] PyConsole IN Pygame?

2009-04-11 Thread Campbell Barton
was going to do IPython at first but autocompleation isnt that hard to
do when you have the events (added basic autocompleate today), there
are other features but personally I just want autocompleate!.
It also adds an extra dependency.

I know other people have PyConsoles in their engines but the one I saw
from Soya3d was mixed in with its own classes, so I was thinking a
reference implementation could be more useful to others.

On Fri, Apr 10, 2009 at 9:12 PM, René Dudfield  wrote:
> Hi,
>
> there are some consoles around... search on the pygame website.
>
> An ipython based one would be awesome.  Note, that pygame has clipboard
> support since 1.8, so would be good for selecting/copying text and such.
> Also copying in image data from an editor(gimp) and pasting it into the
> console - assigning it to replace in game graphics from the clipboard!
>
> Would be great if we had a nice working implementation.
>
>
> cheers,
>
>
>
> On Fri, Apr 10, 2009 at 8:03 PM, Campbell Barton 
> wrote:
>>
>> Hi, have been writing basic console in blender3d's game engine but I
>> was thinking that anyone else trying to write an in-game console (like
>> in quake :) ) would have to do almost the same things.
>> There is just some differences when you are getting events directly,
>> and having to do a basic readline style line editor in python which
>> could be generic between blender3d or any other engine.
>>
>> Requirements are that you can get events, render text and store the
>> console object between execution's.
>>
>> I was wondering if anyone had written a python console in PyGame? or
>> could it be useful to port as a testcase?
>>
>> --
>> - Campbell
>
>



-- 
- Campbell


Re: [pygame] pygame for portable python

2009-04-11 Thread Marcus von Appen
On, Sat Apr 11, 2009, Rene Dudfield wrote:

> Yeah cool.
> 
> I think it will give me a good push to finish off more tests as we change
> towards py3k.
> 
> The sprite module is missing tests for a lot of the older sprite
> functionality.  So that's the major one of the .py files I think.  Our build
> scripts, and tests are the other major .py files.
> 
> If we start back porting some of the pgreloaded py3k stuff, then I think we
> can have a pygame 1.9 prerelease for py3k within 4 weeks time(in time for
> the course).  Remember, it only took Marcus a few days to port pgreloaded.

It has a less messy internal API, though :-).

Regards
Marcus


pgpM8zOi3tbyf.pgp
Description: PGP signature