Generating class definitions at runtime in memory from XSD or JSON

2012-02-16 Thread Stodge
Does anyone know of a library to generate class definitions in memory,
at runtime, from XSD or JSON? I know about PyXB, generateDS and some
others, but they all rely on generating python source files at the
command line, and then using those to parse XML.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Python DXF import library?

2010-04-20 Thread Stodge
Is anyone aware of a Python DXF import library? I think I remember
seeing converters but so far I haven't found a library. I need to
write a tool that reads DXFs so I'm not yet sure if a converter would
be of any use. Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Can I configure Markdown to not wrap my text in elements?

2009-12-22 Thread Stodge
I want to use Markdown to process some text before displaying it in a
list. However, Markdown, by default, wraps the resulting text in 
elements, which screws up my list and displays the list item symbol
and text on different lines. Can I stop Markdown from wrapping text in
paragraphs elements? Sorry if this is not the right group.

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Twisted Matrix and multicast broadcast

2008-10-09 Thread Stodge
On Oct 9, 9:33 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On Thu, 9 Oct 2008 06:03:44 -0700 (PDT), Stodge <[EMAIL PROTECTED]> wrote:
> > [snip]
> >class MulticastServerUDP(DatagramProtocol):
> >    def startProtocol(self):
> >        print 'Started Listening'
> >        # Join a specific multicast group, which is the IP we will
> >respond to
> >        self.transport.joinGroup('224.0.0.1')
>
> > [snip]
>
> >class MulticastClientUDP(DatagramProtocol):
> >    def startProtocol(self):
> >        print 'Started Listening'
> >        # Join a specific multicast group, which is the IP we will
> >respond to
> >        self.transport.joinGroup('224.0.0.1')
>
> > [snip]
>
> >No surprises there! But how do I get the server to send to all clients
> >using multicast? transport.write requires an address. Any suggestions
> >appreciated.
>
> Your server and client are both listening on the multicast address
> 224.0.0.1.  Traffic sent to that address will be delivered to both
> of them.  If you want to send something to all clients listening on
> that address, then that's the address to pass to transport.write.
>
> Jean-Paul

Thanks. So the server write should be:

self.transport.write("data", ('224.0.0.1', 8005))

I guess I can't run multiple peers on the same PC as they'll all be
listening on port 8005.
--
http://mail.python.org/mailman/listinfo/python-list


Twisted Matrix and multicast broadcast

2008-10-09 Thread Stodge
I'm trying to get a simple multicast application working using
Twisted; so far I have:

from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from twisted.application.internet import MulticastServer

class MulticastServerUDP(DatagramProtocol):
def startProtocol(self):
print 'Started Listening'
# Join a specific multicast group, which is the IP we will
respond to
self.transport.joinGroup('224.0.0.1')

def datagramReceived(self, datagram, address):
# The uniqueID check is to ensure we only service requests
from
# ourselves
if datagram == 'UniqueID':
print "Server Received: " + repr(datagram)
self.transport.write("data", address)

# Listen for multicast on 224.0.0.1:8005
reactor.listenMulticast(8005, MulticastServerUDP())
reactor.run()


and:



from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from twisted.application.internet import MulticastServer

class MulticastClientUDP(DatagramProtocol):
def startProtocol(self):
print 'Started Listening'
# Join a specific multicast group, which is the IP we will
respond to
self.transport.joinGroup('224.0.0.1')

self.transport.write('UniqueID',('224.0.0.1', 8005))

def datagramReceived(self, datagram, address):
print "Received:" + repr(datagram)

# Send multicast on 224.0.0.1:8005, on our dynamically allocated port
reactor.listenMulticast(0, MulticastClientUDP())
reactor.run()



No surprises there! But how do I get the server to send to all clients
using multicast? transport.write requires an address. Any suggestions
appreciated.

Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Boost Python DLL from Boost Pro is built incorrectly?

2008-08-20 Thread Stodge
I'm having issues with Boost Python, downloaded via http://www.boostpro.com.
I *think* it's related to WinXP side by side assemblies. My
application that uses Boost Python fails to start.

I ran dependancy walker on the Boost Python DLL and I get the
following:

Error: The Side-by-Side configuration information for "c:\data\excds
\test adaptation\BOOST_PYTHON-VC80-MT-1_35.DLL" contains errors. This
application has failed to start because the application configuration
is incorrect. Reinstalling the application may fix this problem
(14001).
Error: At least one required implicit or forwarded dependency was not
found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing
export function in a delay-load dependent module.

