⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapsite.py

📁 python web programming 部分
💻 PY
字号:
"""Used to instantiate required page generators, and look up realm authentication data."""

import urllib
import SiteSpec, Static, ErrorPages
from types import ClassType, DictType, StringType

def PageSpec(op, path, query, session, headers,
    Map=SiteSpec.PageMap, Realm=None, PathFound=None):
    """Return the page processor and authentication realm corresponding to a path."""
    if not path:
        return ErrorPages.Error404Page(op, PathFound, query, session, headers, Realm=None)
    pathel = path[0]
    if not PathFound:
        PathFound = [pathel]
    else:
        PathFound.append(pathel)
    del path[0]
    try:
        item, realm = Map[pathel]
        if not realm:
            realm = Realm # Inherit realm from containing tree
        itemtype = type(item)
        if itemtype == DictType:
            return PageSpec(op, path, query, session, headers,
                             Map=item, Realm=realm, PathFound=PathFound)
        elif len(PathFound) and not len(path): # A mapped element was not followed by a "/"
            URI = "/".join([""]+PathFound+path+[""])
            if query:
                URI += "?" + urllib.urlencode(query)
            return ErrorPages.Error301Page(op, path, query, session, headers, Realm=realm,
                             oHeaders=["Location: %s" % URI])
        if itemtype == StringType:
            return Static.Page(op, path, query, session, headers,
                            Realm=realm, Initpath=item.split("/"))
        elif itemtype == ClassType:
            if path[-1] == "": # remove evidence of trailing slash
                del path[-1]
            return item(op, path, query, session, headers,
                         Realm=realm, Initpath=PathFound)
        else:
            raise KeyError
    except KeyError:
        return ErrorPages.Error404Page(op, path, query, session, headers, Realm=None)

def RealmData(realm):
    try:
        return SiteSpec.RealmAuth[realm]
    except KeyError:
        return None

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -