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


Python Scanner.scan方法代码示例

本文整理汇总了Python中scanner.Scanner.scan方法的典型用法代码示例。如果您正苦于以下问题:Python Scanner.scan方法的具体用法?Python Scanner.scan怎么用?Python Scanner.scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scanner.Scanner的用法示例。


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

示例1: __init__

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
class Parser:
    def __init__(self, text=''):
        self.lex     = Scanner(text)           # make a scanner
        self.vars    = {'pi':3.14159}          # add constants
        self.traceme = TraceDefault
 
    def parse(self, *text):                    # external interface
        if text: 
            self.lex.newtext(text[0])          # reuse with new text
        tree = self.analyse()                  # parse string
        if tree:
            if self.traceme:                   # dump parse-tree?
                print; tree.trace(0)
            if self.errorCheck(tree):          # check names
                self.interpret(tree)           # evaluate tree

    def analyse(self):
        try:
            self.lex.scan()                    # get first token
            return self.Goal()                 # build a parse-tree
        except SyntaxError:
            print 'Syntax Error at column:', self.lex.start
            self.lex.showerror()
        except LexicalError:
            print 'Lexical Error at column:', self.lex.start
            self.lex.showerror()

    def errorCheck(self, tree):
        try:
            tree.validate(self.vars)           # error checker
            return 'ok'
        except UndefinedError, varinfo:
            print "'%s' is undefined at column: %d" % varinfo
            self.lex.start = varinfo[1]
            self.lex.showerror()               # returns None 
开发者ID:inteljack,项目名称:EL6183-Digital-Signal-Processing-Lab-2015-Fall,代码行数:37,代码来源:parser2.py

示例2: Tray

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
class Tray(QtWidgets.QSystemTrayIcon):
    def __init__(self, client, icon, parent=None):
        QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
        self.client = client
        self.icon = icon
        self.user = self.client.get_account('me').url
        self.scanner = Scanner(self.client, self)
        self.options = OptionsWindow(self.client, self.scanner, self)
        self.options.init_options()

        self.stop_event = threading.Event()
        self.scan_thread = threading.Thread(target=self.scanner.scan, args=(self.stop_event,))
        self.scan_thread.start()

        menu = QtWidgets.QMenu(parent)

        exitAction = QtWidgets.QAction("&Quit     ", self)
        exitAction.setShortcut("Ctrl+Q")
        exitAction.setStatusTip('Good bye')
        exitAction.triggered.connect(self.appExit)

        optAction = QtWidgets.QAction("&Options...  ", self)
        optAction.setShortcut("Ctrl+O")
        optAction.setStatusTip("Customize")
        optAction.triggered.connect(self.show_options)

        sendAction = QtWidgets.QAction("Copy Link of Last Uploaded Image", self)
        sendAction.setShortcut("Ctrl+S")
        sendAction.setStatusTip("...")
        sendAction.triggered.connect(self.copy_last)

        menu.addAction(sendAction)
        menu.addAction(optAction)
        menu.addSeparator()
        menu.addAction(exitAction)
        self.setContextMenu(menu)

    def appExit(self):
        # Reset OSX Screenshot storage
        with open(os.devnull, 'w') as nul:
            path = os.path.expanduser('~') + '/Desktop/'
            subprocess.call(["defaults", "write", "com.apple.screencapture", "location", path])
            subprocess.call(["killAll", "SystemUIServer"])

        kill_proc_tree(me)
        self.stop_event.set()
        self.scanner.scan(self.stop_event)
        sys.exit()

    def show_options(self):
        self.options.show_opts()

    def copy_last(self):
        if self.scanner.loader.link == '':
            self.scanner.loader.to_clipboard()
        else:
            self.scanner.loader.to_clipboard()
            self.scanner.loader.copy_notification()
开发者ID:ACollectionOfAtoms,项目名称:imgshare,代码行数:60,代码来源:tray.py

示例3: run

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
    def run(self):
        parsedArgs = self.options.parse()
        scanner = Scanner(parsedArgs.path)
        duplicateCollector = DuplicateCollector()
        scanner.scan(duplicateCollector)

        if parsedArgs.verbose:
            duplicateCollector.write(True)
        else:
            duplicateCollector.write()
开发者ID:mdunhem,项目名称:duplicates-old,代码行数:12,代码来源:controller.py