I removed the installation of the 1.35 binaries and reverted to
1.34.1, rebuilt my app and it works fine. So I think there's a problem
with the 1.35 Boost Python DLL from Boost Pro. Could someone verify?

Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boost Python - C++ class' private static data blown away before accessing in Python?

2008-07-09 Thread Stodge
Oops - I didn't see my post so I thought something had gone wrong and
reposted. Apologies for the multiple posts.

On Jul 9, 11:57 am, Stodge <[EMAIL PROTECTED]> wrote:
> Could it be a boundary problem? The static data is initialised by the
> application. The problem arises when the python module tries to access
> it.
>
> On Jul 5, 11:14 pm, Giuseppe Ottaviano <[EMAIL PROTECTED]> wrote:
>
> > > In Python, I retrive an Entity from the EntityList:
>
> > > elist = EntityList()
> > > elist.append(Entity())
> > > elist.append(Entity())
>
> > > entity = elist.get_at(0)
>
> > > entity.foo()
>
> > > But it crashes inside foo() as the private static data is empty; or
> > > rather the string array is empty. I know before that point that the
> > > private static data is valid when accessed earlier by the C++ code as
> > > the program works fine. It just won't work from Python, so somehow the
> > > private static data has been blown away but I can't work out where or
> > > why.
>
> > Probably it is a problem of lifetime. What is the signature of append?  
> > Who deletes the appended Entity in C++ code?
> > If append takes a raw pointer, Boost.Python copies the pointer but  
> > destroys the Entity object because it is a temporary and its reference  
> > count went to zero. So the pointer in the list is referring to a  
> > destroyed object, which results in undefined behaviour.
>
> > Did you have a look at the lifetime policies of Boost.Python? The  
> > simplest way to workaround the problem is using const reference  
> > arguments, and always use value semantics. If it can result in a  
> > performance penalty, another simple way is using shared_ptr's, which  
> > have their own reference count (different from the one in CPython  
> > lib), but Boost.Python does the magic to make them work together.
>
> > HTH,
> > Giuseppe

--
http://mail.python.org/mailman/listinfo/python-list


Re: Boost Python - C++ class' private static data blown away before accessing in Python?

2008-07-09 Thread Stodge
Could it be a boundary problem? The static data is initialised by the
application. The problem arises when the python module tries to access
it.

On Jul 5, 11:14 pm, Giuseppe Ottaviano <[EMAIL PROTECTED]> wrote:
> > In Python, I retrive an Entity from the EntityList:
>
> > elist = EntityList()
> > elist.append(Entity())
> > elist.append(Entity())
>
> > entity = elist.get_at(0)
>
> > entity.foo()
>
> > But it crashes inside foo() as the private static data is empty; or
> > rather the string array is empty. I know before that point that the
> > private static data is valid when accessed earlier by the C++ code as
> > the program works fine. It just won't work from Python, so somehow the
> > private static data has been blown away but I can't work out where or
> > why.
>
> Probably it is a problem of lifetime. What is the signature of append?  
> Who deletes the appended Entity in C++ code?
> If append takes a raw pointer, Boost.Python copies the pointer but  
> destroys the Entity object because it is a temporary and its reference  
> count went to zero. So the pointer in the list is referring to a  
> destroyed object, which results in undefined behaviour.
>
> Did you have a look at the lifetime policies of Boost.Python? The  
> simplest way to workaround the problem is using const reference  
> arguments, and always use value semantics. If it can result in a  
> performance penalty, another simple way is using shared_ptr's, which  
> have their own reference count (different from the one in CPython  
> lib), but Boost.Python does the magic to make them work together.
>
> HTH,
> Giuseppe

--
http://mail.python.org/mailman/listinfo/python-list


Re: Boost Python - C++ class' private static data blown away before accessing in Python?

2008-07-09 Thread Stodge
I wonder if it's a DLL boundary problem.

On Jul 5, 11:14 pm, Giuseppe Ottaviano <[EMAIL PROTECTED]> wrote:
> > In Python, I retrive an Entity from the EntityList:
>
> > elist = EntityList()
> > elist.append(Entity())
> > elist.append(Entity())
>
> > entity = elist.get_at(0)
>
> > entity.foo()
>
> > But it crashes inside foo() as the private static data is empty; or
> > rather the string array is empty. I know before that point that the
> > private static data is valid when accessed earlier by the C++ code as
> > the program works fine. It just won't work from Python, so somehow the
> > private static data has been blown away but I can't work out where or
> > why.
>
> Probably it is a problem of lifetime. What is the signature of append?  
> Who deletes the appended Entity in C++ code?
> If append takes a raw pointer, Boost.Python copies the pointer but  
> destroys the Entity object because it is a temporary and its reference  
> count went to zero. So the pointer in the list is referring to a  
> destroyed object, which results in undefined behaviour.
>
> Did you have a look at the lifetime policies of Boost.Python? The  
> simplest way to workaround the problem is using const reference  
> arguments, and always use value semantics. If it can result in a  
> performance penalty, another simple way is using shared_ptr's, which  
> have their own reference count (different from the one in CPython  
> lib), but Boost.Python does the magic to make them work together.
>
> HTH,
> Giuseppe

