473,624 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Providing full interaction with the run time

We have a system we're developing which runs as a server. It has an xml-rpc
interface which I've extended to provide some debugging facilities. This
has already proved very useful and will continue to be so as the system is
prepared for live deployment.

The debugging interface attempts to emulate the Python interactive shell.
You type expressions, you get an answer. You type statements, they get
executed.

The problem is these two types of input are handled differently by Python.
You don't seem to be able to pass statements (which includes assignments)
and expressions through the same calls.

There are three keywords that support this type of function: EXEC, EVAL and
COMPILE. We can ignore EXEC for this because it doesn't support saving and
restoring a local environment and EVAL can do it better.

When you COMPILE code for EVAL, you have to say what sort of statement it
is. You can't pass an assignment as an expression:
>>lcls={}
r = eval(compile('a =1', '<>', 'eval'), globals(), lcls)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<>", line 1
a=1
^
SyntaxError: invalid syntax

However, changing option 'eval' to 'single' is OK for statements:
>>lcls={}
r = eval(compile('a =1', '<>', 'single'), globals(), lcls)
lcls
{'a': 1}
>>>
But if I use 'single', I can't get expression results because the stupid
function prints them on the console.
>>r = eval(compile('a ', '<>', 'single'), globals(), lcls)
1
>>print r
None

I can use the 'eval' option but that doesn't take assignments, remember?
>>r = eval(compile('a ', '<>', 'eval'), globals(), lcls)
print r
1

The compile function also supports an 'exec' parameter in place of 'eval' or
'single' but this throws away expression results so that's no help.

At the moment, I'm making a crude attempt to distinguish between statements
and expressions but it's easily fooled.

So the question is: how does my debug interface (which operates over RPC)
decide which type of COMPILE it wants?

Or am I going about this all wrong?

(I don't need warnings about the obvious security implications of this
interface.)

Thanks
--
Dale Strickland-Clark
Riverhall Systems - www.riverhall.co.uk

Oct 29 '06 #1
2 900
Dale Strickland-Clark wrote:
We have a system we're developing which runs as a server. It has an xml-rpc
interface which I've extended to provide some debugging facilities. This
has already proved very useful and will continue to be so as the system is
prepared for live deployment.

The debugging interface attempts to emulate the Python interactive shell.
You type expressions, you get an answer. You type statements, they get
executed.

The problem is these two types of input are handled differently by Python.
You don't seem to be able to pass statements (which includes assignments)
and expressions through the same calls.

There are three keywords that support this type of function: EXEC, EVAL and
COMPILE. We can ignore EXEC for this because it doesn't support saving and
restoring a local environment and EVAL can do it better.
huh? both exec and eval take optional execution contexts:

http://effbot.org/pyref/eval.htm
http://effbot.org/pyref/exec.htm
Or am I going about this all wrong?
yes, you're trying to reinvent the "code" module (and badly, it seems
;-). see the library reference to details, this page for some examples:

http://www.effbot.org/librarybook/code.htm

</F>

Oct 29 '06 #2
Thanks for the info. I didn't know about that module. I'll take a look.

Fredrik Lundh wrote:
Dale Strickland-Clark wrote:
>We have a system we're developing which runs as a server. It has an
xml-rpc interface which I've extended to provide some debugging
facilities. This has already proved very useful and will continue to be
so as the system is prepared for live deployment.

The debugging interface attempts to emulate the Python interactive shell.
You type expressions, you get an answer. You type statements, they get
executed.

The problem is these two types of input are handled differently by
Python. You don't seem to be able to pass statements (which includes
assignments) and expressions through the same calls.

There are three keywords that support this type of function: EXEC, EVAL
and COMPILE. We can ignore EXEC for this because it doesn't support
saving and restoring a local environment and EVAL can do it better.

huh? both exec and eval take optional execution contexts:

http://effbot.org/pyref/eval.htm
http://effbot.org/pyref/exec.htm
>Or am I going about this all wrong?

yes, you're trying to reinvent the "code" module (and badly, it seems
;-). see the library reference to details, this page for some examples:

http://www.effbot.org/librarybook/code.htm

</F>
--
Dale Strickland-Clark
Riverhall Systems - www.riverhall.co.uk

Nov 1 '06 #3

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

Similar topics

1
1922
by: Nobody | last post by:
I have a website that is built around a web-application that my company purchased. My company has full ownership and administrative rights to this software and its corresponding files. It uses HTTP Basic Authentication and that cannot be changed at all (it is compiled into the web-application itself). This is my problem: We have a secure subnet (a customer of ours) that regularly uses this website and they don't want to have to log...
1
15606
by: Senthuran | last post by:
Hi I am getting this common error once or twice a day: Error: 9002, Severity: 17, State: 2 The log file for database 'tempdb' is full. Back up the transaction log for the database to free up some log space. provided......
2
6888
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app (which is the UI used to adjust the actions taken by, and the schedule of the service), then a privileged user thread should be used in the UI - no service required. But... "A windows service enables the creation of long-running executable
36
2018
by: Peter Olcott | last post by:
So far the only way that I found to do this was by making a single global instance of the container class and providing access to the contained class, through this single global instance. Are there any other no-overhead ways that a contained class can access its container? The obvious choice of passing (a pointer or a reference to the container) to the contained class is not a no-overhead solution, it requires both memory and time. I am...
0
1704
by: padmajapenmetsa | last post by:
Hi, We have the full text search table and are using CONTAINSTABLE to search in the fulltext search column, its workingfine, but we have a requirement that we need to return results which match a particular sequence in word. ex: The search text column has the word as 0203456-345567 if we give the input as " 0203456", the result is coming and showing the above column, but if we search for " 203456" no results return,
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8474
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.