示例4: __init__

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
class MainController:
    def __init__(self, app):
        self.deviceData = DeviceData()
        self.view = MainView(None)
        self.view.scanForDevices.Bind(wx.EVT_BUTTON, self.ScanForDevices)
        self.view.syncActivities.Bind(wx.EVT_BUTTON, self.SyncActivities)
        self.view.Bind(wx.EVT_MENU, self.OnAbout, self.view.aboutMenuItem)
        self.view.Bind(wx.EVT_MENU, self.OnExit, self.view.exitMenuItem)
        self.view.Show()
        self.scanner = Scanner()
        ## TODO Preferences for Selected Scanners
        self.scanner.addScanner(AntScanner())
        self.connector = Connector()
        ## TODO Preferences for Selected Connectors
        self.connector.addConnector(GarminConnector())
        pub.subscribe(self.ScanningStarted, "SCANNING STARTED")
        pub.subscribe(self.DeviceDetected, "DEVICE DETECTED")
        pub.subscribe(self.ActivityRetrieved, "ACTIVITY RETRIEVED")
        pub.subscribe(self.ScanningEnded, "SCANNING ENDED")
        pub.subscribe(self.SyncStarted, "SYNC STARTED")
        pub.subscribe(self.SyncEnded, "SYNC ENDED")
        pub.subscribe(self.LoginSuccesful, "LOGIN SUCCESFUL")
        pub.subscribe(self.LoginFailed, "LOGIN FAILED")
        pub.subscribe(self.ActivitiesUploaded, "ACTIVITIES UPLOADED")
    def ScanForDevices(self, evt):
        self.scanner.scan()
    def ScanningStarted(self, evt):
        self.view.setStatus("Scanning started")
    def ScanningEnded(self, evt):
        self.view.setStatus("Scanning ended")
    def DeviceDetected(self, evt):
        self.view.setStatus("Device detected")
    def ActivityRetrieved(self, evt):
        self.view.setStatus("Retrieved activity")
    def SyncActivities(self, evt):
        self.connector.sync()
    def SyncStarted(self, evt):
        self.view.setStatus("Sync started")
    def SyncEnded(self, evt):
        self.view.setStatus("Sync ended")
    def LoginSuccesful(self, evt):
        self.view.setStatus("Login Succesful")
    def LoginFailed(self, evt):
        self.view.setStatus("Login Failed")
    def ActivitiesUploaded(self, evt):
        self.view.setStatus("Activities Uploaded")
    def OnExit(self,e):
        self.Close(True)
    def OnAbout(self, event):
        dlg = wx.MessageDialog( self.view, "A community-developed Linux version of the ANT Agent. Supports Garmin-based fitness devices that communicate either over USB serial or via the ANT USB connector. Developed by Philip Whitehouse, based on work by Braiden Kindt, Gustav Tiger and Collin (cpfair). Copyright 2014", "About ANT Agent for Linux", wx.OK);
        dlg.ShowModal()
        dlg.Destroy()
开发者ID:philipwhiuk,项目名称:garmin-Ant-GUI,代码行数:54,代码来源:main.py

示例5: test_01

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
def test_01():
    text_XX = """
@@ aa
"""

    def callback(mo):
        D("callback %r", mo)

    scanner = Scanner((
        (r'^@@', callback),
        (r'aaa', callback),
    ), re.MULTILINE)
    scanner.scan(text_XX)
开发者ID:bossjones,项目名称:etc-python,代码行数:15,代码来源:test_scanner.py

示例6: main

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
def main(argv):
    if len(argv) == 1 or len(argv) > 2:
        usage()
        sys.exit(2)
    try:
        path = argv[1]
        scanner = Scanner()
        scanner.scan(path)
        scanner.rebuild_tracks()
        fcpxml = FcpXML()
        fcpxml.create_xml()
    except getopt.GetoptError, err:
        print str(err)
        usage()
        sys.exit(2)
开发者ID:liaozd,项目名称:melissa,代码行数:17,代码来源:go.py

示例7: compile_pascal

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
def compile_pascal(source, dest, is_debug = False, is_interpret = False, out_stream = sys.stdout, output_tokens = False, output_bytecodes = False, lib = ['.'], in_stream = sys.stdin):
  '''
  DID YOU KNOW that compile() is a built in function?
  '''
  set_debug(is_debug)
  debug("Compiling %s into %s" % (source, dest))
  scanner = Scanner(source)
  tokens = scanner.scan()
  if output_tokens:
    write(tokens, source + "_tokenized")
  debug('scanning complete')
  parser = Parser(tokens, source, lib = lib)
  bytecodes, success = parser.parse()
  if output_bytecodes:
    if is_debug:
      write(prettify(bytecodes), source + "_unassembled")
    else:
      write(bytecodes, source + "_unassembled")
  if not success:
    print 'Parsing error'
    return
  debug('parsing complete')
  assembler = Assembler(bytecodes)
  assembled = assembler.assemble()
  if is_debug:
    write(prettify(assembled), dest + '_debug')
  write(assembled, dest)
  debug('assembly complete.' )
  if is_interpret:
    interp = Interpreter(out_stream, in_stream, code = assembled)
    interp.interpret()
  else:
    debug('run program now with `python interpreter.py %s`' % dest)
