Re: Can code objects outlive the interpreter that created them?

2010-06-15 Thread Thomas Jollans
On 06/15/2010 10:51 PM, Andy Jost wrote: > Hi, > > > > I’m working on an application program that embeds Python using the > C-API. Sometimes, I need to call functions written in pure Python from > the C code, so I use Py_CompileString and PyEval_EvalCode. I'd recommend putting your Python code

Can code objects outlive the interpreter that created them?

2010-06-15 Thread Andy Jost
Hi, I'm working on an application program that embeds Python using the C-API. Sometimes, I need to call functions written in pure Python from the C code, so I use Py_CompileString and PyEval_EvalCode. I would like to avoid compiling the same code over and over by storing the result of Py_Compi

Re: lxml + mod_python: cannot unmarshal code objects in restricted execution mode

2007-09-14 Thread Dmitri Fedoruk
On Sep 14, 3:04 am, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > Try forcing mod_python to run your code in the first interpreter > instance created by Python. > PythonInterpreter main_interpreter Thank you very much, that solved the problem! A more detailed discussion can also be found in the l

Re: lxml + mod_python: cannot unmarshal code objects in restricted execution mode

2007-09-13 Thread Graham Dumpleton
on, exc: > logger.log(logging.CRITICAL, exc.__str__() ) > > try: > result_tree = transform(data) > return etree.tostring(result_tree, 'utf-8') > except Exception, exc: > print "xslt processing error!", exc.__str__() >

Re: lxml + mod_python: cannot unmarshal code objects in restricted execution mode

2007-09-13 Thread Dmitri Fedoruk
On Sep 13, 5:05 pm, Dmitri Fedoruk <[EMAIL PROTECTED]> wrote: > So, my configuration is the following: > Python 2.5.1 > Server version: Apache/2.2.4 (FreeBSD) > mod_python-3.3.1 update: lxml-1.3.4 libxslt-1.1.21 libxml2-2.6.29 -- http://mail.python.org/mailman/listinfo/python-list

Re: lxml + mod_python: cannot unmarshal code objects in restricted execution mode

2007-09-13 Thread Stefan Behnel
Dmitri Fedoruk wrote: > def extApplyXslt(xslt, data, logger ): > try: > strXslt = urllib2.urlopen(xslt).read() > # i have to read the xslt url to the python string > except urllib2.HTTPError, e: >... > except urllib2.URLError, e: >. >

lxml + mod_python: cannot unmarshal code objects in restricted execution mode

2007-09-13 Thread Dmitri Fedoruk
xcept Exception, exc: logger.log(logging.CRITICAL, exc.__str__() ) try: result_tree = transform(data) return etree.tostring(result_tree, 'utf-8') except Exception, exc: print "xslt processing error!", exc.__str__() return "" It dies

Re: Code objects

2007-07-24 Thread Terry Reedy
ect has one code attribute, .func_code I think. On the other hand, you should be able to attach other code objects under different names, such as .func_code2. Such would, however, be ignored in function calls. | For example, will the following code ever create a | list whose length is gr

Code objects

2007-07-23 Thread Evan Klitzke
I was playing around with the inspect module tonight, and I have a question about "code components". Can an object have more than one code component? For example, will the following code ever create a list whose length is greater than one? import inspect # Some code here defining an object/functi

Re: Functions and code objects

2006-07-27 Thread Fuzzyman
Duncan Booth wrote: > Fuzzyman wrote: [snip..] > > Does this do what you wanted? Instead of messing about with the code object > just work out which values from the namespace the function actually > expects. > > >>> def callfromnamespace(fn, namespace): > names = fn.func_code.co_varnames[:fn.f

Re: Functions and code objects

2006-07-27 Thread Fuzzyman
Simon Forman wrote: > Fuzzyman wrote: [snip..] > > I was hoping I could get to the code object for the *body* of the > > function. Looks like that won't be possible without dis-assembling the > > bytecode or other tricks even more hackish than what I've already done. > > > > For the record, the co

Re: Functions and code objects

2006-07-27 Thread Duncan Booth
Fuzzyman wrote: >> I'd like to construct the code object so that it takes the parameters >> from the enclosing scope (the context I pass into exec I guess), >> without clobbering any local variables that may be defined in the code >> object. >> >> Anyone got any clues ? Does this do what you want

Re: Functions and code objects

2006-07-27 Thread Simon Forman
Fuzzyman wrote: > Fuzzyman wrote: > > Fuzzyman wrote: > > > Hello all, > > > > > > I'm trying to extract the code object from a function, and exec it > > > without explicitly passing parameters. > > > > > > The code object 'knows' it expects to receive paramaters. It's > > > 'arg_count' attribute i

Re: Functions and code objects

2006-07-27 Thread Fuzzyman
Fuzzyman wrote: > Fuzzyman wrote: > > Hello all, > > > > I'm trying to extract the code object from a function, and exec it > > without explicitly passing parameters. > > > > The code object 'knows' it expects to receive paramaters. It's > > 'arg_count' attribute is readonly. > > > > How can I set

Re: Functions and code objects

2006-07-27 Thread Fuzzyman
Fuzzyman wrote: > Hello all, > > I'm trying to extract the code object from a function, and exec it > without explicitly passing parameters. > > The code object 'knows' it expects to receive paramaters. It's > 'arg_count' attribute is readonly. > > How can I set the arg_count to 0, or pass paramet

Functions and code objects

2006-07-27 Thread Fuzzyman
Hello all, I'm trying to extract the code object from a function, and exec it without explicitly passing parameters. The code object 'knows' it expects to receive paramaters. It's 'arg_count' attribute is readonly. How can I set the arg_count to 0, or pass parameters to the code object when I ex

Re: Using bytecode, not code objects

2006-02-10 Thread Christos Georgiou
On Sun, 29 Jan 2006 14:51:18 -0800, rumours say that Michael Spencer <[EMAIL PROTECTED]> might have written: >> http://www.effbot.org/librarybook/marshal.htm >There's a typo in the text accompanying that example: img.get_magic() should >be >imp.get_magic(). The error is easy to explain: h

Re: Using bytecode, not code objects

2006-02-06 Thread Terry Reedy
"Raymond Hettinger" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Fabiano Sidler wrote: >> with pdb (which I'm surely not using as neatly as it could be). Or is >> there any documentation on it I couldn't find? > > The pysassem module is part of the compiler package: > > http:

Re: Using bytecode, not code objects

2006-02-06 Thread Raymond Hettinger
Fabiano Sidler wrote: > 2006/1/29, Fabiano Sidler <[EMAIL PROTECTED]>: > > 28 Jan 2006 22:02:45 -0800, Raymond Hettinger <[EMAIL PROTECTED]>: > > > But if you want to make your life unnecessarily hard, you can hack the > > > compiler module just upstream from the creation of the code object -- > >

Re: Using bytecode, not code objects

2006-02-06 Thread Fabiano Sidler
2006/1/29, Fabiano Sidler <[EMAIL PROTECTED]>: > 28 Jan 2006 22:02:45 -0800, Raymond Hettinger <[EMAIL PROTECTED]>: > > But if you want to make your life unnecessarily hard, you can hack the > > compiler module just upstream from the creation of the code object -- > > alter the newCodeObject() meth

Re: Using bytecode, not code objects

2006-01-29 Thread Michael Spencer
Fredrik Lundh wrote: > Fabiano Sidler wrote: > >> I'm looking for a way to compile python source to bytecode instead of >> code-objects. Is there a possibility to do that? The reason is: I want >> to store pure bytecode with no additional data. > > use ma

Re: Using bytecode, not code objects

2006-01-29 Thread Fredrik Lundh
Fabiano Sidler wrote: > I'm looking for a way to compile python source to bytecode instead of > code-objects. Is there a possibility to do that? The reason is: I want > to store pure bytecode with no additional data. use marshal. > The second question is, therefore: How can

Re: Using bytecode, not code objects

2006-01-28 Thread Raymond Hettinger
[Fabiano Sidler] > I'm looking for a way to compile python source to bytecode instead of > code-objects. Is there a possibility to do that? The reason is: I want > to store pure bytecode with no additional data. > > The second question is, therefore: How can I get the correct

Using bytecode, not code objects

2006-01-28 Thread Fabiano Sidler
Hi folks! I'm looking for a way to compile python source to bytecode instead of code-objects. Is there a possibility to do that? The reason is: I want to store pure bytecode with no additional data. The second question is, therefore: How can I get the correct values for a given bytecode, su

Re: Using code objects?

2005-06-22 Thread Fredrik Lundh
Chinook wrote: > When I create the code objects though, it seems a couple different ways > work and I'm wondering which is better and why (or is there a more correct > technique in this situation)? from where are you getting the source code for those code objects? from the exa

Re: Using code objects?

2005-06-21 Thread Chinook
On Tue, 21 Jun 2005 09:56:27 -0400, Konstantin Veretennicov wrote (in message <[EMAIL PROTECTED]>): > On 6/21/05, Chinook <[EMAIL PROTECTED]> wrote: >> >> When I create the code objects though, it seems a couple different ways work >> and I'm wondering which

Re: Using code objects?

2005-06-21 Thread Konstantin Veretennicov
On 6/21/05, Chinook <[EMAIL PROTECTED]> wrote: > > When I create the code objects though, it seems a couple different ways work > and I'm wondering which is better and why (or is there a more correct > technique in this situation)? > > The two different ways are illu

Using code objects?

2005-06-20 Thread Chinook
Using code objects? === As an OO exercise I have a factory pattern that returns class objects that each have an "action" method. ClassObj.action() in turn returns a code object in my recursive process loop. I create the code objects as a one time step outside