473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

rexec in jython??

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

Feb 5 '06 #1
7 1318
sorry for the double post!
It is the r_eval() functionality of the rexec module I am looking
forward to replace

Feb 5 '06 #2
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

Feb 5 '06 #3
Mark Fink wrote:
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


How about showing code? Otherwise we all have to use our crystal balls, and
these thingies tend to be not so precise...

Diez
Feb 5 '06 #4
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)"

Feb 5 '06 #5
Mark Fink wrote:
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)"


And what does self.eval look like? Crystal ball still not working....

Diez
Feb 5 '06 #6
:-))) 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.

Feb 5 '06 #7
Mark Fink wrote:
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


CPython gives the same result and the language reference says, "Plain or
long integer division yields an integer of the same type; the result is
that of mathematical division with the `floor' function applied to the
result." so this seems to be intentional.

Kent
Feb 6 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Colin Coghill (SFive) | last post by:
Hi, a year or so back some students of mine and I wrote some software which made use of the rexec module to run untrusted user code relatively safely. (We were creating a prototype of a mobile-code...
13
by: Rainer Deyke | last post by:
Now that rexec is gone, is there any code or information available on executing Python in a restricted environment? And before I roll my own solution, exactly where the security holes in rexec...
9
by: Huaiyu Zhu | last post by:
What is the prefered way to eval a string like "('a', 1)"? These strings are representations of simple objects of type int, str, or dict, tuple or list made of them. I do not want to use naked...
1
by: Paul Miller | last post by:
I came across this recipe on the Python Cookbook site: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286134 As written, it allows evaluation of either constants or more general...
4
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
2
by: Kay Schluehr | last post by:
Cited from Python-doc ( v.2.3 ) My question about rexec and bastion may be anachronistic but I did not found much explanation, why rexec and bastion are swiss cheese? It may be helpfull to...
5
by: JoeBrain00 | last post by:
Sorry if this is in the wrong forum, I couldn't find another place for it... Does anyone use Visual Integration Studio? ( http://www.crossrhoades.com ) I am attempting to load some Oracle...
0
by: Mark Fink | last post by:
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...
3
by: Paul Miller | last post by:
Bastion and rexec have been deprecated since Python 2.2, so it seems we (the Python community) have gotten along well enough without them. Have these modules not been reimplemented because: a)...
1
by: datactrl | last post by:
Hi, all I'd like to execute a remote program in Windows operation system with rexec in PHP. Is there a rexec module PHP instead of using PHP to create a process to run rexec, just like CGI? Or is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.