[python-win32] IIS and ASP: If blocks that span multiple code blocks

Steven Manross steven at manross.net
Tue Nov 3 10:13:24 EST 2020


Thanks for the reply!

Just an FYI...  This VBScript/ASP code/behavior is probably 10+ years old.

I've already started adapting the python code understanding that it wasn’t likely possible (or was going to take a major RFE that wasn't likely coming any time soon) - and it all works well now.

I hope this helps someone searching the internet for answers to how Python & VBScript in ASP behave differently.

I don’t put it past Microsoft to give their technologies an advantage over other scripting languages when it comes to things like this.

Kudos to everyone's work/documentation on python-win32 and the pywin32 libraries.  This is amazing work, and I super-appreciate it all!  

The coding to translate a VBScript project was pretty seamless, except when it came to "Scripting.Dictionary" objects (some weird edge cases on manipulating items after they were created), and in that case, I just converted to python dictionaries since they are SO flexible and come OOTB without need for COM objects (like in VBScript).

HTH someone

Steven
-----Original Message-----
From: Mark Hammond <skippy.hammond at gmail.com> 
Sent: Monday, November 02, 2020 3:50 PM
To: Steven Manross <steven at manross.net>; python-win32 at python.org
Subject: Re: [python-win32] IIS and ASP: If blocks that span multiple code blocks

IIS/ASP sends Python different strings to evaluate, and Python evaluates them individually. It's much like wanting Python code such as:

if foo:
   bar()

To be handled in Python by using:

 >>> exec("if foo:\n")
 >>> exec("  bar()\n")

Which doesn't work.

The semantics are largely defined by the "Active Scripting" 
specifications. I haven't kept up with that recently, so it's possible there have been enhancements to that spec which might make this possible, but if there were, they would have been targeted at making languages offered directly by MS better than Python.

So I'm afraid that I think you are out of luck.

Cheers,

Mark

On 2/11/2020 12:12 pm, Steven Manross wrote:
> I was wondering if there's any way to support this style of coding in ASP/Python.
> 
> This works in VBScript (but I'm trying to remove all my VBScript), but I seem to be getting hit by the fact that each block of code is being analyzed as a single block of code and the "if" not being able to span multiple code blocks.
> 
> #VBScript
> <%
> If This = "THAT" Then
>      Response.Write("BEFORE")
> %>
>      This does == THAT<BR>
>      <!-- #include virtual="/inc/whatever.vbscriptincludefile" --> <%
>      Response.Write("AFTER<BR>")
> End If
> %>
> 
> What I am trying to show you is that in VBScript, an IF block can span 
> the multiple code regions (<% code %>) and conditionally display the 
> HTML in between the IF and END IF if the condition matches
> 
> Note that in VBScript if This = "THAT", this VBScript would display:
> 
> BEFORE<BR>
> This does == THAT<BR>
>   *** whatever the include file displayed AFTER<BR>
> 
> And of course, if This <> "THAT" it wouldn't display anything from above!
> 
> However in Python, and a similarly structured code-block:
> 
> #Python
> <%
> if This == "THAT":
>      Response.Write("BEFORE<BR>")
> %>
>      This does == THAT<BR>
>      <!-- #include virtual="/inc/whatever.pythonincludefile" --> <%
> Response.Write("AFTER<BR>")
> %>
> 
> In python, We would get (if This == "THAT"):
> 
> BEFORE
> This does == THAT<BR>
>   *** and whatever the include file displayed (if the include file had 
> no additional logic to filter the data) AFTER<BR>
> 
> However, in python, we would get (if This != "THAT"):
> 
> This does == THAT<BR>
>   *** and whatever the include file displayed (if the include file had 
> no additional logic to filter the data) AFTER<BR>
> 
> Lastly, if I indent the Response.Write("AFTER<BR>") in this second code block to try and span the code block to the same conditional started in the first code block, I get a syntax error like this:
> 
> unexpected indent
> /folder/somefile.asp, line ###
>      Response.Write("AFTER<BR>")
> ---^
> 
> is there any way around this without doing a lot of other if blocks in 
> each section of <% code %>
> 
> It sounds like an RFE to me (and probably not an easy one), but maybe I'm missing something?
> 
> IIS on W2016 (most recent patches)
> Activestate Python: 3.8.2
> pywin32==227
> 
> Please and Thank You,
> Steven
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
> 



More information about the python-win32 mailing list