当前位置: 首页>>代码示例>>Python>>正文


Python pattern.Pattern类代码示例

本文整理汇总了Python中pattern.Pattern的典型用法代码示例。如果您正苦于以下问题:Python Pattern类的具体用法?Python Pattern怎么用?Python Pattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Pattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __fetch_requests

    def __fetch_requests(self, task_entry):
        p = Pattern(task_entry, self.__getCurrentShell(task_entry), self.global_data)

        timeout = task_entry.get('timeout', 120)
        urls = p.convertPattern('url')
        s = requests.session()
        headers = task_entry.get('headers', [])
        task_entry['datas'] = []
        if not urls:
            return task_entry
        for url in urls:
            self.logger.info("fetching " + url)
            data = ""
            if not url:
                # do not fetch null url
                continue
            try:
                response = s.get(url, timeout=timeout, headers=headers)
                if 200 != response.status_code:
                    self.logger.error("fetch " + url + " failed with code " + (str)(response.status_code))
                data = response.text
            except:
                self.logger.error("fetch " + url + " failed in sockets")
            task_entry['datas'].append(data)
        return task_entry
开发者ID:zesov,项目名称:pyrailgun,代码行数:25,代码来源:railgun.py

示例2: getPattern

    def getPattern(self):

        pat = Pattern()
        
        for i in range(0, self.length):
            try:
                note = MIDI_Dict[self.GetCellValue(NOTE_ROW,i)]
            except KeyError, e:
                note = REST_NOTE
            
            if 'A' in self.GetCellValue(EFFECT_ROW, i):
                accent = True
            else:
                accent = False

            if 'S' in self.GetCellValue(EFFECT_ROW,i):
                slide = True
            else:
                slide = False

            if 'U' in self.GetCellValue(EFFECT_ROW, i):
                transpose = TRANSPOSE_UP
            elif 'D' in self.GetCellValue(EFFECT_ROW, i):
                transpose = TRANSPOSE_DOWN
            else:
                transpose = TRANSPOSE_NONE

            pat.appendNote(note, accent, slide, transpose)
开发者ID:cu,项目名称:temp0,代码行数:28,代码来源:PatternEditGrid.py

示例3: __init__

class If:
    def __init__(self, predicate):
        if isinstance(predicate, str):
            self.predicate = Pattern(predicate)
        else:
            self.predicate = predicate
        self.predicate_assertion = True
        self.deduction = Pattern('')

    def is_(self, v):
        self.predicate_assertion = v
        return self

    def then(self, deduction):
        if isinstance(deduction, str):
            self.deduction = Pattern(deduction)
        else:
            self.deduction = deduction
        return self

    def deduct(self, input_):
        refs, successful = self.predicate.match(input_)
        if self.predicate_assertion and successful:
            return self.deduction.evaluate(refs)
        else:
            raise Paradox

    def __str__(self):
        return 'if %s then %s' % (self.predicate, self.deduction)
开发者ID:qwert42,项目名称:fos,代码行数:29,代码来源:rule.py

示例4: export

 def export(self):
     """
     """
     logger.debug("Begin RSS Export:")
     db = CrawlDB()
     rep = Pattern()
     for pat in db.getPatterns():
         pid = pat["pid"]
         pattern = pat["pattern"]
         description = pat["name"]
         items = []
         for page in db.getPages("where pid=%d limit 10" % pid):
             items.append(self.rssitem % (page["url"],
                                          page["title"],
                                          "",
                                          pattern,
                                          "",
                                          page["url"],
                                          rep.sub(page["content"])))
         itemout = "\n".join(items)
         output = self.rssframe % (pattern,
                                   "http://hjbbs.com/bbs",
                                   description,
                                   "Learning English Tool",
                                   itemout)
         logger.debug("LET %d:\n%s\n" % (pid, output))
         # write out
         fp = open("%slet%d.xml" % (config.RSSDIR, pid), "w")
         fp.write(output.encode('utf8'))
         fp.close()
     logger.debug("End RSS Export.")
开发者ID:forestbaker,项目名称:jqian,代码行数:31,代码来源:rsspub.py