--
http://mail.python.org/mailman/listinfo/python-list


Re: Boost Python - C++ class' private static data blown away before accessing in Python?

2008-07-09 Thread Stodge
Thanks. Maybe it's a DLL boundary issue? I'll look into this too.

On Jul 5, 11:14 pm, Giuseppe Ottaviano <[EMAIL PROTECTED]> wrote:
> > In Python, I retrive an Entity from the EntityList:
>
> > elist = EntityList()
> > elist.append(Entity())
> > elist.append(Entity())
>
> > entity = elist.get_at(0)
>
> > entity.foo()
>
> > But it crashes inside foo() as the private static data is empty; or
> > rather the string array is empty. I know before that point that the
> > private static data is valid when accessed earlier by the C++ code as
> > the program works fine. It just won't work from Python, so somehow the
> > private static data has been blown away but I can't work out where or
> > why.
>
> Probably it is a problem of lifetime. What is the signature of append?  
> Who deletes the appended Entity in C++ code?
> If append takes a raw pointer, Boost.Python copies the pointer but  
> destroys the Entity object because it is a temporary and its reference  
> count went to zero. So the pointer in the list is referring to a  
> destroyed object, which results in undefined behaviour.
>
> Did you have a look at the lifetime policies of Boost.Python? The  
> simplest way to workaround the problem is using const reference  
> arguments, and always use value semantics. If it can result in a  
> performance penalty, another simple way is using shared_ptr's, which  
> have their own reference count (different from the one in CPython  
> lib), but Boost.Python does the magic to make them work together.
>
> HTH,
> Giuseppe

--
http://mail.python.org/mailman/listinfo/python-list


Boost Python - C++ class' private static data blown away before accessing in Python?

2008-07-04 Thread Stodge
I've exposed a C++ class to Python using Boost Python. The class,
let's say it's called Entity, contains private static data, which is
an array of strings. Though I think it implements it using MFC's
CPtrArray.

I've also exposed a public function from Entity - let's say it's
called foo. This function accesses the private static data (the string
array).

I have multiple instances of Entity stored in a custom C++ container,
which is also exposed to Python as class EntityList.

In Python, I retrive an Entity from the EntityList:

elist = EntityList()
elist.append(Entity())
elist.append(Entity())

entity = elist.get_at(0)

entity.foo()

But it crashes inside foo() as the private static data is empty; or
rather the string array is empty. I know before that point that the
private static data is valid when accessed earlier by the C++ code as
the program works fine. It just won't work from Python, so somehow the
private static data has been blown away but I can't work out where or
why.

The static data is setup at initialisation - my Python code is only
called long after initialisation is complete.

I added a static dump() function to the Entity class that dumps the
string array, and even if I just do the following in Python:

Entity.dump()

in Python, the private static data is empty. Doing the same from C++
works fine. Weird.

I know this is an impossible question to ask, but can anyone think of
something obvious I need to look into?

Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Boost::Python - Question about object ownership and lifetime

2008-05-02 Thread Stodge
Hi folks, new to Boost Python and struggling to build a prototype at
work. I thought I'd start with a conceptual question to help clarify
my understanding. I already have a basic prototype working nicely but
I'm having a few issues, which I may post about later.

A brief functional rundown of what I'm trying to prototype. Hopefully
my explanation doesn't get too confusing!

I'm embedding a python module into an application; Python will provide
application logic, responding to events such as timers expiring or the
user clicking widgets.

I have the following classes I'm exporting to Python:

Entity, DerivedEntity, EntityList (contains pointers to Entity).

They all have varying types of copy/constructors, e.g. some are
private, some have non-const copy constructors etc. It's inherited
code that I can't mess with so I'm stuck with it.

So the typical logic flow I'm looking at is:

C++ Application:

- Create an instance of EntityList called entity_list, populate with
many instances of DerivedEntity.
- Create an instance of EntityList called change_list
- Invoke python function passing entity_list and change_list as
parameters

Python:

- For each entity in entity_list:
- Invoke C++ function clone_entity, pass entity as parameter

C++ Application:

- Create clone of entity like this --> DerivedEntity* entity_copy
= new DerivedEntity(entity)
- return entity_copy to Python

