亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? kgp.py

?? 深入python編程
?? PY
字號:
#!/usr/bin/env python2"""Kant Generator for PythonGenerates mock philosophy based on a context-free grammarUsage: python kgp.py [options] [source]Options:  -g ..., --grammar=...   use specified grammar file or URL  -h, --help              show this help  -d                      show debugging information while parsingExamples:  kgp.py                  generates several paragraphs of Kantian philosophy  kgp.py -g husserl.xml   generates several paragraphs of Husserl  kpg.py "<xref id='paragraph'/>"  generates a paragraph of Kant  kgp.py template.xml     reads from template.xml to decide what to generateThis program is part of "Dive Into Python", a free Python book forexperienced programmers.  Visit http://diveintopython.org/ for thelatest version."""__author__ = "Mark Pilgrim (mark@diveintopython.org)"__version__ = "$Revision: 1.4 $"__date__ = "$Date: 2004/05/05 21:57:19 $"__copyright__ = "Copyright (c) 2001 Mark Pilgrim"__license__ = "Python"from xml.dom import minidomimport randomimport toolboximport sysimport getopt_debug = 0class NoSourceError(Exception): passclass KantGenerator:    """generates mock philosophy based on a context-free grammar"""        def __init__(self, grammar, source=None):        self.loadGrammar(grammar)        self.loadSource(source and source or self.getDefaultSource())        self.refresh()    def _load(self, source):        """load XML input source, return parsed XML document        - a URL of a remote XML file ("http://diveintopython.org/kant.xml")        - a filename of a local XML file ("~/diveintopython/common/py/kant.xml")        - standard input ("-")        - the actual XML document, as a string        """        sock = toolbox.openAnything(source)        xmldoc = minidom.parse(sock).documentElement        sock.close()        return xmldoc    def loadGrammar(self, grammar):        """load context-free grammar"""        self.grammar = self._load(grammar)        self.refs = {}        for ref in self.grammar.getElementsByTagName("ref"):            self.refs[ref.attributes["id"].value] = ref            def loadSource(self, source):        """load source"""        self.source = self._load(source)    def getDefaultSource(self):        """guess default source of the current grammar                The default source will be one of the <ref>s that is not        cross-referenced.  This sounds complicated but it's not.        Example: The default source for kant.xml is        "<xref id='section'/>", because 'section' is the one <ref>        that is not <xref>'d anywhere in the grammar.        In most grammars, the default source will produce the        longest (and most interesting) output.        """        xrefs = {}        for xref in self.grammar.getElementsByTagName("xref"):            xrefs[xref.attributes["id"].value] = 1        xrefs = xrefs.keys()        standaloneXrefs = [e for e in self.refs.keys() if e not in xrefs]        if not standaloneXrefs:            raise NoSourceError, "can't guess source, and no source specified"        return '<xref id="%s"/>' % random.choice(standaloneXrefs)            def reset(self):        """reset parser"""        self.pieces = []        self.capitalizeNextWord = 0    def refresh(self):        """reset output buffer, re-parse entire source file, and return output                Since parsing involves a good deal of randomness, this is an        easy way to get new output without having to reload a grammar file        each time.        """        self.reset()        self.parse(self.source)        return self.output()    def output(self):        """output generated text"""        return "".join(self.pieces)    def randomChildElement(self, node):        """choose a random child element of a node                This is a utility method used by do_xref and do_choice.        """        choices = [e for e in node.childNodes                   if e.nodeType == e.ELEMENT_NODE]        chosen = random.choice(choices)        if _debug:            sys.stderr.write('%s available choices: %s\n' % \                (len(choices), [e.toxml() for e in choices]))            sys.stderr.write('Chosen: %s\n' % chosen.toxml())        return chosen    def parse(self, node):        """parse a single XML node                A parsed XML document (from minidom.parse) is a tree of nodes        of various types.  Each node is represented by an instance of the        corresponding Python class (Element for a tag, Text for        text data, Document for the top-level document).  The following        statement constructs the name of a class method based on the type        of node we're parsing ("parse_Element" for an Element node,        "parse_Text" for a Text node, etc.) and then calls the method.        """        parseMethod = getattr(self, "parse_%s" % node.__class__.__name__)        parseMethod(node)    def parse_Document(self, node):        """parse the document node                The document node by itself isn't interesting (to us), but        its only child, node.documentElement, is: it's the root node        of the grammar.        """        self.parse(node.documentElement)    def parse_Text(self, node):        """parse a text node                The text of a text node is usually added to the output buffer        verbatim.  The one exception is that <p class='sentence'> sets        a flag to capitalize the first letter of the next word.  If        that flag is set, we capitalize the text and reset the flag.        """        text = node.data        if self.capitalizeNextWord:            self.pieces.append(text[0].upper())            self.pieces.append(text[1:])            self.capitalizeNextWord = 0        else:            self.pieces.append(text)    def parse_Element(self, node):        """parse an element                An XML element corresponds to an actual tag in the source:        <xref id='...'>, <p chance='...'>, <choice>, etc.        Each element type is handled in its own method.  Like we did in        parse(), we construct a method name based on the name of the        element ("do_xref" for an <xref> tag, etc.) and        call the method.        """        handlerMethod = getattr(self, "do_%s" % node.tagName)        handlerMethod(node)    def parse_Comment(self, node):        """parse a comment                The grammar can contain XML comments, but we ignore them        """        pass        def do_xref(self, node):        """handle <xref id='...'> tag                An <xref id='...'> tag is a cross-reference to a <ref id='...'>        tag.  <xref id='sentence'/> evaluates to a randomly chosen child of        <ref id='sentence'>.        """        id = node.attributes["id"].value        self.parse(self.randomChildElement(self.refs[id]))    def do_p(self, node):        """handle <p> tag                The <p> tag is the core of the grammar.  It can contain almost        anything: freeform text, <choice> tags, <xref> tags, even other        <p> tags.  If a "class='sentence'" attribute is found, a flag        is set and the next word will be capitalized.  If a "chance='X'"        attribute is found, there is an X% chance that the tag will be        evaluated (and therefore a (100-X)% chance that it will be        completely ignored)        """        keys = node.attributes.keys()        if "class" in keys:            if node.attributes["class"].value == "sentence":                self.capitalizeNextWord = 1        if "chance" in keys:            chance = int(node.attributes["chance"].value)            doit = (chance > random.randrange(100))        else:            doit = 1        if doit:            for child in node.childNodes: self.parse(child)    def do_choice(self, node):        """handle <choice> tag                A <choice> tag contains one or more <p> tags.  One <p> tag        is chosen at random and evaluated; the rest are ignored.        """        self.parse(self.randomChildElement(node))def usage():    print __doc__def main(argv):    grammar = "kant.xml"    try:        opts, args = getopt.getopt(argv, "hg:d", ["help", "grammar="])    except getopt.GetoptError:        usage()        sys.exit(2)    for opt, arg in opts:        if opt in ("-h", "--help"):            usage()            sys.exit()        elif opt == '-d':            global _debug            _debug = 1        elif opt in ("-g", "--grammar"):            grammar = arg        source = "".join(args)    k = KantGenerator(grammar, source)    print k.output()if __name__ == "__main__":    main(sys.argv[1:])

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91丨porny丨首页| 一区二区三区视频在线看| 欧美aaaaaa午夜精品| 欧美日韩在线免费视频| 亚洲二区在线观看| 欧美蜜桃一区二区三区| 免费成人你懂的| 久久九九影视网| 91免费看片在线观看| 一区二区三区四区不卡在线| 欧美午夜不卡在线观看免费| 蜜桃视频第一区免费观看| www成人在线观看| 色综合视频一区二区三区高清| 亚洲视频一区二区免费在线观看| 色偷偷一区二区三区| 免费人成黄页网站在线一区二区| 久久久高清一区二区三区| 99精品视频一区二区三区| 免费在线观看一区二区三区| 久久综合九色综合欧美98 | 亚洲国产精品久久久男人的天堂| 欧美精品乱码久久久久久| 春色校园综合激情亚洲| 天堂成人免费av电影一区| 日本一区二区三区高清不卡| 欧美性猛交xxxxxxxx| 国产精品夜夜爽| 免费人成在线不卡| 亚洲一区二区三区小说| 中文字幕第一页久久| 日韩欧美国产三级| 欧美日本在线观看| 欧洲激情一区二区| 成人av一区二区三区| 久草中文综合在线| 美女一区二区三区| 视频一区视频二区在线观看| 国产在线播精品第三| 国内成人精品2018免费看| 91国产丝袜在线播放| 精品一区二区影视| 久久99九九99精品| 日av在线不卡| 另类小说欧美激情| 激情综合亚洲精品| 国产综合久久久久影院| 国产精品影音先锋| 粉嫩13p一区二区三区| 粉嫩嫩av羞羞动漫久久久| voyeur盗摄精品| av在线一区二区| 色综合咪咪久久| 91精品麻豆日日躁夜夜躁| 欧美一区二区三区视频在线观看| 日韩精品一区二区三区四区| 久久先锋影音av| 亚洲精品一卡二卡| 日韩国产在线观看一区| 极品少妇xxxx精品少妇| jlzzjlzz国产精品久久| 欧美日韩免费不卡视频一区二区三区| 欧美在线免费观看视频| 精品国产伦理网| 日韩美女精品在线| 日韩激情在线观看| 国产99久久久久| 91视频免费观看| 成人黄页在线观看| 日本韩国欧美一区| 国产欧美一二三区| 粉嫩13p一区二区三区| av中文字幕一区| 欧美精品电影在线播放| 国产视频在线观看一区二区三区| 亚洲欧洲成人自拍| 精品在线一区二区| 欧美日韩精品一区二区天天拍小说| 欧美精品一区在线观看| 亚洲成人一区二区在线观看| 国产成人av电影在线播放| 不卡大黄网站免费看| 日韩欧美一级二级| 亚洲成人免费在线| 色综合久久综合| 国产精品美女久久福利网站 | 欧美私模裸体表演在线观看| 国产色综合久久| 蜜桃久久精品一区二区| 欧美日本韩国一区| 亚洲永久免费视频| 91精彩视频在线| 亚洲欧美日韩国产手机在线| 99re热视频精品| 日韩码欧中文字| 色综合久久中文综合久久牛| 欧美极品aⅴ影院| 最近日韩中文字幕| youjizz国产精品| 一区免费观看视频| 91官网在线观看| 日韩高清国产一区在线| 欧美大片免费久久精品三p | 亚洲精品乱码久久久久久日本蜜臀 | 欧美日韩在线观看一区二区 | 免费成人在线播放| 精品欧美乱码久久久久久| 日韩高清在线不卡| 欧美激情中文字幕| 欧美日精品一区视频| 日本中文字幕一区二区视频| 精品国产一区二区三区久久影院| 成人手机电影网| 亚洲精品第一国产综合野| 91麻豆精品国产自产在线观看一区 | 色猫猫国产区一区二在线视频| 一区二区三区毛片| 国产色产综合色产在线视频| 91麻豆精品在线观看| 久久爱www久久做| 亚洲国产成人91porn| 欧美高清在线精品一区| 日韩一区二区电影| 色偷偷久久人人79超碰人人澡| 久久国产乱子精品免费女| 亚洲男人的天堂av| 国产人伦精品一区二区| 51久久夜色精品国产麻豆| 国产高清在线精品| 狠狠色综合色综合网络| 日韩精品乱码av一区二区| 亚洲男人都懂的| 2021中文字幕一区亚洲| 欧美高清dvd| 欧美日韩美女一区二区| 色综合天天做天天爱| 成人高清在线视频| 国产高清精品在线| 国精品**一区二区三区在线蜜桃| 日韩av成人高清| 美腿丝袜亚洲综合| 蜜臀av一区二区| 久久精品国产久精国产| 久久精品国产色蜜蜜麻豆| 久久精品理论片| 国产精品一区在线观看乱码| 国产在线不卡一卡二卡三卡四卡| 日产国产欧美视频一区精品| 美女诱惑一区二区| 福利电影一区二区| 在线观看日韩毛片| 99re这里都是精品| 91老师片黄在线观看| 欧美日韩一级视频| 久久久精品国产99久久精品芒果| 亚洲色欲色欲www| 蜜臀a∨国产成人精品| 亚洲一区国产视频| 韩国三级中文字幕hd久久精品| 成人永久看片免费视频天堂| 色系网站成人免费| 91精品啪在线观看国产60岁| 欧美福利视频导航| 国产精品女同一区二区三区| 久久久午夜精品| 亚洲欧美经典视频| 亚洲 欧美综合在线网络| 久久成人麻豆午夜电影| 国产很黄免费观看久久| 色婷婷综合久久久久中文一区二区| 欧美在线播放高清精品| 日韩亚洲电影在线| 亚洲精品国产一区二区精华液| 青青草视频一区| 99riav久久精品riav| 精品国产伦一区二区三区观看方式 | 日本乱码高清不卡字幕| 久久精品视频免费观看| 日韩国产在线观看一区| 91影院在线观看| 国产亚洲一本大道中文在线| 免费成人在线视频观看| 欧美性色aⅴ视频一区日韩精品| 欧美经典一区二区| 精品一区二区三区不卡 | 91在线免费看| 中文字幕一区二区三区在线不卡| 久久丁香综合五月国产三级网站| 欧美图片一区二区三区| 亚洲日本在线a| 色天使色偷偷av一区二区| 中文字幕av一区二区三区免费看 | 国产精品女上位| 成人性生交大片免费看在线播放 | 99国内精品久久| 亚洲精品视频在线观看免费| 99re这里只有精品首页| 国产精品剧情在线亚洲| 99精品欧美一区| 一区二区激情小说|