蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行 Classic ASP 20 组 100 项实例目录代表性场景离线抽样验证

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-examples.py
explore-examples.py174 行
"""Offline Classic ASP 100-Examples Catalog verification lab (IIS ASP absent)."""
from datetime import date, timedelta
import json
from pathlib import Path
import tempfile


CATALOG_CATEGORIES = [
    ("基础", 2),
    ("变量", 5),
    ("Date/Time 函数(VBScript)", 8),
    ("其他函数(VBScript)", 8),
    ("程序", 3),
    ("表单", 3),
    ("Cookie", 1),
    ("Response 对象", 12),
    ("Request 对象", 13),
    ("Session 对象", 2),
    ("Server 对象", 3),
    ("FileSystem 对象", 7),
    ("TextStream 对象", 8),
    ("Drive 对象", 10),
    ("File 对象", 4),
    ("Dictionary 对象", 6),
    ("AdRotator 组件", 1),
    ("Browser Capabilities 组件", 1),
    ("ContentRotator 组件", 1),
    ("Content Linking 组件", 2),
]


def main() -> None:
    cases = []

    # Case 1: VBScript Date/Time and String/Math functions
    base_day = date(2026, 12, 1)
    y3000 = date(3000, 1, 1)
    days_to_3000 = (y3000 - base_day).days
    plus_30 = (base_day + timedelta(days=30)).isoformat()
    sample = "  Hello ASP  "
    expected1 = {
        "days_to_3000": 355412,
        "plus_30_days": "2026-12-31",
        "ucase": "HELLO ASP",
        "lcase": "hello asp",
        "trim": "Hello ASP",
        "str_reverse": "PSA olleH",
        "right_3": "ASP",
        "mid_2_4": "ello",
        "replace": "Hello Classic ASP",
        "round_val": 4,
    }
    trimmed = sample.strip()
    actual1 = {
        "days_to_3000": days_to_3000,
        "plus_30_days": plus_30,
        "ucase": trimmed.upper(),
        "lcase": trimmed.lower(),
        "trim": trimmed,
        "str_reverse": trimmed[::-1],
        "right_3": trimmed[-3:],
        "mid_2_4": trimmed[1:5],
        "replace": trimmed.replace("ASP", "Classic ASP"),
        "round_val": round(3.6),
    }
    cases.append({
        "name": "examples_vbscript_date_and_string",
        "summary": "Verify VBScript DateDiff/DateAdd and UCase/LCase/Trim/StrReverse/Right/Mid/Replace/Round examples.",
        "expected": expected1,
        "actual": actual1,
        "passed": actual1 == expected1,
    })

    # Case 2: Forms, Cookie counter, Response buffer/end, Request multi-value & TotalBytes
    form_colors = ["Red", "Blue"]
    visits = 0
    visits += 1
    visits += 1
    buf = ["part1", "part2"]
    buf.clear()
    buf.append("final")
    expected2 = {
        "checkbox_count": 2,
        "cookie_visits": 2,
        "after_buffer_clear": ["final"],
        "total_bytes": 15,
    }
    actual2 = {
        "checkbox_count": len(form_colors),
        "cookie_visits": visits,
        "after_buffer_clear": buf,
        "total_bytes": len(b"fname=Alex&ok=1"),
    }
    cases.append({
        "name": "examples_forms_cookies_response_request",
        "summary": "Verify multi-value form Count, welcome cookie counter, Response.Clear, and Request.TotalBytes.",
        "expected": expected2,
        "actual": actual2,
        "passed": actual2 == expected2,
    })

    # Case 3: Session Timeout, Server file hit-counter in real temp directory
    with tempfile.TemporaryDirectory(prefix="asp_examples_") as tmp:
        counter_path = Path(tmp) / "hitcounter.txt"
        counter_path.write_text("41", encoding="utf-8")
        hits = int(counter_path.read_text(encoding="utf-8").strip()) + 1
        counter_path.write_text(str(hits), encoding="utf-8")
        persisted = int(counter_path.read_text(encoding="utf-8").strip())

        # Case 4 data inside same temp dir: FSO / TextStream / File / Dictionary
        notes = Path(tmp) / "notes.txt"
        notes.write_text("Line1\nLine2\nLine3\n", encoding="utf-8")
        lines = notes.read_text(encoding="utf-8").splitlines()
        file_size = notes.stat().st_size

    expected3 = {"session_timeout_min": 20, "hit_counter": 42}
    actual3 = {"session_timeout_min": 20, "hit_counter": persisted}
    cases.append({
        "name": "examples_session_server_and_hitcounter",
        "summary": "Verify Session timeout configuration and file-backed hit counter persistence.",
        "expected": expected3,
        "actual": actual3,
        "passed": actual3 == expected3,
    })

    # Case 4: FileSystem / TextStream / File / Dictionary smoke check
    d = {"re": "Red", "gr": "Green", "bl": "Blue"}
    expected4 = {
        "line_count": 3,
        "second_line": "Line2",
        "file_size_positive": True,
        "dict_exists_gr": True,
        "dict_count": 3,
    }
    actual4 = {
        "line_count": len(lines),
        "second_line": lines[1],
        "file_size_positive": file_size > 0,
        "dict_exists_gr": "gr" in d,
        "dict_count": len(d),
    }
    cases.append({
        "name": "examples_fso_textstream_file_dictionary",
        "summary": "Verify FileSystem, TextStream, File metadata, and Dictionary core operations.",
        "expected": expected4,
        "actual": actual4,
        "passed": actual4 == expected4,
    })

    # Case 5: Full 20-category, 100-example catalog inventory verification
    total_examples = sum(c for _, c in CATALOG_CATEGORIES)
    expected5 = {"category_count": 20, "total_examples": 100, "mswc_component_categories": 4}
    actual5 = {
        "category_count": len(CATALOG_CATEGORIES),
        "total_examples": total_examples,
        "mswc_component_categories": sum(1 for name, _ in CATALOG_CATEGORIES if "组件" in name),
    }
    cases.append({
        "name": "examples_catalog_completeness_check",
        "summary": "Verify all 20 example groups totaling 100 Classic ASP examples including 4 MSWC components.",
        "expected": expected5,
        "actual": actual5,
        "passed": actual5 == expected5,
    })

    print(json.dumps({
        "version": "CPython 3.12.14 offline Classic ASP / VBScript verifier (IIS ASP absent)",
        "cases": cases,
    }, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

入口文件:projects/asp-examples-lab/explore-examples.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-examples.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:ASP

课程关联工程包(登记关联36章) · 含当前章节或实例 · mbskycom202612a1425.zip

下载课程关联工程包:ASP

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a1430.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习