Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Interoperability between VB and Python under ASP

Reply
Thread Tools

Interoperability between VB and Python under ASP

 
 
Max Ischenko
Guest
Posts: n/a
 
      09-03-2003


Hi,

I've started to develop under Microsoft ASP framework, which allows
different lang. used in a ActiveX page. I wonder about possible
strategies to use Python modules from VBScript <%%> includes.

Right now I'm thinking about this approaches:
- create a COM server in Python to be able to call it from VB.
Drawbacks: cumbersome and (probably) slow.
- pure data exchange. Python code sets some data in global env. that is
afterwards read by VB. Drawbacks: very limited in nature.
- convert all VB pieces that need access to Python modules into Python.

Have I missed something or could anyone comment on this?
Discussion is wellcomed.

--
Regards, Max.

 
Reply With Quote
 
 
 
 
bigdog
Guest
Posts: n/a
 
      09-03-2003
Max Ischenko <> wrote in message news:<bj46f2$kk2$>...
> Hi,
>
> I've started to develop under Microsoft ASP framework, which allows
> different lang. used in a ActiveX page. I wonder about possible
> strategies to use Python modules from VBScript <%%> includes.
>
> Right now I'm thinking about this approaches:
> - create a COM server in Python to be able to call it from VB.
> Drawbacks: cumbersome and (probably) slow.
> - pure data exchange. Python code sets some data in global env. that is
> afterwards read by VB. Drawbacks: very limited in nature.
> - convert all VB pieces that need access to Python modules into Python.
>
> Have I missed something or could anyone comment on this?
> Discussion is wellcomed.