Back in Python again:

- Apply logic to entity_copy returned from clone_entity C++
function
- If entity_copy updated add to change_list

Back in C++ Application:

- For each new_entity in change_list
- Apply further logic to new_entity
- Delete new_entity pointer
- Clear the change_list

I'm having problems in my prototype - it looks like I have a memory
leak but I'm not sure where. So my question is, what should I be aware
of in this logic flow with regards to object ownership and lifetime?

When I receive entity_copy in Python, returned from clone_entity, what
happens to this object when I insert it into change_list and
subsequently delete the C++ pointer? I don't know how to prove that
the Python object is being deleted and isn't hanging around due to a
lifetime issue,

I guess my main problem is that I'm entirely sure I understand object
ownership - who owns what object when it's created in C++, passed to
Python and then returned back to C++ to be deleted.

So if any of this makes sense, I would greatly appreciated any
suggestions or help. I'm very impressed with Boost Python so far but
my own lack of understanding is holding me back I think.

Thanks again
Mike
--
http://mail.python.org/mailman/listinfo/python-list


SWIG (Python) - "no constructor defined" for concrete class

2008-04-18 Thread Stodge
Yet another SWIG question (YASQ!).

I'm having a problem with using an abstract base class. When
generating the Python bindings, SWIG thinks that all the concrete
classes that derive from this abstract class are abstract too and
won't create the correct constructor.

Abstract class:

[source lang="cpp"]class CORE_API Shape
{
public:
  virtual ~Shape()
  {
nshapes--;
  };
  double  x, y;
  virtual void move(double dx, double dy);
  virtual double area(void) = 0;
  virtual double perimeter(void) = 0;
  static  int nshapes;
protected:
  Shape() {
nshapes++;
  }

};
[/source]

Derived classes:

[source lang="cpp"]class CORE_API Circle : public Shape
{
private:
  double radius;
public:
  Circle(double r): Shape(), radius(r)
  {
  };
  virtual double area(void);
  virtual double perimeter(void);
};

class CORE_API Square : public Shape
{
private:
  double width;
public:
  Square(double r): Shape(), width(r)
  {
  };
  virtual double area(void);
  virtual double perimeter(void);
};
[/source]

SWIG file:

[source lang="cpp"]class Shape
{
  virtual void move(double dx, double dy);
  virtual double area(void) = 0;
  virtual double perimeter(void) = 0;
};

class Circle: public Shape
{
Circle(double r);
virtual double area(void);
virtual double perimeter(void);
};


class Square: public Shape
{
Square(double r);
virtual double area(void);
virtual double perimeter(void);
};
[/source]

C++ COde:

[source lang="cpp"] Circle c(1.02);
std::cout << "(c++)\t\tCircle\t" << c.area() << std::endl;
Square s(9.20);
std::cout << "(c++)\t\tSquare\t" << s.area() << std::endl;

[/source]

For some reason SWIG thinks that Circle and Square are abstract. Any
ideas why? I'm rather confused by this.

Thanks as always
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving parameters between Python applications?

2007-10-13 Thread Stodge
os.getppid() isn't cross platform. I don't think it works on Windows.
I think I'll just create a simple shell script (BAT or Bash) for each
platform as needed.

Thanks

On Sep 20, 3:17 pm, David <[EMAIL PROTECTED]> wrote:
> On 9/16/07, Stodge <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm trying to do the following. I have a Python application that is
> > run:
>
> > python app1.py --location=c:\test1
>
> > What I want to do is save the location parameter, so I can then do (in
> > the same window):
>
> > python app2.py
>
> > And have app2.py automatically have access to the value of "location".
>
> > Now, the difficult part is, that in another window I want to do:
>
> > python app1.py --location=c:\test2
> > python app2.py
>
> > And have app2.py automatically get c:\test2 as the location. So the
> > two windows (consoles) are isolated from each other.
>
> > I thought I could use os.environ, but that doesn't save the variable
> > for applications that are run afterwards in the same window.
>
> Use a value based on your current tty. I don't know how to get this
> value in Python but you could just shell 'tty' and grab the output.
>
> Or, to get your parent process's pid, use os.getppid().
>
> Then, use a temporary file whose name is based on the above info.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving parameters between Python applications?

2007-09-19 Thread Stodge
I wrote a small C program in Linux and used setenv() from stdlib and
it modified the console's environment. I can also modify the console's
environment from a DOS batch file, so why not in Python?

Guess I'm inexperienced and I just don't get it. :)

