本文整理汇总了Python中Scanner类的典型用法代码示例。如果您正苦于以下问题:Python Scanner类的具体用法?Python Scanner怎么用?Python Scanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scanner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cmp_lt
def test_cmp_lt(self):
scanner = Scanner('a > b')
scanner.lex()
parser = Parser(scanner.tokens)
ast = parser.expr()
self.assertEqual(ast, test_asts['a > b'])
示例2: parseRegexp
def parseRegexp(self, scanner):
# leading '/' is already consumed
rexp = ""
in_char_class = False
token = scanner.next()
while True:
rexp += token.value # accumulate token strings
# -- Check last token
# character classes
if token.value == "[":
if not Scanner.is_last_escaped(rexp): # i.e. not preceded by an odd number of "\"
in_char_class = True
elif token.value == "]" and in_char_class:
if not Scanner.is_last_escaped(rexp):
in_char_class = False
# check for termination of rexp
elif rexp[-1] == "/" and not in_char_class: # rexp[-1] != token.value if token.value == "//"
if not Scanner.is_last_escaped(rexp):
break
token = scanner.next()
# regexp modifiers
try:
if scanner.peek()[0].name == "ident":
token = scanner.next()
rexp += token.value
except StopIteration:
pass
return rexp
示例3: load_rules
def load_rules():
file = request.files['file']
if file == False or allowed_file(file.filename) == False:
return Response(status=500, mimetype='application/json')
try:
file_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(file_path)
Scanner.load_yaml_rules(file_path)
return Response(status=200, mimetype='application/json')
except Exception as e:
logging.error(e)
return Response(status=500, mimetype='application/json')
示例4: cmp_ast
def cmp_ast(self, expr, expect):
scanner = Scanner(expr)
scanner.lex()
parser = Parser(scanner.tokens)
ast = parser.parse()
# eval_visitor = ASTEvalVisitor()
# res = eval_visitor.eval(ast)
# disp_visitor = ASTDisplayVisitor()
# disp_visitor.display(ast)
self.assertEqual(ast, expect)
示例5: common
def common(self, expr, expect):
scanner = Scanner(expr)
scanner.lex()
parser = Parser(scanner.tokens)
ast = parser.parse()
eval_visitor = ASTEvalVisitor()
res = eval_visitor.eval(ast)
disp_visitor = ASTDisplayVisitor()
disp_visitor.display(ast)
self.assertEqual(res, expect)
示例6: __init__
def __init__(self, log_flag):
self.logger = Logger(log_flag, LOG_FILE);
self.logger.info('Started Greenleaf Slave daemon');
print('######## SLAVE DAEMON #######')
self.connected_masters = {};
self.connected_knx = [];
self.connected_enocean = [];
self.clients = [];
self._scanner = Scanner(HOST_CONF_FILE);
self._scanner.scan(False);
self._hostlist = self._scanner._HostList;
self._parser = DaemonConfigParser(SLAVE_CONF_FILE);
self.encrypt_keys = {};
self.knx_sock = None;
self.master_sock = None;
self.enocean_sock = None;
self.private_aes = hashlib.md5(self._parser.getValueFromSection('personnal_key', 'aes').encode()).hexdigest();
self.functions = {
KNX_READ_REQUEST : self.knx_read_request,
KNX_WRITE_SHORT : self.knx_write_short,
KNX_WRITE_LONG : self.knx_write_long,
KNX_WRITE_TEMP : self.knx_write_temp,
CHECK_SLAVE : self.check_slave,
MONITOR_IP : self.monitor_ip,
DATA_UPDATE : self.update
};
示例7: IOManager
class IOManager(object):
def __init__(self):
led = 11
button = 13
GPIO.setmode(GPIO.BOARD)
GPIO.setup(led, GPIO.OUT)
self.__scanner = Scanner()
self.__button = Button(button)
self.__led = LED(led)
self.__printer = Printer()
#set up connections and variables for button, light, printer, and scanner
def getButton(self):
return self.__button.getButtonBool()
def getScan(self):
return self.__scanner.getInput()
def setLight(self, value):
self.__led.setValue(value)
def blinkLight(self):
self.__led.blink()
def printReceipt(self, items):
if items:
self.__printer.printHeader()
for item in items:
self.__printer.printItem(item)
self.__printer.printTotals(items)
self.__printer.complete()
示例8: __init__
def __init__(self, log_flag):
self.logger = Logger(log_flag, LOG_FILE);
self.logger.info('Started Domoleaf Slave daemon');
print('######## SLAVE DAEMON #######')
self.connected_masters = {};
self.connected_knx = [];
self.connected_enocean = [];
self.connected_cron = [];
self.clients = [];
self._scanner = Scanner(HOST_CONF_FILE);
self._scanner.scan(False);
self._hostlist = self._scanner._HostList;
self._parser = DaemonConfigParser(SLAVE_CONF_FILE);
self.encrypt_keys = {};
self.knx_sock = None;
self.master_sock = None;
self.enocean_sock = None;
self.cron_sock = None;
self.private_aes = hashlib.md5(self._parser.getValueFromSection('personnal_key', 'aes').encode()).hexdigest();
self.wifi_init(self._parser.getValueFromSection('wifi', 'ssid'), self._parser.getValueFromSection('wifi', 'password'), self._parser.getValueFromSection('wifi', 'encryption'), self._parser.getValueFromSection('wifi', 'mode'), 0);
self.functions = {
KNX_READ_REQUEST : self.knx_read_request,
KNX_WRITE_SHORT : self.knx_write_short,
KNX_WRITE_LONG : self.knx_write_long,
KNX_WRITE_TEMP : self.knx_write_temp,
CHECK_SLAVE : self.check_slave,
MONITOR_IP : self.monitor_ip,
DATA_UPDATE : self.update,
SEND_TECH : self.send_tech,
SEND_ALIVE : self.send_alive,
SEND_INTERFACES : self.send_interfaces,
SHUTDOWN_D3 : self.shutdown_d3,
REBOOT_D3 : self.reboot_d3,
WIFI_UPDATE : self.wifi_update
};
示例9: main
def main():
"""
Assume we pass this script the image file path as an argument on the
command line.
"""
usage = 'usage: %prog [options] imagefile'
parser = OptionParser(usage=usage)
parser.add_option('--chunksize', action='store', type='int',
dest='chunk_size', default=2048)
parser.add_option('--oobsize', action='store', type='int',
dest='oob_size', default=64)
options, args = parser.parse_args()
if len(args) != 1:
print "Incorrect command line arguments. Missing (or too many) image files"
return 1
image = args[0]
headers = Scanner.get_anchor_headers(image, options.chunk_size,
options.oob_size, 'contacts2.db')
oobs = YaffsParser.get_oob_bytes(image, headers, options.oob_size)
for oob in oobs:
sys.stdout.write(oob)
#Separate each oob with 16 'X' Bytes.
sys.stdout.write('X'*16)
示例10: processSCAN2Phase
def processSCAN2Phase(self, tran, obj, data):
# compute scanner for all objects on the map
playerMap = Scanner.computeMap(self, tran, obj)
# distribute map
for playerID, map in playerMap.iteritems():
player = tran.db[playerID]
self.cmd(player).mergeScannerMap(tran, player, map)
return
示例11: duplexScan
def duplexScan(self):
self.setScanning( True )
self.scan = Scanner(self)
self.scan.setDuplex( True )
self.connect( self.scan, SIGNAL('scanned(QImage)'), self.scanned )
self.connect( self.scan, SIGNAL('error(int)'), self.error )
self.connect( self.scan, SIGNAL('finished()'), self.finished )
self.scan.startScan()
示例12: parseString
def parseString(scanner, sstart):
# parse string literals
result = ""
for token in scanner:
result += token.value
if token.value == sstart and not Scanner.is_last_escaped(result): # be aware of escaped quotes
break
return result
示例13: __init__
def __init__(self, log_flag):
## Logger object for formatting and printing logs
self.logger = Logger(log_flag, LOG_FILE)
self.logger.info("Started Domoleaf Slave daemon")
## Array of master daemon on local network
self.connected_masters = {}
## Array of monitor KNX on local network
self.connected_knx = []
## Array of monitor EnOcean on local network
self.connected_enocean = []
## Array of cron running on the system
self.connected_cron = []
self._scanner = Scanner(log_flag)
self._hostlist = []
myhostname = socket.gethostname().upper()
if SLAVE_NAME_PREFIX in myhostname:
self._scanner.scan()
self._hostlist = self._scanner._HostList
else:
self._hostlist.append(Host("", "127.0.0.1", myhostname))
self._parser = DaemonConfigParser(SLAVE_CONF_FILE)
## Keys for encrypting communications
self.encrypt_keys = {}
## Main socket for communication with KNX daemon
self.knx_sock = None
## Main socket for communication with master daemon
self.master_sock = None
## Main socket for communication with enocean daemon
self.enocean_sock = None
## Main socket for communication with cron
self.cron_sock = None
## Private AES key got from configuration file
self.private_aes = self._parser.getValueFromSection("personnal_key", "aes")
self.wifi_init(
self._parser.getValueFromSection("wifi", "ssid"),
self._parser.getValueFromSection("wifi", "password"),
self._parser.getValueFromSection("wifi", "encryption"),
self._parser.getValueFromSection("wifi", "mode"),
0,
)
## Port on which connect got from configuration file
self.connect_port = self._parser.getValueFromSection(SLAVE_CONF_CONNECT_SECTION, SLAVE_CONF_CONNECT_PORT_ENTRY)
## Callback array indexed on packet type
self.functions = {
KNX_READ_REQUEST: self.knx_read_request,
KNX_WRITE_SHORT: self.knx_write_short,
KNX_WRITE_LONG: self.knx_write_long,
KNX_WRITE_TEMP: self.knx_write_temp,
CHECK_SLAVE: self.check_slave,
MONITOR_IP: self.monitor_ip,
DATA_UPDATE: self.update,
SEND_TECH: self.send_tech,
SEND_ALIVE: self.send_alive,
SEND_INTERFACES: self.send_interfaces,
SHUTDOWN_D3: self.shutdown_d3,
REBOOT_D3: self.reboot_d3,
WIFI_UPDATE: self.wifi_update,
}
示例14: networkScan
def networkScan( scheduler ):
logging.info('Scanning Network')
scan = Scanner.scanNetwork( mac=config.get('ScannerProperties','target'),
network=config.get('ScannerProperties','network'))
if (scan == 1):
SqliteHandler.logConnection()
logging.info('Connection Logged')
scheduler.enter(60,1,networkScan,(scheduler, ))
return
示例15: parseCommentM
def parseCommentM(self, scanner):
res = []
while True:
token = scanner.next(r'\*/') # inform the low-level scanner to switch to commentM
res.append(token.value)
if not Scanner.is_last_escaped(token.value):
break
# run-away comments bomb in the above scanner.next()
return u"".join(res)