开发者ID:FoxLisk,项目名称:Pascal-Minus,代码行数:35,代码来源:pascalm.py

示例8: run

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
    def run(cls):
        s3 = boto.connect_s3()

        prod_bucket = s3.get_bucket('dray-assets-prod')
        load_files = list(prod_bucket.list(prefix="media/loads"))
        document_files = [f for f in load_files if "load_action_approvals" not in f.name]

        for f in document_files:
            # Check for existing scanned version
            filename, file_extension = os.path.splitext(f.key)
            result_keyname = filename + "-scanned" + file_extension
            possible_key = prod_bucket.get_key(result_keyname)
            if possible_key is not None or "-scanned" in f.key:
                # Scanned file already exists, move on
                continue

            # Read image and scan
            image = prod_bucket.get_key(f.key)
            image.get_contents_to_filename('tmp/tmp-src.png')
            result_filename = Scanner.scan('tmp/tmp-src.png')

            # Create new key for result file
            k = Key(prod_bucket)
            k.key = result_keyname
            k.set_contents_from_filename(result_filename)
开发者ID:twuster,项目名称:DocumentScanner,代码行数:27,代码来源:runner.py

示例9: test_can_scan

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
    def test_can_scan(self):
        self.skipTest('Don\'t know how to test with SSH :/')
        scanner = Scanner(network_tools=NetworkToolsStub(), hostname='10.0.1.231')

        scan = scanner.scan(port=9100)

        self.assertDictEqual(scan, {})
开发者ID:,项目名称:,代码行数:9,代码来源:

示例10: test_3

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
def test_3():
    s = Scanner()
    input_string = 'naqsh faryaadii hai kis kii sho;xii-e ta;hriir kaa'
    scan_results = s.scan(input_string, known_only=True)

    assert len(scan_results['results']) == 1
    
    result = scan_results['results'][0]
    assert len(scan_results['results']) == 1
    assert result['scan'] == '=-===-===-===-=', result['scan']
开发者ID:asp49,项目名称:meter,代码行数:12,代码来源:test_basic.py

示例11: __init__

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
class Parser:
    def __init__(self, text=''):
        self.lex  = Scanner(text)              # embed a scanner
        self.vars = {'pi':3.14159}             # add a variable

    def parse(self, *text):
        if text:                               # main entry-point
            self.lex.newtext(text[0])          # reuse this parser?
        try:
            self.lex.scan()                    # get first token
            self.Goal()                        # parse a sentence
        except SyntaxError:
            print 'Syntax Error at column:', self.lex.start
            self.lex.showerror()
        except LexicalError:
            print 'Lexical Error at column:', self.lex.start
            self.lex.showerror()
        except UndefinedError, name:
            print "'%s' is undefined at column:" % name, self.lex.start
            self.lex.showerror()
开发者ID:inteljack,项目名称:EL6183-Digital-Signal-Processing-Lab-2015-Fall,代码行数:22,代码来源:parser1.py

示例12: consume_text_worker

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
def consume_text_worker( params ):

	then 			= datetime.datetime.now()

	offset			= 0
	if OFFSET_KEY in params:
		offset = int( params[ OFFSET_KEY ] )

	text 			= datastore.read_current_blob( offset )
	scanner 		= Scanner( text )
	current_word 	= None
	num_tasks 		= 0 
	pattern			= re.compile( r"[\w']+|[.,!?;]" )
	timeout			= False
	elapsed			= None

	while not timeout and not scanner.eos():
		
		token = scanner.scan( pattern )
		if current_word is not None:
			add_forward_link( current_word, token )
			num_tasks = num_tasks + 1
		current_word = token
		scanner.get()

		elapsed = datetime.datetime.now() - then
		if elapsed >= TASK_TIME:
			offset = scanner.pos 
			add_task( "/tasks/consume_text", { OFFSET_KEY : offset } )
			logging.debug( "consume_text_worker hit timelimit, will resume at offset %d" % offset )
			timeout = True
	
	logging.debug( "scanned %d tokens in %d seconds" % (num_tasks,elapsed.total_seconds() ) )

	if scanner.eos():
		finalise_links()
开发者ID:prehensile,项目名称:verbivore-appengine,代码行数:38,代码来源:tasks.py

示例13: list

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
import boto
import os

from boto.s3.key import Key
from scanner import Scanner

