Legacy Classic ASP / VBScript Support
ASPPY promises 99% compatibility with legacy Classic ASP. It implements a fully functioning VBScript Virtual Machine and provides Python-based shims for the most common built-in ASP objects (Request, Response, Server, Application, Session) and commonly used COM objects.
VBScript Language Features
ASPPY supports standard VBScript syntax and flow control:
- Variables & Types:
Dim,Const, Variants (Strings, Integers, Booleans, Arrays). - Flow Control:
If...Then...Else,Select Case,For...Next,For Each...In,Do...Loop,While...Wend. - Procedures:
SubandFunction(including ByRef and ByVal passing). - Classes:
Classdefinitions,Public/Privatemembers,Property Get/Let/Set. - Error Handling:
On Error Resume Next,On Error GoTo 0, and theErrobject. - Includes:
<!-- #include file="..." -->and<!-- #include virtual="..." -->.
The Response Object
Used to send output to the client.
| Method / Property | Description |
|---|---|
Response.Write(string) | Writes a string to the HTTP output. |
Response.Redirect(url) | Sends a 302 redirect. |
Response.End() | Stops script execution and flushes the buffer. |
Response.Flush() / Clear() | Flushes or clears the current output buffer. |
Response.File(path, [inline]) | Serves a physical file to the client natively (handles mime type and content length automatically). |
Response.BinaryWrite(data) | Writes raw binary data. |
Response.ContentType | Sets the HTTP content type (e.g., "text/html"). |
Response.Cookies(name) = value | Sets a cookie. Supports keys: Response.Cookies(name)(key) = value and .Expires. |
Response.Status | Sets the HTTP status line (e.g., "404 Not Found"). |
The Request Object
Used to retrieve client information.
| Collection / Property | Description |
|---|---|
Request.QueryString("key") | Gets GET parameters. |
Request.Form("key") | Gets POST parameters. |
Request.ServerVariables("key") | Gets server vars (e.g., REMOTE_ADDR, HTTP_USER_AGENT). |
Request.Cookies("key") | Gets cookie values. |
Request("key") | Shorthand: searches QueryString, Form, Cookies, then ServerVariables. |
Request.Method / Request.HttpMethod | Returns the HTTP method (e.g., GET, POST, PUT, DELETE). |
Native File Uploads & Downloads
ASPPY supports native multipart/form-data file uploads via Request.Files, entirely eliminating the need for complex third-party VBScript parser scripts (like freeASPUpload).
<%
If Request.Files.Count > 0 Then
Dim uploadedFile
Set uploadedFile = Request.Files("myFile")
If Not uploadedFile Is Nothing Then
' Save to disk natively
uploadedFile.SaveAs Server.MapPath("/data/uploaded_" & uploadedFile.FileName)
Response.Write "Uploaded: " & uploadedFile.FileName & " (" & uploadedFile.Size & " bytes)"
End If
End If
%>
Similarly, securely streaming files back to the client is natively supported using Response.File. This stops script execution, handles correct Content-Type guessing, Content-Length calculation, and sets the Content-Disposition automatically.
<%
Dim filePath
filePath = Server.MapPath("/data/download_test.txt")
' The second parameter determines if it's served inline (True) or as an attachment (False)
Response.File filePath, False
%>
The Server Object
| Method | Description |
|---|---|
Server.CreateObject(progid) | Instantiates COM objects (shimmed by Python equivalents). |
Server.MapPath(path) | Translates a virtual path to a physical filesystem path. |
Server.HTMLEncode(string) | Encodes HTML characters. |
Server.URLEncode(string) | URL-encodes a string. |
Server.Execute(path) / Transfer(path) | Executes another ASP page. |
Supported COM Objects via Server.CreateObject
ASPPY intercepts Server.CreateObject calls and routes them to native Python implementations:
Scripting.Dictionary- Native dictionary implementation with string/case-insensitive mapping.Scripting.FileSystemObject- Native file IO (File, Folder, TextStream).ADODB.Connection,ADODB.Recordset,ADODB.Command- SQL database connectivity.ADODB.Stream- Binary and Text stream manipulation.VBScript.RegExp- Regular expressions (powered by Pythonre).MSXML2.ServerXMLHTTP/MSXML2.DOMDocument- HTTP requests and XML parsing.CDO.Message- Email sending.