mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Replaced unnecessary lists with generators
This commit is contained in:
parent
25f12b0e5d
commit
b1dc418a53
@ -347,7 +347,7 @@ class ConnectionView(WWrap):
|
|||||||
return self.master._cached_conn_text(
|
return self.master._cached_conn_text(
|
||||||
e,
|
e,
|
||||||
conn.content,
|
conn.content,
|
||||||
tuple([tuple(i) for i in conn.headers.lst]),
|
tuple(tuple(i) for i in conn.headers.lst),
|
||||||
viewmode
|
viewmode
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -1542,7 +1542,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
mkup.append(",")
|
mkup.append(",")
|
||||||
prompt.extend(mkup)
|
prompt.extend(mkup)
|
||||||
prompt.append(")? ")
|
prompt.append(")? ")
|
||||||
self.onekey = "".join([i[1] for i in keys])
|
self.onekey = "".join(i[1] for i in keys)
|
||||||
self.prompt(prompt, "", callback, *args)
|
self.prompt(prompt, "", callback, *args)
|
||||||
|
|
||||||
def prompt_done(self):
|
def prompt_done(self):
|
||||||
|
@ -137,7 +137,7 @@ else:
|
|||||||
|
|
||||||
if not _PY3K:
|
if not _PY3K:
|
||||||
def _str2dict(strg):
|
def _str2dict(strg):
|
||||||
return dict( [(c,0) for c in strg] )
|
return dict((c,0) for c in strg)
|
||||||
else:
|
else:
|
||||||
_str2dict = set
|
_str2dict = set
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ nums = string.digits
|
|||||||
hexnums = nums + "ABCDEFabcdef"
|
hexnums = nums + "ABCDEFabcdef"
|
||||||
alphanums = alphas + nums
|
alphanums = alphas + nums
|
||||||
_bslash = chr(92)
|
_bslash = chr(92)
|
||||||
printables = "".join( [ c for c in string.printable if c not in string.whitespace ] )
|
printables = "".join(c for c in string.printable if c not in string.whitespace)
|
||||||
|
|
||||||
class ParseBaseException(Exception):
|
class ParseBaseException(Exception):
|
||||||
"""base exception class for all parsing runtime exceptions"""
|
"""base exception class for all parsing runtime exceptions"""
|
||||||
@ -205,8 +205,8 @@ class ParseBaseException(Exception):
|
|||||||
line_str = self.line
|
line_str = self.line
|
||||||
line_column = self.column - 1
|
line_column = self.column - 1
|
||||||
if markerString:
|
if markerString:
|
||||||
line_str = "".join( [line_str[:line_column],
|
line_str = "".join(line_str[:line_column],
|
||||||
markerString, line_str[line_column:]])
|
markerString, line_str[line_column:])
|
||||||
return line_str.strip()
|
return line_str.strip()
|
||||||
def __dir__(self):
|
def __dir__(self):
|
||||||
return "loc msg pstr parserElement lineno col line " \
|
return "loc msg pstr parserElement lineno col line " \
|
||||||
@ -488,8 +488,8 @@ class ParseResults(object):
|
|||||||
"""Returns the parse results as XML. Tags are created for tokens and lists that have defined results names."""
|
"""Returns the parse results as XML. Tags are created for tokens and lists that have defined results names."""
|
||||||
nl = "\n"
|
nl = "\n"
|
||||||
out = []
|
out = []
|
||||||
namedItems = dict( [ (v[1],k) for (k,vlist) in self.__tokdict.items()
|
namedItems = dict((v[1],k) for (k,vlist) in self.__tokdict.items()
|
||||||
for v in vlist ] )
|
for v in vlist)
|
||||||
nextLevelIndent = indent + " "
|
nextLevelIndent = indent + " "
|
||||||
|
|
||||||
# collapse out indents if formatting is not desired
|
# collapse out indents if formatting is not desired
|
||||||
@ -1848,9 +1848,9 @@ class QuotedString(Token):
|
|||||||
(escChar is not None and _escapeRegexRangeChars(escChar) or '') )
|
(escChar is not None and _escapeRegexRangeChars(escChar) or '') )
|
||||||
if len(self.endQuoteChar) > 1:
|
if len(self.endQuoteChar) > 1:
|
||||||
self.pattern += (
|
self.pattern += (
|
||||||
'|(?:' + ')|(?:'.join(["%s[^%s]" % (re.escape(self.endQuoteChar[:i]),
|
'|(?:' + ')|(?:'.join("%s[^%s]" % (re.escape(self.endQuoteChar[:i]),
|
||||||
_escapeRegexRangeChars(self.endQuoteChar[i]))
|
_escapeRegexRangeChars(self.endQuoteChar[i]))
|
||||||
for i in range(len(self.endQuoteChar)-1,0,-1)]) + ')'
|
for i in range(len(self.endQuoteChar)-1,0,-1)) + ')'
|
||||||
)
|
)
|
||||||
if escQuote:
|
if escQuote:
|
||||||
self.pattern += (r'|(?:%s)' % re.escape(escQuote))
|
self.pattern += (r'|(?:%s)' % re.escape(escQuote))
|
||||||
@ -1999,9 +1999,9 @@ class White(Token):
|
|||||||
def __init__(self, ws=" \t\r\n", min=1, max=0, exact=0):
|
def __init__(self, ws=" \t\r\n", min=1, max=0, exact=0):
|
||||||
super(White,self).__init__()
|
super(White,self).__init__()
|
||||||
self.matchWhite = ws
|
self.matchWhite = ws
|
||||||
self.setWhitespaceChars( "".join([c for c in self.whiteChars if c not in self.matchWhite]) )
|
self.setWhitespaceChars( "".join(c for c in self.whiteChars if c not in self.matchWhite) )
|
||||||
#~ self.leaveWhitespace()
|
#~ self.leaveWhitespace()
|
||||||
self.name = ("".join([White.whiteStrs[c] for c in self.matchWhite]))
|
self.name = ("".join(White.whiteStrs[c] for c in self.matchWhite))
|
||||||
self.mayReturnEmpty = True
|
self.mayReturnEmpty = True
|
||||||
self.errmsg = "Expected " + self.name
|
self.errmsg = "Expected " + self.name
|
||||||
#self.myException.msg = self.errmsg
|
#self.myException.msg = self.errmsg
|
||||||
@ -2371,7 +2371,7 @@ class And(ParseExpression):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
if self.strRepr is None:
|
if self.strRepr is None:
|
||||||
self.strRepr = "{" + " ".join( [ _ustr(e) for e in self.exprs ] ) + "}"
|
self.strRepr = "{" + " ".join(_ustr(e) for e in self.exprs) + "}"
|
||||||
|
|
||||||
return self.strRepr
|
return self.strRepr
|
||||||
|
|
||||||
@ -2427,7 +2427,7 @@ class Or(ParseExpression):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
if self.strRepr is None:
|
if self.strRepr is None:
|
||||||
self.strRepr = "{" + " ^ ".join( [ _ustr(e) for e in self.exprs ] ) + "}"
|
self.strRepr = "{" + " ^ ".join(_ustr(e) for e in self.exprs) + "}"
|
||||||
|
|
||||||
return self.strRepr
|
return self.strRepr
|
||||||
|
|
||||||
@ -2486,7 +2486,7 @@ class MatchFirst(ParseExpression):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
if self.strRepr is None:
|
if self.strRepr is None:
|
||||||
self.strRepr = "{" + " | ".join( [ _ustr(e) for e in self.exprs ] ) + "}"
|
self.strRepr = "{" + " | ".join(_ustr(e) for e in self.exprs) + "}"
|
||||||
|
|
||||||
return self.strRepr
|
return self.strRepr
|
||||||
|
|
||||||
@ -2543,7 +2543,7 @@ class Each(ParseExpression):
|
|||||||
keepMatching = False
|
keepMatching = False
|
||||||
|
|
||||||
if tmpReqd:
|
if tmpReqd:
|
||||||
missing = ", ".join( [ _ustr(e) for e in tmpReqd ] )
|
missing = ", ".join(_ustr(e) for e in tmpReqd)
|
||||||
raise ParseException(instring,loc,"Missing one or more required elements (%s)" % missing )
|
raise ParseException(instring,loc,"Missing one or more required elements (%s)" % missing )
|
||||||
|
|
||||||
# add any unmatched Optionals, in case they have default values defined
|
# add any unmatched Optionals, in case they have default values defined
|
||||||
@ -2572,7 +2572,7 @@ class Each(ParseExpression):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
if self.strRepr is None:
|
if self.strRepr is None:
|
||||||
self.strRepr = "{" + " & ".join( [ _ustr(e) for e in self.exprs ] ) + "}"
|
self.strRepr = "{" + " & ".join(_ustr(e) for e in self.exprs) + "}"
|
||||||
|
|
||||||
return self.strRepr
|
return self.strRepr
|
||||||
|
|
||||||
@ -3242,9 +3242,9 @@ def oneOf( strs, caseless=False, useRegex=True ):
|
|||||||
#~ print (strs,"->", "|".join( [ _escapeRegexChars(sym) for sym in symbols] ))
|
#~ print (strs,"->", "|".join( [ _escapeRegexChars(sym) for sym in symbols] ))
|
||||||
try:
|
try:
|
||||||
if len(symbols)==len("".join(symbols)):
|
if len(symbols)==len("".join(symbols)):
|
||||||
return Regex( "[%s]" % "".join( [ _escapeRegexRangeChars(sym) for sym in symbols] ) )
|
return Regex( "[%s]" % "".join(_escapeRegexRangeChars(sym) for sym in symbols) )
|
||||||
else:
|
else:
|
||||||
return Regex( "|".join( [ re.escape(sym) for sym in symbols] ) )
|
return Regex( "|".join(re.escape(sym) for sym in symbols) )
|
||||||
except:
|
except:
|
||||||
warnings.warn("Exception creating Regex for oneOf, building MatchFirst",
|
warnings.warn("Exception creating Regex for oneOf, building MatchFirst",
|
||||||
SyntaxWarning, stacklevel=2)
|
SyntaxWarning, stacklevel=2)
|
||||||
@ -3298,14 +3298,14 @@ stringStart = StringStart().setName("stringStart")
|
|||||||
stringEnd = StringEnd().setName("stringEnd")
|
stringEnd = StringEnd().setName("stringEnd")
|
||||||
|
|
||||||
_escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
|
_escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
|
||||||
_printables_less_backslash = "".join([ c for c in printables if c not in r"\]" ])
|
_printables_less_backslash = "".join(c for c in printables if c not in r"\]")
|
||||||
_escapedHexChar = Combine( Suppress(_bslash + "0x") + Word(hexnums) ).setParseAction(lambda s,l,t:unichr(int(t[0],16)))
|
_escapedHexChar = Combine( Suppress(_bslash + "0x") + Word(hexnums) ).setParseAction(lambda s,l,t:unichr(int(t[0],16)))
|
||||||
_escapedOctChar = Combine( Suppress(_bslash) + Word("0","01234567") ).setParseAction(lambda s,l,t:unichr(int(t[0],8)))
|
_escapedOctChar = Combine( Suppress(_bslash) + Word("0","01234567") ).setParseAction(lambda s,l,t:unichr(int(t[0],8)))
|
||||||
_singleChar = _escapedPunc | _escapedHexChar | _escapedOctChar | Word(_printables_less_backslash,exact=1)
|
_singleChar = _escapedPunc | _escapedHexChar | _escapedOctChar | Word(_printables_less_backslash,exact=1)
|
||||||
_charRange = Group(_singleChar + Suppress("-") + _singleChar)
|
_charRange = Group(_singleChar + Suppress("-") + _singleChar)
|
||||||
_reBracketExpr = Literal("[") + Optional("^").setResultsName("negate") + Group( OneOrMore( _charRange | _singleChar ) ).setResultsName("body") + "]"
|
_reBracketExpr = Literal("[") + Optional("^").setResultsName("negate") + Group( OneOrMore( _charRange | _singleChar ) ).setResultsName("body") + "]"
|
||||||
|
|
||||||
_expanded = lambda p: (isinstance(p,ParseResults) and ''.join([ unichr(c) for c in range(ord(p[0]),ord(p[1])+1) ]) or p)
|
_expanded = lambda p: (isinstance(p,ParseResults) and ''.join(unichr(c) for c in range(ord(p[0]),ord(p[1])+1)) or p)
|
||||||
|
|
||||||
def srange(s):
|
def srange(s):
|
||||||
r"""Helper to easily define string ranges for use in Word construction. Borrows
|
r"""Helper to easily define string ranges for use in Word construction. Borrows
|
||||||
@ -3324,7 +3324,7 @@ def srange(s):
|
|||||||
any combination of the above ('aeiouy', 'a-zA-Z0-9_$', etc.)
|
any combination of the above ('aeiouy', 'a-zA-Z0-9_$', etc.)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return "".join([_expanded(part) for part in _reBracketExpr.parseString(s).body])
|
return "".join(_expanded(part) for part in _reBracketExpr.parseString(s).body)
|
||||||
except:
|
except:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@ -3402,7 +3402,7 @@ def _makeTags(tagStr, xml):
|
|||||||
Dict(ZeroOrMore(Group( tagAttrName + Suppress("=") + tagAttrValue ))) + \
|
Dict(ZeroOrMore(Group( tagAttrName + Suppress("=") + tagAttrValue ))) + \
|
||||||
Optional("/",default=[False]).setResultsName("empty").setParseAction(lambda s,l,t:t[0]=='/') + Suppress(">")
|
Optional("/",default=[False]).setResultsName("empty").setParseAction(lambda s,l,t:t[0]=='/') + Suppress(">")
|
||||||
else:
|
else:
|
||||||
printablesLessRAbrack = "".join( [ c for c in printables if c not in ">" ] )
|
printablesLessRAbrack = "".join(c for c in printables if c not in ">")
|
||||||
tagAttrValue = quotedString.copy().setParseAction( removeQuotes ) | Word(printablesLessRAbrack)
|
tagAttrValue = quotedString.copy().setParseAction( removeQuotes ) | Word(printablesLessRAbrack)
|
||||||
openTag = Suppress("<") + tagStr + \
|
openTag = Suppress("<") + tagStr + \
|
||||||
Dict(ZeroOrMore(Group( tagAttrName.setParseAction(downcaseTokens) + \
|
Dict(ZeroOrMore(Group( tagAttrName.setParseAction(downcaseTokens) + \
|
||||||
@ -3656,7 +3656,7 @@ cppStyleComment = Regex(r"/(?:\*(?:[^*]*\*+)+?/|/[^\n]*(?:\n[^\n]*)*?(?:(?<!\\)|
|
|||||||
|
|
||||||
javaStyleComment = cppStyleComment
|
javaStyleComment = cppStyleComment
|
||||||
pythonStyleComment = Regex(r"#.*").setName("Python style comment")
|
pythonStyleComment = Regex(r"#.*").setName("Python style comment")
|
||||||
_noncomma = "".join( [ c for c in printables if c != "," ] )
|
_noncomma = "".join(c for c in printables if c != ",")
|
||||||
_commasepitem = Combine(OneOrMore(Word(_noncomma) +
|
_commasepitem = Combine(OneOrMore(Word(_noncomma) +
|
||||||
Optional( Word(" \t") +
|
Optional( Word(" \t") +
|
||||||
~Literal(",") + ~LineEnd() ) ) ).streamline().setName("commaItem")
|
~Literal(",") + ~LineEnd() ) ) ).streamline().setName("commaItem")
|
||||||
|
@ -222,7 +222,7 @@ class FAnd(_Token):
|
|||||||
i.dump(indent+1, fp)
|
i.dump(indent+1, fp)
|
||||||
|
|
||||||
def __call__(self, o):
|
def __call__(self, o):
|
||||||
return all([i(o) for i in self.lst])
|
return all(i(o) for i in self.lst)
|
||||||
|
|
||||||
|
|
||||||
class FOr(_Token):
|
class FOr(_Token):
|
||||||
@ -235,7 +235,7 @@ class FOr(_Token):
|
|||||||
i.dump(indent+1, fp)
|
i.dump(indent+1, fp)
|
||||||
|
|
||||||
def __call__(self, o):
|
def __call__(self, o):
|
||||||
return any([i(o) for i in self.lst])
|
return any(i(o) for i in self.lst)
|
||||||
|
|
||||||
|
|
||||||
class FNot(_Token):
|
class FNot(_Token):
|
||||||
@ -277,7 +277,7 @@ def _make():
|
|||||||
f.setParseAction(klass.make)
|
f.setParseAction(klass.make)
|
||||||
parts.append(f)
|
parts.append(f)
|
||||||
|
|
||||||
simplerex = "".join([c for c in pp.printables if c not in "()~'\""])
|
simplerex = "".join(c for c in pp.printables if c not in "()~'\"")
|
||||||
rex = pp.Word(simplerex) |\
|
rex = pp.Word(simplerex) |\
|
||||||
pp.QuotedString("\"", escChar='\\') |\
|
pp.QuotedString("\"", escChar='\\') |\
|
||||||
pp.QuotedString("'", escChar='\\')
|
pp.QuotedString("'", escChar='\\')
|
||||||
|
@ -234,9 +234,9 @@ class Request(HTTPMsg):
|
|||||||
decode appropriately.
|
decode appropriately.
|
||||||
"""
|
"""
|
||||||
if self.headers["accept-encoding"]:
|
if self.headers["accept-encoding"]:
|
||||||
self.headers["accept-encoding"] = [', '.join([
|
self.headers["accept-encoding"] = [', '.join(
|
||||||
e for e in encoding.ENCODINGS if e in self.headers["accept-encoding"][0]
|
e for e in encoding.ENCODINGS if e in self.headers["accept-encoding"][0]
|
||||||
])]
|
)]
|
||||||
|
|
||||||
def _set_replay(self):
|
def _set_replay(self):
|
||||||
self.client_conn = None
|
self.client_conn = None
|
||||||
@ -704,7 +704,7 @@ class ServerPlaybackState:
|
|||||||
l.append(i)
|
l.append(i)
|
||||||
|
|
||||||
def count(self):
|
def count(self):
|
||||||
return sum([len(i) for i in self.fmap.values()])
|
return sum(len(i) for i in self.fmap.values())
|
||||||
|
|
||||||
def _hash(self, flow):
|
def _hash(self, flow):
|
||||||
"""
|
"""
|
||||||
|
@ -135,10 +135,10 @@ def hexdump(s):
|
|||||||
for i in range(0, len(s), 16):
|
for i in range(0, len(s), 16):
|
||||||
o = "%.10x"%i
|
o = "%.10x"%i
|
||||||
part = s[i:i+16]
|
part = s[i:i+16]
|
||||||
x = " ".join(["%.2x"%ord(i) for i in part])
|
x = " ".join("%.2x"%ord(i) for i in part)
|
||||||
if len(part) < 16:
|
if len(part) < 16:
|
||||||
x += " "
|
x += " "
|
||||||
x += " ".join([" " for i in range(16-len(part))])
|
x += " ".join(" " for i in range(16 - len(part)))
|
||||||
parts.append(
|
parts.append(
|
||||||
(o, x, cleanBin(part))
|
(o, x, cleanBin(part))
|
||||||
)
|
)
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
IVERSION = (0, 6)
|
IVERSION = (0, 6)
|
||||||
VERSION = ".".join([str(i) for i in IVERSION])
|
VERSION = ".".join(str(i) for i in IVERSION)
|
||||||
|
Loading…
Reference in New Issue
Block a user