On Sep 18, 11:48 am, Steve Holden <[EMAIL PROTECTED]> wrote:
> Stodge wrote:
> > os.path.expanduser isn't an option; I need each console/window to
> > maintain different values which I wouldn't get from saving to a user's
> > home directory. Unless I used a different file for each console/window
> > but that just gets me into the same situation I'm already in. I think
> > the only option is to set environment variables using another script.
> > I'm really surprised and disapponited by this.
>
> That's a sign of your inexperience, then. As someone has already pointed
> out, this is nothing to do with Python.
>
> Under UNIX/Linux you could use the $$ variable to construct a filename
> specific to a particular shell process and put it in the environment,
> but I'm not aware of a similar feature in Windows. This is probably a
> sign of *my* inexperience :-)
>
> > One option I thought of but haven't investigated, is the ability to
> > get the parent (i.e. console's) process id and use that to create a
> > file somewhere. Not sure if this is even possible.
>
> You might be able to write a Python program to access it :-)
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
>
> Sorry, the dog ate my .sigline


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving parameters between Python applications?

2007-09-18 Thread Stodge
os.path.expanduser isn't an option; I need each console/window to
maintain different values which I wouldn't get from saving to a user's
home directory. Unless I used a different file for each console/window
but that just gets me into the same situation I'm already in. I think
the only option is to set environment variables using another script.
I'm really surprised and disapponited by this.

One option I thought of but haven't investigated, is the ability to
get the parent (i.e. console's) process id and use that to create a
file somewhere. Not sure if this is even possible.



On Sep 17, 4:29 pm, [EMAIL PROTECTED] wrote:
> On Sep 17, 6:39 am, Laurent Pointal
>
> > May use simple file in known place:
> > $HOME/.myprefs
> > $HOME/.conf/myprefs
>
> > Or host specific configuration API:
> > WindowsRegistry HKEY_CURRENT_USER\Software\MySociety\MyApp\myprefs
>
> > See os.getenv, and _winreg Windows specific module.
> > See also standard ConfigParser module
>
> Also, os.path offers expanduser(). The following is reasonably
> portable:
>
> import os
>
> user_home_dir = os.path.expanduser("~")
>
> --
> --Bryan


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Saving parameters between Python applications?

2007-09-17 Thread Stodge
You're probably right!

Thanks all. :)

On Sep 17, 10:15 am, Bruno Desthuilliers  wrote:
> Stodge a écrit :
>
>
>
> > I'm trying to do the following. I have a Python application that is
> > run:
>
> > python app1.py --location=c:\test1
>
> > What I want to do is save the location parameter, so I can then do (in
> > the same window):
>
> > python app2.py
>
> > And have app2.py automatically have access to the value of "location".
>
> > Now, the difficult part is, that in another window I want to do:
>
> > python app1.py --location=c:\test2
> > python app2.py
>
> > And have app2.py automatically get c:\test2 as the location. So the
> > two windows (consoles) are isolated from each other.
>
> > I thought I could use os.environ, but that doesn't save the variable
> > for applications that are run afterwards in the same window.
>
> > Any suggestions?
>
> Yes : pass the same arg to both app1.py and app2.py !-)
>
> Braindead, I know, but still the simplest solution.


-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Saving parameters between Python applications?

2007-09-17 Thread Stodge
Good idea, but I can't guarantee that the two scripts will be run from
the same directory - so where to store the pickle?

On Sep 16, 5:25 pm, "Sebastian Bassi" <[EMAIL PROTECTED]>
wrote:
> On 9/16/07, Stodge <[EMAIL PROTECTED]> wrote:
>
> > python app1.py --location=c:\test1
> > What I want to do is save the location parameter, so I can then do (in
> > the same window):
> > python app2.py
> > And have app2.py automatically have access to the value of "location".
>
> Do app1.py to save a pickle of the value you want app2 to read.
>
> --
> Sebastián Bassi (   ). Diplomado en Ciencia y Tecnología.
> Curso Biologia molecular para programadores:http://tinyurl.com/2vv8w6
> GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D

-- 
http://mail.python.org/mailman/listinfo/python-list

Saving parameters between Python applications?

2007-09-16 Thread Stodge
I'm trying to do the following. I have a Python application that is
run:

python app1.py --location=c:\test1

What I want to do is save the location parameter, so I can then do (in
the same window):

python app2.py

And have app2.py automatically have access to the value of "location".

Now, the difficult part is, that in another window I want to do:

python app1.py --location=c:\test2
python app2.py

And have app2.py automatically get c:\test2 as the location. So the
two windows (consoles) are isolated from each other.

I thought I could use os.environ, but that doesn't save the variable
for applications that are run afterwards in the same window.

Any suggestions?

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list