summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo <hugovk@users.noreply.github.com>2018-08-21 15:40:38 +0300
committerHugo <hugovk@users.noreply.github.com>2018-08-21 15:40:38 +0300
commitc3dba1ed5f9be226044c7ffaf1cd47adcc7482f4 (patch)
tree2c0c45c153434d0c6b78c0d5e51448933f959fb8
parent444859662f1829f2d8068fb33cdc375427bf9b6c (diff)
downloadpyparsing-git-c3dba1ed5f9be226044c7ffaf1cd47adcc7482f4.tar.gz
Upgrade Python syntax with pyupgrade
-rw-r--r--examples/adventureEngine.py2
-rw-r--r--examples/gen_ctypes.py16
-rw-r--r--examples/getNTPserversNew.py2
-rw-r--r--examples/parseListString.py2
-rw-r--r--examples/parseResultsSumExample.py1
-rw-r--r--examples/protobuf_parser.py2
-rw-r--r--examples/pymicko.py68
-rw-r--r--examples/pythonGrammarParser.py4
-rw-r--r--examples/rangeCheck.py2
-rw-r--r--examples/searchParserAppDemo.py4
-rw-r--r--examples/searchparser.py90
-rw-r--r--examples/shapes.py2
-rw-r--r--examples/simpleWiki.py2
-rw-r--r--examples/sparser.py4
-rw-r--r--examples/stateMachine2.py10
-rw-r--r--examples/urlExtractor.py2
-rw-r--r--examples/urlExtractorNew.py2
17 files changed, 107 insertions, 108 deletions
diff --git a/examples/adventureEngine.py b/examples/adventureEngine.py
index be09770..cdc618e 100644
--- a/examples/adventureEngine.py
+++ b/examples/adventureEngine.py
@@ -66,7 +66,7 @@ class Room(object):
is_form = "are"
else:
is_form = "is"
- print("There %s %s here." % (is_form, enumerateItems(visibleItems)))
+ print("There {} {} here.".format(is_form, enumerateItems(visibleItems)))
else:
print("You see %s." % (enumerateItems(visibleItems)))
diff --git a/examples/gen_ctypes.py b/examples/gen_ctypes.py
index 9e74819..e79798f 100644
--- a/examples/gen_ctypes.py
+++ b/examples/gen_ctypes.py
@@ -102,7 +102,7 @@ def getUDType(typestr):
key = typestr.rstrip(" *")
if key not in typemap:
user_defined_types.add(key)
- typemap[key] = "%s_%s" % (module, key)
+ typemap[key] = "{}_{}".format(module, key)
def typeAsCtypes(typestr):
if typestr in typemap:
@@ -140,13 +140,13 @@ for en_,_,_ in enum_def.scanString(c_header):
enum_constants.append( (ev.name, ev.value) )
print("from ctypes import *")
-print("%s = CDLL('%s.dll')" % (module, module))
+print("{} = CDLL('{}.dll')".format(module, module))
print()
print("# user defined types")
for tdname,tdtyp in typedefs:
- print("%s = %s" % (tdname, typemap[tdtyp]))
+ print("{} = {}".format(tdname, typemap[tdtyp]))
for fntd in fn_typedefs:
- print("%s = CFUNCTYPE(%s)" % (fntd.fn_name,
+ print("{} = CFUNCTYPE({})".format(fntd.fn_name,
',\n '.join(typeAsCtypes(a.argtype) for a in fntd.fn_args)))
for udtype in user_defined_types:
print("class %s(Structure): pass" % typemap[udtype])
@@ -154,20 +154,20 @@ for udtype in user_defined_types:
print()
print("# constant definitions")
for en,ev in enum_constants:
- print("%s = %s" % (en,ev))
+ print("{} = {}".format(en,ev))
print()
print("# functions")
for fn in functions:
- prefix = "%s.%s" % (module, fn.fn_name)
+ prefix = "{}.{}".format(module, fn.fn_name)
- print("%s.restype = %s" % (prefix, typeAsCtypes(fn.fn_type)))
+ print("{}.restype = {}".format(prefix, typeAsCtypes(fn.fn_type)))
if fn.varargs:
print("# warning - %s takes variable argument list" % prefix)
del fn.fn_args[-1]
if fn.fn_args.asList() != [['void']]:
- print("%s.argtypes = (%s,)" % (prefix, ','.join(typeAsCtypes(a.argtype) for a in fn.fn_args)))
+ print("{}.argtypes = ({},)".format(prefix, ','.join(typeAsCtypes(a.argtype) for a in fn.fn_args)))
else:
print("%s.argtypes = ()" % (prefix))
diff --git a/examples/getNTPserversNew.py b/examples/getNTPserversNew.py
index 14e710c..6995b29 100644
--- a/examples/getNTPserversNew.py
+++ b/examples/getNTPserversNew.py
@@ -31,5 +31,5 @@ serverListPage.close()
addrs = {}
for srvr,startloc,endloc in timeServerPattern.scanString( serverListHTML ):
- print("%s (%s) - %s" % (srvr.ipAddr, srvr.hostname.strip(), srvr.loc.strip()))
+ print("{} ({}) - {}".format(srvr.ipAddr, srvr.hostname.strip(), srvr.loc.strip()))
addrs[srvr.ipAddr] = srvr.loc
diff --git a/examples/parseListString.py b/examples/parseListString.py
index d74f3af..d5723b0 100644
--- a/examples/parseListString.py
+++ b/examples/parseListString.py
@@ -76,7 +76,7 @@ tupleStr.setParseAction( lambda t:tuple(t.asList()) )
listStr <<= (lbrack + Optional(delimitedList(listItem)) + Optional(Suppress(",")) + rbrack)
dictKeyStr = real | integer | quotedString.setParseAction(removeQuotes)
dictStr <<= lbrace + Optional(delimitedList( Group( dictKeyStr + colon + listItem ))) + Optional(Suppress(",")) + rbrace
-dictStr.setParseAction(lambda t: dict((k_v[0],(k_v[1].asList() if isinstance(k_v[1],ParseResults) else k_v[1])) for k_v in t))
+dictStr.setParseAction(lambda t: {k_v[0]:(k_v[1].asList() if isinstance(k_v[1],ParseResults) else k_v[1]) for k_v in t})
test = '[{0: [2], 1: []}, {0: [], 1: [], 2: [,]}, {0: [1, 2,],}]'
print(listStr.parseString(test))
diff --git a/examples/parseResultsSumExample.py b/examples/parseResultsSumExample.py
index 1fb694a..a18ba29 100644
--- a/examples/parseResultsSumExample.py
+++ b/examples/parseResultsSumExample.py
@@ -23,4 +23,3 @@ for test in (samplestr1,samplestr2,samplestr3,samplestr4,):
print()
- \ No newline at end of file
diff --git a/examples/protobuf_parser.py b/examples/protobuf_parser.py
index 04ce0d8..8f8b12d 100644
--- a/examples/protobuf_parser.py
+++ b/examples/protobuf_parser.py
@@ -17,7 +17,7 @@ LBRACE,RBRACE,LBRACK,RBRACK,LPAR,RPAR,EQ,SEMI = map(Suppress,"{}[]()=;")
kwds = """message required optional repeated enum extensions extends extend
to package service rpc returns true false option import"""
for kw in kwds.split():
- exec("%s_ = Keyword('%s')" % (kw.upper(), kw))
+ exec("{}_ = Keyword('{}')".format(kw.upper(), kw))
messageBody = Forward()
diff --git a/examples/pymicko.py b/examples/pymicko.py
index b136689..0db2938 100644
--- a/examples/pymicko.py
+++ b/examples/pymicko.py
@@ -325,7 +325,7 @@ class SymbolTableEntry(object):
def attribute_str(self):
"""Returns attribute string (used only for table display)"""
- return "{0}={1}".format(self.attribute_name, self.attribute) if self.attribute != None else "None"
+ return "{}={}".format(self.attribute_name, self.attribute) if self.attribute != None else "None"
class SymbolTable(object):
"""Class for symbol table of microC program"""
@@ -368,9 +368,9 @@ class SymbolTable(object):
parameters = ""
for p in sym.param_types:
if parameters == "":
- parameters = "{0}".format(SharedData.TYPES[p])
+ parameters = "{}".format(SharedData.TYPES[p])
else:
- parameters += ", {0}".format(SharedData.TYPES[p])
+ parameters += ", {}".format(SharedData.TYPES[p])
print("{0:3d} | {1:^{2}s} | {3:^{4}s} | {5:^{6}s} | {7:^{8}} | ({9})".format(i, sym.name, sym_len, SharedData.KINDS[sym.kind], kind_len, SharedData.TYPES[sym.type], type_len, sym.attribute_str(), attr_len, parameters))
def insert_symbol(self, sname, skind, stype):
@@ -524,7 +524,7 @@ class CodeGenerator(object):
"""Class for code generation methods."""
#dictionary of relational operators
- RELATIONAL_DICT = dict([op,i] for i, op in enumerate(SharedData.RELATIONAL_OPERATORS))
+ RELATIONAL_DICT = {op:i for i, op in enumerate(SharedData.RELATIONAL_OPERATORS)}
#conditional jumps for relational operators
CONDITIONAL_JUMPS = ["JLTS", "JGTS", "JLES", "JGES", "JEQ ", "JNE ",
"JLTU", "JGTU", "JLEU", "JGEU", "JEQ ", "JNE "]
@@ -604,7 +604,7 @@ class CodeGenerator(object):
internal - boolean value, adds "@" prefix to label
definition - boolean value, adds ":" suffix to label
"""
- return "{0}{1}{2}".format(self.internal if internal else "", name, self.definition if definition else "")
+ return "{}{}{}".format(self.internal if internal else "", name, self.definition if definition else "")
def symbol(self, index):
"""Generates symbol name from index"""
@@ -616,14 +616,14 @@ class CodeGenerator(object):
sym = self.symtab.table[index]
#local variables are located at negative offset from frame pointer register
if sym.kind == SharedData.KINDS.LOCAL_VAR:
- return "-{0}(%14)".format(sym.attribute * 4 + 4)
+ return "-{}(%14)".format(sym.attribute * 4 + 4)
#parameters are located at positive offset from frame pointer register
elif sym.kind == SharedData.KINDS.PARAMETER:
- return "{0}(%14)".format(8 + sym.attribute * 4)
+ return "{}(%14)".format(8 + sym.attribute * 4)
elif sym.kind == SharedData.KINDS.CONSTANT:
- return "${0}".format(sym.name)
+ return "${}".format(sym.name)
else:
- return "{0}".format(sym.name)
+ return "{}".format(sym.name)
def save_used_registers(self):
"""Pushes all used working registers before function call"""
@@ -674,7 +674,7 @@ class CodeGenerator(object):
internal - boolean value, adds "@" prefix to label
definition - boolean value, adds ":" suffix to label
"""
- self.newline_text(self.label("{0}{1}{2}".format("@" if internal else "", name, ":" if definition else "")))
+ self.newline_text(self.label("{}{}{}".format("@" if internal else "", name, ":" if definition else "")))
def global_var(self, name):
"""Inserts a new static (global) variable definition"""
@@ -704,7 +704,7 @@ class CodeGenerator(object):
#if operand3 is not defined, reserve one free register for it
output = self.take_register(output_type) if operand3 == None else operand3
mnemonic = self.arithmetic_mnemonic(operation, output_type)
- self.newline_text("{0}\t{1},{2},{3}".format(mnemonic, self.symbol(operand1), self.symbol(operand2), self.symbol(output)), True)
+ self.newline_text("{}\t{},{},{}".format(mnemonic, self.symbol(operand1), self.symbol(operand2), self.symbol(output)), True)
return output
def relop_code(self, relop, operands_type):
@@ -723,13 +723,13 @@ class CodeGenerator(object):
label - jump label
"""
jump = self.OPPOSITE_JUMPS[relcode] if opposite else self.CONDITIONAL_JUMPS[relcode]
- self.newline_text("{0}\t{1}".format(jump, label), True)
+ self.newline_text("{}\t{}".format(jump, label), True)
def unconditional_jump(self, label):
"""Generates an unconditional jump instruction
label - jump label
"""
- self.newline_text("JMP \t{0}".format(label), True)
+ self.newline_text("JMP \t{}".format(label), True)
def move(self,operand1, operand2):
"""Generates a move instruction
@@ -741,7 +741,7 @@ class CodeGenerator(object):
self.free_if_register(operand1)
else:
output_type = SharedData.TYPES.NO_TYPE
- self.newline_text("MOV \t{0},{1}".format(self.symbol(operand1), self.symbol(operand2)), True)
+ self.newline_text("MOV \t{},{}".format(self.symbol(operand1), self.symbol(operand2)), True)
if isinstance(operand2, int):
if self.symtab.get_kind(operand2) == SharedData.KINDS.WORKING_REGISTER:
self.symtab.set_type(operand2, output_type)
@@ -761,7 +761,7 @@ class CodeGenerator(object):
typ = self.symtab.get_type(operand1)
self.free_if_register(operand1)
self.free_if_register(operand2)
- self.newline_text("CMP{0}\t{1},{2}".format(self.OPSIGNS[typ], self.symbol(operand1), self.symbol(operand2)), True)
+ self.newline_text("CMP{}\t{},{}".format(self.OPSIGNS[typ], self.symbol(operand1), self.symbol(operand2)), True)
def function_begin(self):
"""Inserts function name label and function frame initialization"""
@@ -772,7 +772,7 @@ class CodeGenerator(object):
def function_body(self):
"""Inserts a local variable initialization and body label"""
if self.shared.function_vars > 0:
- const = self.symtab.insert_constant("{0}".format(self.shared.function_vars * 4), SharedData.TYPES.UNSIGNED)
+ const = self.symtab.insert_constant("{}".format(self.shared.function_vars * 4), SharedData.TYPES.UNSIGNED)
self.arithmetic("-", "%15", const, "%15")
self.newline_label(self.shared.function_name + "_body", True, True)
@@ -796,7 +796,7 @@ class CodeGenerator(object):
args = self.symtab.get_attribute(function)
#generates stack cleanup if function has arguments
if args > 0:
- args_space = self.symtab.insert_constant("{0}".format(args * 4), SharedData.TYPES.UNSIGNED)
+ args_space = self.symtab.insert_constant("{}".format(args * 4), SharedData.TYPES.UNSIGNED)
self.arithmetic("+", "%15", args_space, "%15")
##########################################################################################
@@ -1148,7 +1148,7 @@ class MicroC(object):
if DEBUG > 2: return
exshared.setpos(loc, text)
if not self.symtab.same_types(arg[0], arg[2]):
- raise SemanticException("Invalid operands for operator '{0}'".format(arg[1]))
+ raise SemanticException("Invalid operands for operator '{}'".format(arg[1]))
self.codegen.compare(arg[0], arg[2])
#return relational operator's code
self.relexp_code = self.codegen.relop_code(arg[1], self.symtab.get_type(arg[0]))
@@ -1161,7 +1161,7 @@ class MicroC(object):
print("AND+EXP:",arg)
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
- label = self.codegen.label("false{0}".format(self.false_label_number), True, False)
+ label = self.codegen.label("false{}".format(self.false_label_number), True, False)
self.codegen.jump(self.relexp_code, True, label)
self.andexp_code = self.relexp_code
return self.andexp_code
@@ -1173,9 +1173,9 @@ class MicroC(object):
print("LOG_EXP:",arg)
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
- label = self.codegen.label("true{0}".format(self.label_number), True, False)
+ label = self.codegen.label("true{}".format(self.label_number), True, False)
self.codegen.jump(self.relexp_code, False, label)
- self.codegen.newline_label("false{0}".format(self.false_label_number), True, True)
+ self.codegen.newline_label("false{}".format(self.false_label_number), True, True)
self.false_label_number += 1
def if_begin_action(self, text, loc, arg):
@@ -1187,7 +1187,7 @@ class MicroC(object):
if DEBUG > 2: return
self.false_label_number += 1
self.label_number = self.false_label_number
- self.codegen.newline_label("if{0}".format(self.label_number), True, True)
+ self.codegen.newline_label("if{}".format(self.label_number), True, True)
def if_body_action(self, text, loc, arg):
"""Code executed after recognising if statement's body"""
@@ -1197,10 +1197,10 @@ class MicroC(object):
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
#generate conditional jump (based on last compare)
- label = self.codegen.label("false{0}".format(self.false_label_number), True, False)
+ label = self.codegen.label("false{}".format(self.false_label_number), True, False)
self.codegen.jump(self.relexp_code, True, label)
#generate 'true' label (executes if condition is satisfied)
- self.codegen.newline_label("true{0}".format(self.label_number), True, True)
+ self.codegen.newline_label("true{}".format(self.label_number), True, True)
#save label numbers (needed for nested if/while statements)
self.label_stack.append(self.false_label_number)
self.label_stack.append(self.label_number)
@@ -1214,10 +1214,10 @@ class MicroC(object):
if DEBUG > 2: return
#jump to exit after all statements for true condition are executed
self.label_number = self.label_stack.pop()
- label = self.codegen.label("exit{0}".format(self.label_number), True, False)
+ label = self.codegen.label("exit{}".format(self.label_number), True, False)
self.codegen.unconditional_jump(label)
#generate final 'false' label (executes if condition isn't satisfied)
- self.codegen.newline_label("false{0}".format(self.label_stack.pop()), True, True)
+ self.codegen.newline_label("false{}".format(self.label_stack.pop()), True, True)
self.label_stack.append(self.label_number)
def if_end_action(self, text, loc, arg):
@@ -1227,7 +1227,7 @@ class MicroC(object):
print("IF_END:",arg)
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
- self.codegen.newline_label("exit{0}".format(self.label_stack.pop()), True, True)
+ self.codegen.newline_label("exit{}".format(self.label_stack.pop()), True, True)
def while_begin_action(self, text, loc, arg):
"""Code executed after recognising a while statement (while keyword)"""
@@ -1238,7 +1238,7 @@ class MicroC(object):
if DEBUG > 2: return
self.false_label_number += 1
self.label_number = self.false_label_number
- self.codegen.newline_label("while{0}".format(self.label_number), True, True)
+ self.codegen.newline_label("while{}".format(self.label_number), True, True)
def while_body_action(self, text, loc, arg):
"""Code executed after recognising while statement's body"""
@@ -1248,10 +1248,10 @@ class MicroC(object):
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
#generate conditional jump (based on last compare)
- label = self.codegen.label("false{0}".format(self.false_label_number), True, False)
+ label = self.codegen.label("false{}".format(self.false_label_number), True, False)
self.codegen.jump(self.relexp_code, True, label)
#generate 'true' label (executes if condition is satisfied)
- self.codegen.newline_label("true{0}".format(self.label_number), True, True)
+ self.codegen.newline_label("true{}".format(self.label_number), True, True)
self.label_stack.append(self.false_label_number)
self.label_stack.append(self.label_number)
@@ -1264,11 +1264,11 @@ class MicroC(object):
if DEBUG > 2: return
#jump to condition checking after while statement body
self.label_number = self.label_stack.pop()
- label = self.codegen.label("while{0}".format(self.label_number), True, False)
+ label = self.codegen.label("while{}".format(self.label_number), True, False)
self.codegen.unconditional_jump(label)
#generate final 'false' label and exit label
- self.codegen.newline_label("false{0}".format(self.label_stack.pop()), True, True)
- self.codegen.newline_label("exit{0}".format(self.label_number), True, True)
+ self.codegen.newline_label("false{}".format(self.label_stack.pop()), True, True)
+ self.codegen.newline_label("exit{}".format(self.label_number), True, True)
def program_end_action(self, text, loc, arg):
"""Checks if there is a 'main' function and the type of 'main' function"""
@@ -1320,7 +1320,7 @@ if 0:
input_file = argv[1]
output_file = argv[2]
else:
- usage = """Usage: {0} [input_file [output_file]]
+ usage = """Usage: {} [input_file [output_file]]
If output file is omitted, output.asm is used
If input file is omitted, stdin is used""".format(argv[0])
print(usage)
diff --git a/examples/pythonGrammarParser.py b/examples/pythonGrammarParser.py
index f199917..706f758 100644
--- a/examples/pythonGrammarParser.py
+++ b/examples/pythonGrammarParser.py
@@ -137,7 +137,7 @@ class SemanticGroup(object):
self.contents = self.contents[:-1] + self.contents[-1].contents
def __str__(self):
- return "%s(%s)" % (self.label,
+ return "{}({})".format(self.label,
" ".join([isinstance(c,str) and c or str(c) for c in self.contents]) )
class OrList(SemanticGroup):
@@ -164,7 +164,7 @@ class Atom(SemanticGroup):
self.contents = contents[0]
def __str__(self):
- return "%s%s" % (self.rep, self.contents)
+ return "{}{}".format(self.rep, self.contents)
def makeGroupObject(cls):
def groupAction(s,l,t):
diff --git a/examples/rangeCheck.py b/examples/rangeCheck.py
index 67cf267..b89a1e3 100644
--- a/examples/rangeCheck.py
+++ b/examples/rangeCheck.py
@@ -26,7 +26,7 @@ def ranged_value(expr, minval=None, maxval=None):
outOfRangeMessage = {
(True, False) : "value is greater than %s" % maxval,
(False, True) : "value is less than %s" % minval,
- (False, False) : "value is not in the range (%s to %s)" % (minval,maxval),
+ (False, False) : "value is not in the range ({} to {})".format(minval,maxval),
}[minval is None, maxval is None]
return expr().addCondition(inRangeCondition, message=outOfRangeMessage)
diff --git a/examples/searchParserAppDemo.py b/examples/searchParserAppDemo.py
index 259e0e3..0532c1c 100644
--- a/examples/searchParserAppDemo.py
+++ b/examples/searchParserAppDemo.py
@@ -6,10 +6,10 @@ products = [ "grape juice", "grape jelly", "orange juice", "orange jujubees",
class FruitSearchParser(SearchQueryParser):
def GetWord(self, word):
- return set( p for p in products if p.startswith(word + " ") )
+ return { p for p in products if p.startswith(word + " ") }
def GetWordWildcard(self, word):
- return set( p for p in products if p.startswith(word[:-1]) )
+ return { p for p in products if p.startswith(word[:-1]) }
def GetQuotes(self, search_string, tmp_result):
result = Set()
diff --git a/examples/searchparser.py b/examples/searchparser.py
index e5b40a7..36e3cd7 100644
--- a/examples/searchparser.py
+++ b/examples/searchparser.py
@@ -184,40 +184,40 @@ class ParserTest(SearchQueryParser):
tests containts a dictionary with tests and expected results.
"""
tests = {
- 'help': set([1, 2, 4, 5]),
- 'help or hulp': set([1, 2, 3, 4, 5]),
- 'help and hulp': set([2]),
- 'help hulp': set([2]),
- 'help and hulp or hilp': set([2, 3, 4]),
- 'help or hulp and hilp': set([1, 2, 3, 4, 5]),
- 'help or hulp or hilp or halp': set([1, 2, 3, 4, 5, 6]),
- '(help or hulp) and (hilp or halp)': set([3, 4, 5]),
- 'help and (hilp or halp)': set([4, 5]),
- '(help and (hilp or halp)) or hulp': set([2, 3, 4, 5]),
- 'not help': set([3, 6, 7, 8]),
- 'not hulp and halp': set([5, 6]),
- 'not (help and halp)': set([1, 2, 3, 4, 6, 7, 8]),
- '"help me please"': set([2]),
- '"help me please" or hulp': set([2, 3]),
- '"help me please" or (hulp and halp)': set([2]),
- 'help*': set([1, 2, 4, 5, 8]),
- 'help or hulp*': set([1, 2, 3, 4, 5]),
- 'help* and hulp': set([2]),
- 'help and hulp* or hilp': set([2, 3, 4]),
- 'help* or hulp or hilp or halp': set([1, 2, 3, 4, 5, 6, 8]),
- '(help or hulp*) and (hilp* or halp)': set([3, 4, 5]),
- 'help* and (hilp* or halp*)': set([4, 5]),
- '(help and (hilp* or halp)) or hulp*': set([2, 3, 4, 5]),
- 'not help* and halp': set([6]),
- 'not (help* and helpe*)': set([1, 2, 3, 4, 5, 6, 7]),
- '"help* me please"': set([2]),
- '"help* me* please" or hulp*': set([2, 3]),
- '"help me please*" or (hulp and halp)': set([2]),
- '"help me please" not (hulp and halp)': set([2]),
- '"help me please" hulp': set([2]),
- 'help and hilp and not holp': set([4]),
- 'help hilp not holp': set([4]),
- 'help hilp and not holp': set([4]),
+ 'help': {1, 2, 4, 5},
+ 'help or hulp': {1, 2, 3, 4, 5},
+ 'help and hulp': {2},
+ 'help hulp': {2},
+ 'help and hulp or hilp': {2, 3, 4},
+ 'help or hulp and hilp': {1, 2, 3, 4, 5},
+ 'help or hulp or hilp or halp': {1, 2, 3, 4, 5, 6},
+ '(help or hulp) and (hilp or halp)': {3, 4, 5},
+ 'help and (hilp or halp)': {4, 5},
+ '(help and (hilp or halp)) or hulp': {2, 3, 4, 5},
+ 'not help': {3, 6, 7, 8},
+ 'not hulp and halp': {5, 6},
+ 'not (help and halp)': {1, 2, 3, 4, 6, 7, 8},
+ '"help me please"': {2},
+ '"help me please" or hulp': {2, 3},
+ '"help me please" or (hulp and halp)': {2},
+ 'help*': {1, 2, 4, 5, 8},
+ 'help or hulp*': {1, 2, 3, 4, 5},
+ 'help* and hulp': {2},
+ 'help and hulp* or hilp': {2, 3, 4},
+ 'help* or hulp or hilp or halp': {1, 2, 3, 4, 5, 6, 8},
+ '(help or hulp*) and (hilp* or halp)': {3, 4, 5},
+ 'help* and (hilp* or halp*)': {4, 5},
+ '(help and (hilp* or halp)) or hulp*': {2, 3, 4, 5},
+ 'not help* and halp': {6},
+ 'not (help* and helpe*)': {1, 2, 3, 4, 5, 6, 7},
+ '"help* me please"': {2},
+ '"help* me* please" or hulp*': {2, 3},
+ '"help me please*" or (hulp and halp)': {2},
+ '"help me please" not (hulp and halp)': {2},
+ '"help me please" hulp': {2},
+ 'help and hilp and not holp': {4},
+ 'help hilp not holp': {4},
+ 'help hilp and not holp': {4},
}
docs = {
@@ -232,17 +232,17 @@ class ParserTest(SearchQueryParser):
}
index = {
- 'help': set((1, 2, 4, 5)),
- 'me': set((2,)),
- 'please': set((2,)),
- 'hulp': set((2, 3,)),
- 'hilp': set((3, 4,)),
- 'halp': set((5, 6,)),
- 'thinks': set((5,)),
- 'he': set((5, 6,)),
- 'needs': set((5, 6,)),
- 'nothing': set((7,)),
- 'helper': set((8,)),
+ 'help': {1, 2, 4, 5},
+ 'me': {2},
+ 'please': {2},
+ 'hulp': {2, 3},
+ 'hilp': {3, 4},
+ 'halp': {5, 6},
+ 'thinks': {5},
+ 'he': {5, 6},
+ 'needs': {5, 6},
+ 'nothing': {7},
+ 'helper': {8},
}
def GetWord(self, word):
diff --git a/examples/shapes.py b/examples/shapes.py
index b5a0ebd..c5f4867 100644
--- a/examples/shapes.py
+++ b/examples/shapes.py
@@ -15,7 +15,7 @@ class Shape(object):
raise NotImplementedException()
def __str__(self):
- return "<%s>: %s" % (self.__class__.__name__, self.__dict__)
+ return "<{}>: {}".format(self.__class__.__name__, self.__dict__)
class Square(Shape):
def area(self):
diff --git a/examples/simpleWiki.py b/examples/simpleWiki.py
index 7a2a0ce..1813432 100644
--- a/examples/simpleWiki.py
+++ b/examples/simpleWiki.py
@@ -21,7 +21,7 @@ def convertToHTML_A(s,l,t):
text,url=t[0].split("->")
except ValueError:
raise ParseFatalException(s,l,"invalid URL link reference: " + t[0])
- return '<A href="%s">%s</A>' % (url,text)
+ return '<A href="{}">{}</A>'.format(url,text)
urlRef = QuotedString("{{",endQuoteChar="}}").setParseAction(convertToHTML_A)
diff --git a/examples/sparser.py b/examples/sparser.py
index 7c416da..c3c3da0 100644
--- a/examples/sparser.py
+++ b/examples/sparser.py
@@ -79,12 +79,12 @@ def msg(txt):
def debug(ftn, txt):
"""Used for debugging."""
if debug_p:
- sys.stdout.write("%s.%s:%s\n" % (modname, ftn, txt))
+ sys.stdout.write("{}.{}:{}\n".format(modname, ftn, txt))
sys.stdout.flush()
def fatal(ftn, txt):
"""If can't continue."""
- msg = "%s.%s:FATAL:%s\n" % (modname, ftn, txt)
+ msg = "{}.{}:FATAL:{}\n".format(modname, ftn, txt)
raise SystemExit(msg)
def usage():
diff --git a/examples/stateMachine2.py b/examples/stateMachine2.py
index eb6633d..748bb8b 100644
--- a/examples/stateMachine2.py
+++ b/examples/stateMachine2.py
@@ -66,10 +66,10 @@ def expand_state_definition(source, loc, tokens):
# define all state classes
statedef.extend(
- "class %s(%s): pass" % (s,baseStateClass)
+ "class {}({}): pass".format(s,baseStateClass)
for s in states )
statedef.extend(
- "%s._next_state_class = %s" % (s,fromTo[s])
+ "{}._next_state_class = {}".format(s,fromTo[s])
for s in states if s in fromTo )
return indent + ("\n"+indent).join(statedef)+"\n"
@@ -107,9 +107,9 @@ def expand_named_state_definition(source,loc,tokens):
" return self.transitionName",
])
statedef.extend(
- "%s = %sTransition()" % (tn,baseStateClass)
+ "{} = {}Transition()".format(tn,baseStateClass)
for tn in transitions)
- statedef.extend("%s.transitionName = '%s'" % (tn,tn)
+ statedef.extend("{}.transitionName = '{}'".format(tn,tn)
for tn in transitions)
# define base class for state classes
@@ -197,7 +197,7 @@ class SuffixImporter(object):
# it probably isn't even a filesystem path
if sys.path_importer_cache.get(dirpath,False) is None:
checkpath = os.path.join(
- dirpath,'%s.%s' % (fullname,self.suffix))
+ dirpath,'{}.{}'.format(fullname,self.suffix))
yield checkpath
def find_module(self, fullname, path=None):
diff --git a/examples/urlExtractor.py b/examples/urlExtractor.py
index 2c66d78..10783de 100644
--- a/examples/urlExtractor.py
+++ b/examples/urlExtractor.py
@@ -26,7 +26,7 @@ for toks,strt,end in link.scanString(htmlText):
# Create dictionary from list comprehension, assembled from each pair of tokens returned
# from a matched URL.
pprint.pprint(
- dict((toks.body, toks.href) for toks,strt,end in link.scanString(htmlText))
+ {toks.body: toks.href for toks,strt,end in link.scanString(htmlText)}
)
diff --git a/examples/urlExtractorNew.py b/examples/urlExtractorNew.py
index 0aac875..7d6a1b5 100644
--- a/examples/urlExtractorNew.py
+++ b/examples/urlExtractorNew.py
@@ -28,7 +28,7 @@ for toks,strt,end in link.scanString(htmlText):
# Create dictionary from list comprehension, assembled from each pair of tokens returned
# from a matched URL.
pprint.pprint(
- dict( [ (toks.body,toks.startA.href) for toks,strt,end in link.scanString(htmlText) ] )
+ { toks.body:toks.startA.href for toks,strt,end in link.scanString(htmlText) }
)