示例5: __init__

    def __init__(self, config, config_global):
        """Init pattern."""
        self.config_defaults = {
            'xxx': 0,
            "list": [
                [
                    1,
                    -1,
                    -1,
                    -1,
                    -1,
                    1,
                    -1,
                    -1,
                    -1,
                    -1,
                    1,
                    -1,
                    -1,
                    -1,
                    -1,
                    1
                ],
                [
                    0,
                    -1,
                    -1,
                    -1,
                    -1,
                    0,
                    -1,
                    -1,
                    -1,
                    -1,
                    0,
                    -1,
                    -1,
                    -1,
                    -1,
                    0
                ]
            ],
        }
        # python3 syntax
        # super().__init__()
        # python2 syntax
        # super(Pattern, self).__init__()
        # explicit call
        Pattern.__init__(self, config, config_global)

        # inits for this pattern
        self.strobe_state = False
开发者ID:s-light,项目名称:OLA_test_pattern_generator,代码行数:52,代码来源:strobe.py

示例6: __fetch

 def __fetch(self, task_entry):
     p = Pattern(task_entry, self.__getCurrentShell(task_entry), self.config_data)
     urls = p.convertPattern('url')
     s = requests.session()
     task_entry['datas'] = []
     for url in urls:
         self.logger.info("fetching " + url)
         if "" == url:
             # do not fetch null url
             continue
         response = s.get(url)
         if 200 != response.status_code:
             self.logger.error("fetch " + url + " failed with code" + response.status_code)
         data = response.text
         task_entry['datas'].append(data)
     return task_entry
开发者ID:hitsmaxft,项目名称:pyrailgun,代码行数:16,代码来源:__init__.py

示例7: loadPatternsFromFile

def loadPatternsFromFile(f):

	# load patterns from file f
	# return: a list of patterns
	
	patterns = list();
	xy = False;
	p = 0;

	ifile = open(f);
	for line in ifile:
		if(line.startswith("===")):
			if p!=0:
				patterns.append(p)
			p = Pattern();
			xy = True;
			continue;
		elements = line.strip().split("\t");

		if xy == True:
			xy = False;
			p.x = elements[0];
			p.y = elements[1];

		v1 = p.g.add_node(elements[0],l=int(elements[1]));
		for i in range(2,len(elements)):
			p.g.add_edge(elements[0],elements[i]);
		# g.elements[0]
		p.covered.add(p.id);

	if(p!=0):
		patterns.append(p);

	if(debug):
		for p in patterns:
			# printG(g,1,0);
			print p.id;
			print p.g.nodes(data=True)
			print p.g.edges();
	

	return patterns;
开发者ID:yecol,项目名称:exp-armining,代码行数:42,代码来源:disc.py

示例8: __fetch_webkit

    def __fetch_webkit(self, task_entry):
        p = Pattern(task_entry, self.__getCurrentShell(task_entry), self.global_data)

        import cwebbrowser

        task_entry['datas'] = []

        urls = p.convertPattern('url')
        timeout = task_entry.get('timeout', 120)
        delay = task_entry.get('delay', 0)

        for url in urls:
            self.logger.info("fetching " + url)
            data = ""
            if not url:
                # do not fetch null url
                continue
            browser = cwebbrowser.CWebBrowser()
            browser.setHeaders(task_entry.get('headers', []))
            #browser.show();
            try:
                browser.load(url=url, load_timeout=timeout, delay=delay)
            except cwebbrowser.Timeout:
                self.logger.error("fetch " + url + " timeout ")
            except  Exception, exception:
                self.logger.error("fetch " + url + " error ")
                print "Exception message:", exception

            else:
                html = browser.html()
                if html:
                    html = html.encode('utf-8')
                    data = html
                else:
                    self.logger.error("fetch " + url + " failed with no response")
            task_entry['datas'].append(data)

            browser.close()
开发者ID:zesov,项目名称:pyrailgun,代码行数:38,代码来源:railgun.py

示例9: __init__

 def __init__(self, input, length=0.05, gain=0.67):
     PyoObject.__init__(self)
     self.points = None
     self.viewFrame = None
     self._input = input
     self._length = length
     self._gain = gain
     self._width = 500
     self._height = 400
     self._in_fader = InputFader(input)
     in_fader, lmax = convertArgsToLists(self._in_fader)
     self._base_objs = [Scope_base(wrap(in_fader,i), length) for i in range(lmax)]
     self.view()
     self._timer = Pattern(self.refreshView, length).play()
开发者ID:ttm,项目名称:pyo,代码行数:14,代码来源:analysis.py

示例10: PatternListener

