mapsite.py

来自「python web programming 部分」· Python 代码 · 共 49 行

PY
49
字号
#
# $Workfile: MapSite.py $ $Revision: 6 $
# $Date: 10/07/01 1:46p $ $Author: Sholden $
#
"""Used to instantiate required page generators, and look up realm authentication data."""

import Static
from types import ClassType, DictType, StringType

def PageSpec(op, path, query, session, headers, Map,
             Realm=None, PathFound=None):
    """Return the page processor and authentication realm coresponding to a path."""
    if not path:
        raise KeyError
    pathel = path[0]
    if not PathFound:
        PathFound = [pathel]
    else:
        PathFound.append(pathel)
    del path[0]
    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)
    if len(PathFound) and not len(path): # A class element was not followed by a "/"
            raise ValueError
    if itemtype == StringType:
        if path[-1] == "": # remove trailing slash
            del path[-1]
        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

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

⌨️ 快捷键说明

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