Question regarding Higher-Order-Programming in Python

2010-12-22 Thread Mark Fink
I am about to learn Higher-Order-Programming with Lisp, Haskell, and
Python. Some people who have gone completely out of their mind call
this FP.

In Haskell I learned that when I use map on a list it starts nesting
as soon as I start adding elements. If I do not like the nesting I use
ConcatMap.

In Python I have a similar scenario. I have a generator which creates
some combinatorics of a input dictionary. The list starts nesting. Now
I could use reduce(concat, ...) which would be the correct thing from
a functional perspective. But from a resource utilization perspective
it is not a good idea since the reduce is executing the generator.

I tried to illustrate this using a small example (the often in
combinatorics the real thing would be much bigger that is why I need
to use a generator):

 from operator import itemgetter, concat
 import itertools as it
 from functools import partial

 dims = {'number': [1,2,3], 'letter': ['a', 'b'], 'special': ['+', '-']}
 dims
{'special': ['+', '-'], 'number': [1, 2, 3], 'letter': ['a', 'b']}
 def get_products(keys):
... # helper to get products from keys in the following form:
... # [('bold', True), ('color', 'black')]
... values  = itemgetter(*keys)(dims)
... product = it.product(*values)
... return map(partial(zip, keys), product)
...
 comb = it.combinations(dims, 2)
 comb_l = list(comb)
 comb_l
[('special', 'number'), ('special', 'letter'), ('number', 'letter')]
 res = map(get_products, comb_l)
 res
[[[('special', '+'), ('number', 1)], [('special', '+'), ('number',
2)], [('special', '+'), ('number', 3)], [('special', '-'), ('number',
1)], [('special', '-'), ('number', 2)], [('special', '-'), ('number',
3)]], [[('special', '+'), ('letter', 'a')], [('special', '+'),
('letter', 'b')], [('special', '-'), ('letter', 'a')], [('special',
'-'), ('letter', 'b')]], [[('number', 1), ('letter', 'a')],
[('number', 1), ('letter', 'b')], [('number', 2), ('letter', 'a')],
[('number', 2), ('letter', 'b')], [('number', 3), ('letter', 'a')],
[('number', 3), ('letter', 'b')]]]  # the resulting list is nested one
level to deep caused by the map(get_products, ..


My problem is that I want to get single elements from the generator
like [('special', '+'), ('number', 1)]. But this does not work because
the list is now nested to deep.

That is what I expect: (I could get something like that with the
following  res = reduce(concat, res)
[[('special', '+'), ('number', 1)], [('special', '+'), ('number', 2)],
[('special', '+'), ('number', 3)], [('special', '-'), ('number', 1)],
[('special', '-'), ('number', 2)], [('special', '-'), ('number', 3)],
[('special', '+'), ('letter', 'a')], [('special', '+'), ('letter',
'b')], [('special', '-'), ('letter', 'a')], [('special', '-'),
('letter', 'b')], [('number', 1), ('letter', 'a')], [('number', 1),
('letter', 'b')], [('number', 2), ('letter', 'a')], [('number', 2),
('letter', 'b')], [('number', 3), ('letter', 'a')], [('number', 3),
('letter', 'b')]]

I have seen the problem many times but so far I could not google a
solution on the web.

By the way do you know any substantial example using FP in Python
(generators, imap, ifilter, ...)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question regarding Higher-Order-Programming in Python

2010-12-22 Thread Mark Fink
  list(chain.from_iterable(starmap(product, izip(izip(dims.iterkeys()),

 dims.itervalues()
 [('special', '+'), ('special', '-'), ('number', 1), ('number', 2),
 ('number', 3), ('letter', 'a'), ('letter', 'b')]

 Peter

so far I have never noticed chain.from_iterable, but many thanks to
you Peter, I have now a beautiful solution to this problem.
 from itertools import chain
 comb = it.combinations(dims, 2)
 l = chain.from_iterable(it.imap(get_products, comb))
 l.next()
[('special', '+'), ('number', 1)]
 l.next()
[('special', '+'), ('number', 2)]
-- 
http://mail.python.org/mailman/listinfo/python-list


Jython Pythonpath question

2006-02-21 Thread Mark Fink
Hi there,

I have a source file FailFixture.py in the folder
D:\AUT_TEST\workspace\JyFIT\testutil. Now I want to import the file
with import testutil.FailFixture. Unfortunately I could not figure
out how to set this up. I am convinced that
D:\AUT_TEST\workspace\JyFIT should be included in the pythonpath but
it does not work. Nor does it work to include this path in the java
classpath. Any idea whats wrong?

I experiented a little at the Jython prompt:

D:\AUT_TESTjava -Dpython.home=D:\AUT_TEST\Jython21
-Dpython.path=D:\AUT_TEST\workspace\JyFIT -classpath
D:\AUT_TEST\Jython21\jython.jar;D:\AUT_TEST\JavaLib\log4j-1.2.13.jar;D:\AUT_TEST\workspace\JyFIT
org.python.util.jython

Jython 2.1 on java1.5.0_06 (JIT: null)
Type copyright, credits or license for more information.
 import testutil.FailFixture
Traceback (innermost last):
  File console, line 1, in ?
ImportError: No module named FailFixture
 ^Z

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


Re: jython socket sendall

2006-02-21 Thread Mark Fink
I used send instead. This should work.
-Mark

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


jython socket sendall

2006-02-18 Thread Mark Fink
Hi there,
I am about to port a server application from Java to Jython. For the
socket part I found some examples written in Python. I have problems to
figure out the socket part of the application. In Jython 2.1 the
sendall function is missing?

def establishConnection(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print type(self.host), repr(self.host)
print type(self.port), repr(self.port)
self.socket.connect((self.host, self.port))
#self.socketOutput = self.socket.getOutputStream()
self.socketOutput = self.socket
#self.socketReader = StreamReader(self.socket.getInputStream())
self.socketReader = self.socket
bytes = self.makeHttpRequest().encode(UTF-8)
print type(bytes), repr(bytes)
self.socketOutput.sendall(bytes)
#self.socketOutput.flush()
sys.stdout.write(http request sent\n)

-Mark

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


Re: Jython socket typecasting problems

2006-02-13 Thread Mark Fink
thanks to the help of this group I moved a tiny step forward. Obviously
it is not possible to resolve name localhost:
Type copyright, credits or license for more information.
 import socket
 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.connect(localhost, 8080)
Traceback (innermost last):
  File console, line 1, in ?
NameError: localhost
 s.connect((localhost, 8080))
Traceback (innermost last):
  File console, line 1, in ?
NameError: localhost
 s.connect(('127.0.0.1', 8080))
Traceback (innermost last):
  File console, line 1, in ?
  File D:\AUT_TEST\Jython21\Lib\socket.py, line 135, in connect
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:507)

Unfortunately this is not the solution (I tried 127.0.0.1 before my
first post).
I added the two print lines as recommended:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print type(self.host), repr(self.host)
print type(self.port), repr(self.port)
self.socket.connect((self.host, self.port))
self.socketOutput = self.socket.getOutputStream()

And more specific information:
D:\AUT_TEST\workspace\JyFIT\fitjython JyFitServer2.py 127.0.0.1 1234
12
['JyFitServer2.py', '127.0.0.1', '1234', '12']
127.0.0.1
org.python.core.PyString '127.0.0.1'
org.python.core.PyString '1234'
Traceback (innermost last):
  File JyFitServer2.py, line 148, in ?
  File JyFitServer2.py, line 31, in run
  File JyFitServer2.py, line 98, in establishConnection
  File D:\AUT_TEST\Jython21\Lib\socket.py, line 135, in connect
TypeError: java.net.Socket(): 1st arg can't be coerced to
java.net.InetAddress or String

No casting from string to string?? I learned that there is no such
thing as explicit typecasting. What to do?

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


Re: Jython inherit from Java class

2006-02-13 Thread Mark Fink
Hi Kent,
many thanks for your help! In the meantime I received my Jython
Essentials book and hope that I have much fewer questions in the near
future.
One last question for this thread. I tried to inherit from a Java class
and override on method. I figured that this approach was nonsense
because the method used private attributes of the Java class. Now I
read that there is injection used in Jython. Jython uses setter and
getter methods to do the injection, right? Unfortunately the Java class
has no setters and getters for the private members. Is there another
way to override the method besides rewriting the Java class or is this
approach really doomed?

Cheers,
Mark

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


Re: Jython inherit from Java class

2006-02-11 Thread Mark Fink
Please enlighten me. This seemed so easy yust inherit from a Java class
overwrite one method - done. At the moment I do not know how to proceed
:-((
Jython or jythonc?
==
In general is it better to run programms with the jython interpreter or
is it better to compile them first? I had the impression that the
inheritance does not work with the interpreter. Is that right?

2.1 or 2.2a
===
The programm did not compile with the 2.1 version and Java 1.5. But
with 2.2a it compiled but 2.2a is an alpha version. Assuming the
programm would compile with the Java 1.4 version would it be better
(saver, more stable, performance) to use 2.1 or 2.2a?

Inherit from java baseclass or reimplement the whole thing in jython?
=
All the problems with Jython stated when I wanted to inherit from a
Java baseclass. I wounder if I would have more success when
implementing it in pure Jython. Regarding the inheritance I had an
empty wrapper arround the Java baseclass and 70% of the unit test
passed. But the performance was ~ factor 10 slower than using the base
class directly. Does this mean that there is overhead with the
inheritanc construct and that this implementation path would always be
so slow. On the other hand would a 100% Jython solution be faster?

Mark

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


Jython socket typecasting problems

2006-02-11 Thread Mark Fink
I try to port a server application to Jython. At the moment I use
Jython21\Lib\socket.py
Currently I do face problems with casting the string localhost to the
desired value:
D:\AUT_TEST\workspace\JyFITjython fit/JyFitServer2.py localhost 1234
23
['fit/JyFitServer2.py', 'localhost', '1234', '23']
localhost
Traceback (innermost last):
  File fit/JyFitServer2.py, line 146, in ?
  File fit/JyFitServer2.py, line 31, in run
  File fit/JyFitServer2.py, line 96, in establishConnection
  File D:\AUT_TEST\Jython21\Lib\socket.py, line 135, in connect
TypeError: java.net.Socket(): 1st arg can't be coerced to
java.net.InetAddress or String

The cast to Integer for the port does not work either:

D:\AUT_TEST\workspace\JyFITjython fit/JyFitServer2.py  1234 23
['fit/JyFitServer2.py', '', '1234', '23']

Traceback (innermost last):
  File fit/JyFitServer2.py, line 146, in ?
  File fit/JyFitServer2.py, line 31, in run
  File fit/JyFitServer2.py, line 96, in establishConnection
  File D:\AUT_TEST\Jython21\Lib\socket.py, line 135, in connect
TypeError: java.net.Socket(): 2nd arg can't be coerced to int

This is the code section of my server class (I cut this from a Python
example):
def establishConnection(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((self.host, self.port))
Do I have to use explicit typecasting? How can this be achieved?

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


Re: Jython inherit from Java class

2006-02-10 Thread Mark Fink
Alan, Kent, many thanks this really helped!
But there is still a problem I guess with inheritance. I use the java
testsuit supplied with the original to test the server. If I use the
Java FitServer the testsuite can be completed. I commented everything
out from my class and it does not work??
Thats the trace when I run the JUnit testsuit:
java.io.IOException: CreateProcess: jython
D:\AUT_TEST\workspace\JyFIT\fit\JyFitServer.py
-Dpython.path='D:\AUT_TEST\workspace\JyFIT'
D:\AUT_TEST\fitnesse\fitnesse.jar localhost 1234 23 error=2
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.init(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at
FitServerTest.FitServerTest.prepareSessionProcess(FitServerTest.java:163)
at
FitServerTest.FitServerTest.testSimpleStartUp(FitServerTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Unfortunately I do not get much information at the prompt because both
Java FitServer and JyFitServer behave the same there.
D:\AUT_TESTjython D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py
-Dpython.path='D:\\AUT_TEST\\workspace\\JyFIT'
D:\\AUT_TEST\\fitnesse\\fitnesse.jar localhost 1234 23
Traceback (innermost last):
  File D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py, line 42,
in ?
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket.init(Socket.java:365)
at java.net.Socket.init(Socket.java:178)
at fit.FitServer.establishConnection(Unknown Source)
at fit.FitServer.establishConnection(Unknown Source)
at fit.FitServer.run(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyMethod.__call__(PyMethod.java)
at org.python.core.PyObject.__call__(PyObject.java)
at org.python.core.PyInstance.invoke(PyInstance.java)
at
org.python.pycode._pyx0.f$0(D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py:42)
at
org.python.pycode._pyx0.call_function(D:\\AUT_TEST\\workspace\\JyFIT\\fit\\JyFitServer.py)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at org.python.core.__builtin__.execfile_flags(__builtin__.java)
at
org.python.util.PythonInterpreter.execfile(PythonInterpreter.java)
at org.python.util.jython.main(jython.java)

java.net.ConnectException: java.net.ConnectException: Connection
refused: connect

## And the Java FitServer:
D:\AUT_TESTjava -cp D:\\AUT_TEST\\fitnesse\\fitnesse.jar fit.FitServer
localhost 1234 23
Exception in thread main java.net.ConnectException: Connection
refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at 

Re: Jython inherit from Java class

2006-02-10 Thread Mark Fink
I observed something strange when I tried to compile the jython class:
D:\AUT_TEST\workspace\JyFIT\fitjythonc JyFitServer.py
processing JyFitServer

Required packages:
  fitnesse.util
  java.io
  java.net
  fitnesse.components*

Creating adapters:

Creating .java files:
  JyFitServer module
JyFitServer extends fit.FitServer

Compiling .java to .class...
Compiling with args: ['C:\\Programme\\Java\\jdk1.5.0_06\\bin\\javac',
'-classpath',
'D:/AUT_TEST/JyFIT_port/fit;D:\\AUT_TEST\\Jython21\\jython.jar;C:\\Programme\\Java\\jdk1.5.0_06\\lib\\tools.jar;C:\\
Java\\jboss-4.0.0\\server\\default\\lib\\mysql-connector-java-2.0.14-bin.jar;C:\\Java\\jboss-4.0.0\\client\\jboss-j2ee.jar;C:\\Java\\jboss-4.0.0\\client\\jboss-client.jar;C:\\Java\\jboss-4.0.0\\client
\\jbosssx-client.jar;C:\\Java\\jboss-4.0.0\\client\\jnp-client.jar;C:\\Java\\jboss-4.0.0\\client\\jnet.jar;C:\\Java\\jboss-4.0.0\\client\\jboss-common-client.jar;C:\\Java\\jboss-4.0.0\\tomcat-4.1.x\\c
ommon\\lib\\servlet.jar;D:\\AUT_TEST\\Jython21\\jython.jar;D:\\AUT_TEST\\fitnesse\\fitnesse.jar;D:\\AUT_TEST\\JyFIT_port;%CLASSPATH%;.\\jpywork;;D:\\AUT_TEST\\Jython21\\Tools\\jythonc;D:\\AUT_TEST\\wo
rkspace\\JyFIT\\fit\\.;D:\\AUT_TEST\\Jython21\\Lib;D:\\AUT_TEST\\workspace\\JyFIT;D:\\AUT_TEST\\fitnesse\\fitnesse.jar;D:\\AUT_TEST\\Jython21',
'.\\jpywork\\JyFitServer.java']
1  D:\AUT_TEST\Jython21\org\python\core\Py.java:989: as of release 1.4,
'assert' is a keyword, and may not be used as an identifier
(try -source 1.3 or lower to use 'assert' as an identifier)
public static void assert(PyObject test, PyObject message) {
   ^
D:\AUT_TEST\Jython21\org\python\core\Py.java:995: as of release 1.4,
'assert' is a keyword, and may not be used as an identifier
(try -source 1.3 or lower to use 'assert' as an identifier)
public static void assert(PyObject test) {
   ^
D:\AUT_TEST\Jython21\org\python\core\Py.java:996: ')' expected
assert(test, Py.None);
   ^
D:\AUT_TEST\Jython21\org\python\parser\PythonGrammar.java:6739: as of
release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.4 or lower to use 'enum' as an identifier)
  for (java.util.Enumeration enum = jj_expentries.elements();
enum.hasMoreElements();) {
 ^
D:\AUT_TEST\Jython21\org\python\parser\PythonGrammar.java:6739: as of
release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.4 or lower to use 'enum' as an identifier)
  for (java.util.Enumeration enum = jj_expentries.elements();
enum.hasMoreElements();) {
  ^
D:\AUT_TEST\Jython21\org\python\parser\PythonGrammar.java:6740: as of
release 1.5, 'enum' is a keyword, and may not be used as an identifier
(try -source 1.4 or lower to use 'enum' as an identifier)
int[] oldentry = (int[])(enum.nextElement());
 ^
D:\AUT_TEST\Jython21\org\python\core\Py.java:996: incompatible types
found   : org.python.core.PyObject
required: boolean
assert(test, Py.None);
   ^
D:\AUT_TEST\Jython21\org\python\core\PyBeanProperty.java:36: warning:
non-varargs call of varargs method with inexact argument type for last
parameter;
cast to java.lang.Object for a varargs call
cast to java.lang.Object[] for a non-varargs call and to suppress this
warning
Object value = getMethod.invoke(iself, Py.EmptyObjects);
 ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
7 errors
1 warning

ERROR DURING JAVA COMPILATION... EXITING

D:\AUT_TEST\workspace\JyFIT\fit
Looks like something in the Jython core causes the problem
(org\python\core\Py.java) any Ideas what I can do?

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


Jython inherit from Java class

2006-02-07 Thread Mark Fink
I wrote a Jython class that inherits from a Java class and (thats the
plan) overrides one method. Everything should stay the same.

If I run this nothing happens whereas if I run the Java class it says:
usage: java fit.FitServer [-v] host port socketTicket
-v  verbose

I think this is because I do not understand the jython mechanism for
inheritance (yet).

JyFitServer.py:
===
import fit.FitServer
import fitnesse.components.FitProtocol
from fit.Parse import Parse
from fit.Fixture import Fixture

# Inherit from original Java FitServer Implementation by Robert C.
Martin and Micah D. Martin
class FitServer(fit.FitServer):
# call constructor of superclass
def __init__(self, host, port, verbose):
FitServer.__init__(self, host, port, verbose)

# override process method
def process(self):
self.fixture.listener = self.fixtureListener
print hello, I am JyFitServer!
try:
size = FitProtocol.readSize(self.socketReader)
if size  0:
try:
document =
FitProtocol.readDocument(self.socketReader, size)
tables = Parse(document)
fixture = Fixture()
fixture.listener = self.fixtureListener;
fixture.doTables(tables)
self.counts.tally(self.fixture.counts)
except FitParseException, e:
self.exception(e)
except Exception, e:
self.exception(e)



Please help,
Mark Fink

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


jython newbee general question docu / os.fstat

2006-02-05 Thread Mark Fink
Hi there,

unfortunately I am new to Jython and my Jython Essentials book is
still in the mail. I looked into the Jython API Doc but could not find
the information.
I am porting a Python library to Jython and some parts are missing. My
question basically is where do I find information on what to use
instead. E.g. I could not find information on the os module. I do not
find the sys module docu either.
The concrete problem is I have something like os.fstat(infile.fileno())
which provokes:
IOError: fileno() is not supported in jpython.
If this question is already documented somewhere please point me to
this direction. I was not able to find it.

Best Regards,
Mark

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


rexec in jython??

2006-02-05 Thread Mark Fink
Hi there,
I at the moment port a library from Python to Jython (at lease I try to
do so :-))). The library uses the Rexec to form a type adapter to cast
parameters given as text into the according Jython type. I learned
rexec is not available in Jython. Is something that is commonly used in
Jython for such tasks available?
In general: how do I find such information by myself?
Best Regards,
Mark

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


rexec in jython??

2006-02-05 Thread Mark Fink
Hi there,
I at the moment port a library from Python to Jython (at lease I try to
do so :-))). The library uses the Rexec to form a type adapter to cast
parameters given as text into the according Jython type. I learned
rexec is not available in Jython. Is something that is commonly used in
Jython for such tasks available?
In general: how do I find such information by myself?
Best Regards,
Mark

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


Re: rexec in jython??

2006-02-05 Thread Mark Fink
sorry for the double post!
It is the r_eval() functionality of the rexec module I am looking
forward to replace

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


Re: rexec in jython??

2006-02-05 Thread Mark Fink
this is really funny...
I tried to use eval(String) as an replacement. It works now but the
calculation results from my tests are not as expected: 2 + 3 = 23 !!! 2
- 3 = 2-3...
I have the feeling that there is a really easy solution for this.
Unfortunately I have no enough experience

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


Re: rexec in jython??

2006-02-05 Thread Mark Fink
This is the original code section of the library including the
comments:
class AutoAdapter(TypeAdapter):

This adapter returns a type based on the format of the table cell
contents, following python's rules for literals (plus a few
others).
We could fall back on this when we don't know what type is
expected.
I am lazy and so use rexec to do the work.

#Note: The RExec class can prevent code from performing unsafe
#operations like reading or writing disk files, or using TCP/IP
#sockets. However, it does not protect against code using
#extremely large amounts of memory or processor time.

r_eval = RExec().r_eval
def parse(self,s):
if s.strip().lower() == 'true':
return 1
elif s.strip().lower() == 'false':
return 0
else:
try:
return self.r_eval(s)
except SystemExit:
return None
except:
return s

I completely removed the import of rexec and replaced return
self.r_eval(s) with return self.eval(s)

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


Re: rexec in jython??

2006-02-05 Thread Mark Fink
:-))) it works!
I replaced it to return eval(s) and the results look extremely well
guess I should get one of this crystal balls myself.

one minor issue is still left:
correct me if I am wrong: result of 2/-3 is 0 (at least this is how it
is defined in the testcase)
In Jython 2.1.3:
 2/-3
-1
Anyway many thanks for your help. Without this would have taken forever.

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


jython how to use Fit and Fitnesse

2006-01-26 Thread Mark Fink
Hi there,
I want to ask how to use Fit and Fitnesse together to use testcases
programmed in Jython. Resently I discussed with John Roth how PyFit
would have to be changed to work together with Jython. This seems to be
a lot of work and comes maybee with version 0.9 in mid 2006 if at all.
I think that it is possible to use Fitnesse and Java Fit and involve
Jython testcases with this configuration but I do not know how. Perhaps
someone from this group has done this before and wants to share some
tipps with me.

Cheers,
Mark Fink
http://www.mark-fink.de

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