s3 = boto.connect_s3()

prod_bucket = s3.get_bucket('dray-assets-prod')
load_files = list(prod_bucket.list(prefix="media/loads"))
document_files = [f for f in load_files if "load_action_approvals" not in f.name]

for f in document_files:
    # Check for existing scanned version
    filename, file_extension = os.path.splitext(f.key)
    result_keyname = filename + "-scanned" + file_extension
    possible_key = prod_bucket.get_key(result_keyname)
    if possible_key is not None or "-scanned" in f.key:
        # Scanned file already exists, move on
        continue

    # Read image and scan
    image = prod_bucket.get_key(f.key)
    image.get_contents_to_filename('tmp/tmp-src.png')
    result_filename = Scanner.scan('tmp/tmp-src.png')

    # Create new key for result file
    k = Key(prod_bucket)
    k.key = result_keyname
    k.set_contents_from_filename(result_filename)
开发者ID:twuster,项目名称:DocumentScanner,代码行数:32,代码来源:test.py

示例14: __init__

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
class Parser:
    def __init__(self, text=''):
        self.lex  = Scanner(text)              # embed a scanner
        self.vars = {'pi': 3.14159}            # add a variable

    def parse(self, *text):
        if text:                               # main entry-point
            self.lex.newtext(text[0])          # reuse this parser?
        try:
            self.lex.scan()                    # get first token
            self.Goal()                        # parse a sentence
        except SyntaxError:
            print('Syntax Error at column:', self.lex.start)
            self.lex.showerror()
        except LexicalError:
            print('Lexical Error at column:', self.lex.start)
            self.lex.showerror()
        except UndefinedError as E:
            name = E.args[0]
            print("'%s' is undefined at column:" % name, self.lex.start)
            self.lex.showerror()

    def Goal(self):
        if self.lex.token in ['num', 'var', '(']:
            val = self.Expr()
            self.lex.match('\0')                    # expression?
            print(val)
        elif self.lex.token == 'set':               # set command?
            self.Assign()
            self.lex.match('\0')
        else:
            raise SyntaxError()

    def Assign(self):
        self.lex.match('set')
        var = self.lex.match('var')
        val = self.Expr()
        self.vars[var] = val           # assign name in dict

    def Expr(self):
        left = self.Factor()
        while True:
            if self.lex.token in ['\0', ')']:
                return left
            elif self.lex.token == '+':
                self.lex.scan()
                left = left + self.Factor()
            elif self.lex.token == '-':
                self.lex.scan()
                left = left - self.Factor()
            else:
                raise SyntaxError()

    def Factor(self):
        left = self.Term()
        while True:
            if self.lex.token in ['+', '-', '\0', ')']:
                return left
            elif self.lex.token == '*':
                self.lex.scan()
                left = left * self.Term()
            elif self.lex.token == '/':
                self.lex.scan()
                left = left / self.Term()
            else:
                raise SyntaxError()

    def Term(self):
        if self.lex.token == 'num':
            val = self.lex.match('num')               # numbers
            return val
        elif self.lex.token == 'var':
            if self.lex.value in self.vars.keys():    # keys(): EIBTI!
                val = self.vars[self.lex.value]       # look up name's value
                self.lex.scan()
                return val
            else:
                raise UndefinedError(self.lex.value)
        elif self.lex.token == '(':
            self.lex.scan()
            val = self.Expr()                         # sub-expression
            self.lex.match(')')
            return val
        else:
            raise SyntaxError()
开发者ID:KhalidEzzeldeen,项目名称:BitsAndBobs,代码行数:87,代码来源:parser1.py

示例15: Scanner

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import scan [as 别名]
scanner = Scanner()

data = {}
import csv
verses = {}
multiple_matches = []
total_verses  = 0
total_matches = 0
with open('data/verses.csv', 'rb') as csvfile:
    versereader = csv.reader(csvfile, delimiter=',', quotechar='|')
    count = 0
    multiple_match_count = 0
    for row in versereader:
        (verse_id, input_string, real_scan) = row
        scan = scanner.scan(input_string, known_only = True)
#        if not(len(scan['results'])>0):
#
#            print 'Error '+verse_id+":"+input_string
#            scan = scanner.scan(input_string, known_only = False)
#            print scanner.print_scan(scan)
#            scan = scanner.scan(input_string, known_only = True)
        total_matches+=len(scan['results'])
        total_verses +=1
              
        assert len(scan['results'])>0

print 'total verses = '+str(total_verses)
print 'total matches = '+str(total_matches)
assert total_verses==3314
assert total_matches==4036
开发者ID:asp49,项目名称:meter,代码行数:32,代码来源:tst.py


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