class PatternListener(liblo.ServerThread):
    def __init__(self, address=8765):
        liblo.ServerThread.__init__(self, address)
        self.pattern = Pattern()

    @liblo.make_method('/pattern/set', 'ii')
    def set_callback(self, path, args):
        track, step = args
        self.pattern.set_step(track, step)

    @liblo.make_method('/pattern/clear', 'ii')
    def clear_callback(self, path, args):
        track, step = args
        self.pattern.clear_step(track, step)

    @liblo.make_method('/pattern/mute', 'i')
    def mute_callback(self, path, track):
        self.pattern.mute(track)

    @liblo.make_method('/pattern/unmute', 'i')
    def unmute_callback(self, path, track):
        self.pattern.unmute(track)
开发者ID:Mondego,项目名称:pyreco,代码行数:22,代码来源:allPythonContent.py

示例11: Pattern

from pattern import Pattern

#----test some known valid cases

p = Pattern([4,4,1])
if(p.is_valid() == False):
	print "test_fail, pattern [4,4,1] should be a valid siteswap"
if(p.particles != 3):
	print "test_fail, pattern [4,4,1] should have 3 balls"

p = Pattern([1,-1,0])
if(p.is_valid() == False):
	print "test_fail, pattern [1,-1,0] should be a valid siteswap"
if(p.particles != 0):
	print "test_fail, pattern [1,-1,0] should have 0 balls"
	
p = Pattern([2,3,3,-2,2,-2,1,1])
if(p.is_valid() == False):
	print "test_fail, pattern [2,3,3,-2,2,-2,1,1] should be a valid siteswap"
if(p.particles != 1):
	print "test_fail, pattern [2,3,3,-2,2,-2,1,1] should have 1 ball"

#----test some known invalid cases
#we try to construct the objects, and in case it fails and throws an error
# then we know everything went as expeced
construct_fail = False
try:
	p = Pattern([2,1,0])
except ValueError as e:
	construct_fail = True
开发者ID:juhakivekas,项目名称:balls-in-the-air,代码行数:30,代码来源:pattern_test.py

示例12: emulate

    def emulate(n, steps):
        assert(n>1)
        n = str(n)

        # Set up emulation:
        man = Manager(get_random_port(), get_random_port(), get_random_port())
        man.add_brok()

        m1_int_sel_in_gpot = '/a/in/gpot0,/a/in/gpot1'
        m1_int_sel_out_gpot = '/a/out/gpot0,/a/out/gpot1'
        m1_int_sel_in_spike = '/a/in/spike0,/a/in/spike1'
        m1_int_sel_out_spike = '/a/out/spike0,/a/out/spike1'
        m1_int_sel = ','.join([m1_int_sel_in_gpot, m1_int_sel_out_gpot,
                               m1_int_sel_in_spike, m1_int_sel_out_spike])
        m1_int_sel_in = ','.join([m1_int_sel_in_gpot, m1_int_sel_in_spike])
        m1_int_sel_out = ','.join([m1_int_sel_out_gpot, m1_int_sel_out_spike])
        m1_int_sel_gpot = ','.join([m1_int_sel_in_gpot, m1_int_sel_out_gpot])
        m1_int_sel_spike = ','.join([m1_int_sel_in_spike, m1_int_sel_out_spike])
        N1_gpot = SelectorMethods.count_ports(m1_int_sel_gpot)
        N1_spike = SelectorMethods.count_ports(m1_int_sel_spike)
        m1 = MyModule(m1_int_sel,
                      m1_int_sel_in, m1_int_sel_out,
                      m1_int_sel_gpot, m1_int_sel_spike,
                      np.zeros(N1_gpot, np.float64),
                      np.zeros(N1_spike, int), ['interface', 'io', 'type'],
                      man.port_data, man.port_ctrl, man.port_time, 'm1', None,
                      False, True)
        man.add_mod(m1)

        m2_int_sel_in_gpot = '/b/in/gpot0,/b/in/gpot1'
        m2_int_sel_out_gpot = '/b/out/gpot0,/b/out/gpot1'
        m2_int_sel_in_spike = '/b/in/spike0,/b/in/spike1'
        m2_int_sel_out_spike = '/b/out/spike0,/b/out/spike1'
        m2_int_sel = ','.join([m2_int_sel_in_gpot, m2_int_sel_out_gpot,
                               m2_int_sel_in_spike, m2_int_sel_out_spike])
        m2_int_sel_in = ','.join([m2_int_sel_in_gpot, m2_int_sel_in_spike])
        m2_int_sel_out = ','.join([m2_int_sel_out_gpot, m2_int_sel_out_spike])
        m2_int_sel_gpot = ','.join([m2_int_sel_in_gpot, m2_int_sel_out_gpot])
        m2_int_sel_spike = ','.join([m2_int_sel_in_spike, m2_int_sel_out_spike])
        N2_gpot = SelectorMethods.count_ports(m2_int_sel_gpot)
        N2_spike = SelectorMethods.count_ports(m2_int_sel_spike),
        m2 = MyModule(m2_int_sel,
                      m2_int_sel_in, m2_int_sel_out,
                      m2_int_sel_gpot, m2_int_sel_spike,
                      np.zeros(N2_gpot, np.float64),
                      np.zeros(N2_spike, int), ['interface', 'io', 'type'],
                      man.port_data, man.port_ctrl, man.port_time, 'm2', None,
                      False, True)
        man.add_mod(m2)

        # Make sure that all ports in the patterns' interfaces are set so 
        # that they match those of the modules:
        pat12 = Pattern(m1_int_sel, m2_int_sel)
        pat12.interface[m1_int_sel_out_gpot] = [0, 'in', 'gpot']
        pat12.interface[m1_int_sel_in_gpot] = [0, 'out', 'gpot']
        pat12.interface[m1_int_sel_out_spike] = [0, 'in', 'spike']
        pat12.interface[m1_int_sel_in_spike] = [0, 'out', 'spike']
        pat12.interface[m2_int_sel_in_gpot] = [1, 'out', 'gpot']
        pat12.interface[m2_int_sel_out_gpot] = [1, 'in', 'gpot']
        pat12.interface[m2_int_sel_in_spike] = [1, 'out', 'spike']
        pat12.interface[m2_int_sel_out_spike] = [1, 'in', 'spike']
        pat12['/a/out/gpot0', '/b/in/gpot0'] = 1
        pat12['/a/out/gpot1', '/b/in/gpot1'] = 1
        pat12['/b/out/gpot0', '/a/in/gpot0'] = 1
        pat12['/b/out/gpot1', '/a/in/gpot1'] = 1
        pat12['/a/out/spike0', '/b/in/spike0'] = 1
        pat12['/a/out/spike1', '/b/in/spike1'] = 1
        pat12['/b/out/spike0', '/a/in/spike0'] = 1
        pat12['/b/out/spike1', '/a/in/spike1'] = 1
        man.connect(m1, m2, pat12, 0, 1)

        # To set the emulation to exit after executing a fixed number of steps,
        # start it as follows and remove the sleep statement:
        man.start(steps=steps)
        # man.start()
        # time.sleep(2)
        man.stop()
        return m1