I've mostly done option 3, converting what I needed to Python. It
results in a lot cleaner code (you can't mix html elements and code
very well, for example, in vb you can put a for loop around a section
of HTML, whereas in Python you can't) and the time it took to convert
the code (not much, really, it's a pretty clean port in most cases)
has been more than paid back in maintainability.

Another thing I've done, rather than just port all the code in a given
piece, is to find things I can modularize and then move only the
pieces to Python that I think make sense. For example, I've got a page
set up that you can dynamically add content to, kind of like a wiki,
but much more structured. The only part that is in Python is the
script that edits the HTML file, as file access and manipulation is so
much easier in Python than in an VBScript. All of the user elements
are either in straight html pages or in asp with vbscript. I post my
results to the Python page, update the file, then Response.Redirect to
the page I'm interested in viewing after the file is updated.

I think your next best bet is creating COM servers, or perhaps using
Python within a CGI app for particular pieces of logic. I would avoid
the data exchange route.

I don't know if this will help, but it might be worth a shot.
http://vb2py.sourceforge.net/ I've never used it myself, I only point
it out as a curiosity I've heard of
 
Reply With Quote
 
 
 
 
Paul Paterson
Guest
Posts: n/a
 
      09-04-2003
bigdog wrote:
> Max Ischenko <> wrote in message news:<bj46f2$kk2$>...
>
>>Hi,
>>
>>I've started to develop under Microsoft ASP framework, which allows
>>different lang. used in a ActiveX page. I wonder about possible
>>strategies to use Python modules from VBScript <%%> includes.

>
> I don't know if this will help, but it might be worth a shot.
> http://vb2py.sourceforge.net/ I've never used it myself, I only point
> it out as a curiosity I've heard of


Although it isn't (currently) targetted at VBScript, the CVS version of
vb2py might help if you have reasonably sized blocks of VBScript code to
convert. It hasn't been tested on VBScipt specifically but the parser
should work for most things and I'd certainly be interested to hear of
any specific problems with ASP scripts.

Out of the box it won't even recognize code in a .asp page, but I threw
together the following code. I'm not an expert on ASP or VBScript but
even if this is not correct it might point you in the right direction if
you want to try a convert-to-python route ....

test = """
<html>
<%

function factorial(x)
if x = 0 then
factorial = 1
else
factorial = x*factorial(x-1)
end if
end function

%>
</html>
"""

from vb2py.vbparser import parseVB, VBCodeModule
import re

def translateScript(match):
"""Translate VBScript fragment to Python"""
block = parseVB(match.groups()[0], container=VBCodeModule())
return "<%%\n%s\n%%>" % block.renderAsCode()

converter = re.compile(r"\<%(.*?)%\>", re.DOTALL + re.MULTILINE)
print converter.sub(translateScript, test)


.... which should output:

"""
<html>
<%
from vb2py.vbfunctions import *

def factorial(x):
if x == 0:
_ret = 1
else:
_ret = x * factorial(x - 1)
return _ret

%>
</html>
"""

You'll need the CVS version to get this to work - the v0.1.1 doesn't
have the full parser and the v0.2 release is a couple of weeks off yet.

If you do decide to try this route, I'd be very interested to hear of
any specific issues that come up with translating ASP/VBScript to Python.


Paul

=========================
Paul Paterson

vb2py :: A Visual Basic to Python Conversion Toolkit
http://vb2py.sourceforge.net

 
Reply With Quote
 
Max Ischenko
Guest
Posts: n/a
 
      09-04-2003


> I've mostly done option 3, converting what I needed to Python. It
> results in a lot cleaner code (you can't mix html elements and code
> very well, for example, in vb you can put a for loop around a section
> of HTML, whereas in Python you can't) and the time it took to convert
> the code (not much, really, it's a pretty clean port in most cases)
> has been more than paid back in maintainability.


That's sounds encouraging, thanks. I'd probably go this route.



--
Regards, Max.

 
Reply With Quote
 
Max Ischenko
Guest
Posts: n/a
 
      09-04-2003
Paul Paterson wrote:

>> I don't know if this will help, but it might be worth a shot.
>> http://vb2py.sourceforge.net/ I've never used it myself, I only point
>> it out as a curiosity I've heard of

>
>
> Although it isn't (currently) targetted at VBScript, the CVS version of
> vb2py might help if you have reasonably sized blocks of VBScript code to
> convert. It hasn't been tested on VBScipt specifically but the parser
> should work for most things and I'd certainly be interested to hear of
> any specific problems with ASP scripts.


That's seems like an interesting idea!
While I doubt that the conversion could (or, more appopriately, should)
be done automatically, I'll check out your project, thanks.

> If you do decide to try this route, I'd be very interested to hear of
> any specific issues that come up with translating ASP/VBScript to Python.


OK.


--
Regards, Max.

 
Reply With Quote
 
Max Ischenko
Guest
Posts: n/a
 
      09-04-2003

> Another thing I've done, rather than just port all the code in a given
> piece, is to find things I can modularize and then move only the
> pieces to Python that I think make sense. For example, I've got a page
> set up that you can dynamically add content to, kind of like a wiki,
> but much more structured. The only part that is in Python is the
> script that edits the HTML file, as file access and manipulation is so
> much easier in Python than in an VBScript. All of the user elements
> are either in straight html pages or in asp with vbscript. I post my
> results to the Python page, update the file, then Response.Redirect to
> the page I'm interested in viewing after the file is updated.


I got a question on this issue.
When modularizing Python code, how does one handle data exchange between
Python snippets?

I mean, you can't store anything complicated in a Session (for
instance). Yeah, I can pickle/unpickle any Python object but that feels
like a kludge. Should I setup some global hash, keyed by SessionID to
store data there?

--
Regards, Max.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fax passthrough: interoperability between One Access and Cisco? ango Cisco 0 12-05-2006 04:55 PM
Fax passthrough: interoperability between One Access and Cisco? ango VOIP 0 12-05-2006 04:53 PM
Interoperability between Cisco and 3com LX sfp's Tosh Cisco 1 11-09-2006 06:47 PM
Wireless interoperability between Cisco Aironet and Orinoco. AM Cisco 2 06-10-2005 12:31 PM
Interoperability between Websphere and Sun JDK Sascha Moellering Java 2 08-11-2004 02:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57