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

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

?? kgp.py

?? Dive into python的配套源碼。
?? PY
字號(hào):
#!/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
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品久久久久影院亚瑟| 精品视频一区三区九区| 91精品在线免费| 亚洲一卡二卡三卡四卡| 欧美日韩精品欧美日韩精品一| 一个色综合网站| 欧美三级电影网站| 日韩主播视频在线| 精品国产乱码久久久久久1区2区| 九九久久精品视频| 国产亚洲综合av| 色婷婷av一区二区三区软件| 亚洲综合精品久久| 欧美成人女星排名| 成人av动漫在线| 亚洲精品自拍动漫在线| 欧美精品乱码久久久久久按摩| 蜜桃一区二区三区四区| 久久久99精品久久| 91一区一区三区| 日本人妖一区二区| 国产日韩三级在线| 欧美综合一区二区三区| 精品中文av资源站在线观看| 欧美经典一区二区三区| 欧美在线不卡一区| 裸体健美xxxx欧美裸体表演| 国产午夜精品一区二区三区视频| 91麻豆国产福利在线观看| 日韩国产成人精品| 国产精品污污网站在线观看| 欧美性高清videossexo| 国产在线精品一区二区不卡了| 亚洲免费观看高清完整版在线观看 | 久久久一区二区| 99re这里都是精品| 免费精品99久久国产综合精品| 国产亚洲欧美日韩俺去了| 久久久亚洲精品一区二区三区| 99精品一区二区| 麻豆精品久久精品色综合| 国产精品日产欧美久久久久| 欧美日韩国产高清一区二区| 成人午夜视频福利| 日本欧美在线看| 亚洲欧洲www| 精品美女被调教视频大全网站| 成人不卡免费av| 久99久精品视频免费观看| 亚洲黄色尤物视频| 国产丝袜欧美中文另类| 91精品在线观看入口| 日本二三区不卡| 国产盗摄一区二区三区| 男女男精品网站| 亚洲一区二区三区视频在线| 中文字幕欧美日本乱码一线二线| 91精品国产一区二区人妖| 色久优优欧美色久优优| 福利一区二区在线| 精东粉嫩av免费一区二区三区| 天天影视色香欲综合网老头| 亚洲欧美视频在线观看| 国产精品伦一区| 久久久久久久久久久黄色| 日韩一二三四区| 在线播放日韩导航| 欧美丝袜丝nylons| 欧美性猛交xxxx黑人交| 色88888久久久久久影院按摩| 成人午夜电影久久影院| 国产激情视频一区二区在线观看 | www.欧美日韩国产在线| 国产一区二区三区免费| 精一区二区三区| 麻豆成人在线观看| 琪琪久久久久日韩精品| 全国精品久久少妇| 人禽交欧美网站| 麻豆91精品91久久久的内涵| 日韩中文字幕一区二区三区| 午夜日韩在线电影| 婷婷开心激情综合| 美腿丝袜在线亚洲一区| 麻豆freexxxx性91精品| 国内外成人在线| 国产电影精品久久禁18| 成人动漫中文字幕| 97精品久久久午夜一区二区三区 | 麻豆精品一区二区三区| 久久精品国产99国产精品| 久久精品国产第一区二区三区| 久久国产精品色| 国产精品影视天天线| 国产福利不卡视频| 成人黄动漫网站免费app| jlzzjlzz亚洲日本少妇| 色成人在线视频| 欧美日韩精品一区二区三区四区 | 69堂精品视频| 日韩一区二区中文字幕| www久久久久| 国产日韩欧美在线一区| 亚洲色图一区二区| 天堂成人免费av电影一区| 久久国产免费看| 国产suv一区二区三区88区| 99久久久久久| 91麻豆精品国产自产在线| 26uuu久久综合| 亚洲情趣在线观看| 蜜桃视频在线观看一区| 成人国产精品免费观看视频| 色94色欧美sute亚洲线路二| 在线播放91灌醉迷j高跟美女 | 亚洲一区视频在线观看视频| 午夜精品久久久久久久99樱桃| 日本美女视频一区二区| 成人在线视频一区二区| 欧美性色综合网| 久久久99精品免费观看| 亚洲国产中文字幕| 国产精品白丝av| 欧美日韩高清影院| 国产精品人妖ts系列视频| 视频在线在亚洲| 成人蜜臀av电影| 欧美一区二区三区视频在线观看| 国产拍欧美日韩视频二区| 五月天欧美精品| 成人av电影免费在线播放| 欧美精品第1页| 国产精品成人免费| 久久精品国产秦先生| 欧美主播一区二区三区| 国产欧美一区二区精品久导航 | 国产精品视频你懂的| 香港成人在线视频| 97精品视频在线观看自产线路二| 日韩一区二区三区视频| 亚洲精品成人悠悠色影视| 国内精品写真在线观看| 欧美亚男人的天堂| 国产精品久久久久三级| 韩国成人精品a∨在线观看| 色国产精品一区在线观看| 国产欧美日韩在线看| 久久av资源网| 欧美精品vⅰdeose4hd| 亚洲精品欧美二区三区中文字幕| 国产在线一区二区综合免费视频| 欧美日韩一二三区| 亚洲日本欧美天堂| 成人免费视频一区二区| 久久蜜桃av一区精品变态类天堂 | 亚洲欧美国产高清| 国产**成人网毛片九色 | 精品99999| 亚洲成av人片在线观看无码| 91视频在线观看免费| 欧美国产欧美综合| 国产精品亚洲一区二区三区妖精 | 国产精品资源网| 日韩精品一区二区三区四区| 日韩高清不卡一区| 91.xcao| 天堂va蜜桃一区二区三区漫画版| 色婷婷久久久久swag精品| 综合亚洲深深色噜噜狠狠网站| 国产乱淫av一区二区三区| 精品电影一区二区| 精品亚洲国产成人av制服丝袜| 欧美一区二区在线播放| 日本欧洲一区二区| 精品久久久影院| 韩国毛片一区二区三区| 久久久国产午夜精品| 国产大陆精品国产| 中文字幕亚洲在| 91福利国产精品| 亚洲va欧美va人人爽午夜 | 一本久久精品一区二区| 国产精品久久久久精k8| 99精品欧美一区二区蜜桃免费| 日韩一区欧美小说| 欧美在线一区二区| 肉色丝袜一区二区| 欧美mv日韩mv国产网站app| 国产呦萝稀缺另类资源| 国产婷婷色一区二区三区四区| 粉嫩aⅴ一区二区三区四区五区| 国产精品免费丝袜| 欧美亚洲禁片免费| 久草在线在线精品观看| 亚洲国产精品v| 欧美亚洲丝袜传媒另类| 久久av资源网| 1000部国产精品成人观看| 欧美亚洲一区三区| 国内外精品视频|