开发者ID:chungheng,项目名称:neurokernel,代码行数:78,代码来源:core.py

示例13: random

 def random(self, difficulty):
     board = self.get_board()
     p = Pattern.random_difficulty()
     print(p)
     return p.set_board(board)
开发者ID:renato04,项目名称:sudoku,代码行数:5,代码来源:generator.py

示例14: then

 def then(self, deduction):
     if isinstance(deduction, str):
         self.deduction = Pattern(deduction)
     else:
         self.deduction = deduction
     return self
开发者ID:qwert42,项目名称:fos,代码行数:6,代码来源:rule.py

示例15: len

	print "recheck with bigQ: " , bigQ;
	while len(bigQ)!=0:
		p = bigQ.pop()
		print "p.id=",p.id,"p.x,p.y",p.x, p.y
		if len(shouldHaveAll.difference(p.covered))!=0:
			# not contain all required nodes
			print "discards p id=",p.id,"since don't covered all should cover."
			pass;

		else:
			#generate several Q'
			for e2y in p.g.out_edges():
				if node_match(p.g.node[e2y[1]],p.g.node[p.y]):
					# edges every x->y
					r = Pattern();
					r.g = p.g.copy();
					r.x = p.x;
					r.y = e2y[1];
					print r.x,"---",r.y
					print "edgesize,b4",len(r.g.edges()),r.g.degree(r.y)
					r.g.remove_edge(e2y[0],e2y[1]);
					print "edgesize,aft",len(r.g.edges()),r.g.degree(r.y)
					if r.g.degree(r.y)==0:
						print "remove y", r.y
						r.g.remove_node(r.y); 
					
					# print float(suppThreshold)/confThreshold;
					if computeSupport(baseG,r) <= float(suppThreshold)/confThreshold:
						# WARN: r will be 0;
						sigma.append(r);
开发者ID:yecol,项目名称:exp-armining,代码行数:30,代码来源:disc.py


注:本文中的pattern.Pattern类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。