/usr/local/lib/python3.6/site-packages/pyparsing/__pycache__
NameSizeModeActions
actions.cpython-36.pyc71380644editdlrm
common.cpython-36.pyc178560644editdlrm
core.cpython-36.pyc1902840644editdlrm
exceptions.cpython-36.pyc97400644editdlrm
helpers.cpython-36.pyc342890644editdlrm
results.cpython-36.pyc254110644editdlrm
testing.cpython-36.pyc119860644editdlrm
unicode.cpython-36.pyc121800644editdlrm
util.cpython-36.pyc95180644editdlrm
__init__.cpython-36.pyc76350644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/pyparsing/__pycache__/results.cpython-36.pyc (25411B)
3 Eg\d@sUddlmZmZmZmZmZddlZddlmZm Z m Z m Z m Z ddl mZeefZeedfeddfDZGd d d ZGd d d ZejeejedS) )MutableMappingMappingMutableSequenceIteratorIterableN)TupleAnyDictSetList)replaced_by_pep8.ccs|] }|VqdS)N).0_rr;/usr/local/lib/python3.6/site-packages/pyparsing/results.py src@sHeZdZUedefdgZdedddZddZdd Z d d Z d S) _ParseResultsWithOffset ParseResultstup)p1p2cCs||f|_dS)N)r)selfrrrrr__init__sz _ParseResultsWithOffset.__init__cCs |j|S)N)r)rirrr __getitem__sz#_ParseResultsWithOffset.__getitem__cCs|jS)N)r)rrrr __getstate__sz$_ParseResultsWithOffset.__getstate__cGs|d|_dS)Nr)r)rargsrrr __setstate__ sz$_ParseResultsWithOffset.__setstate__N) __name__ __module__ __qualname__rintr __slots__rrrrrrrrrs  rc@s6eZdZUdZdgffZeedfed e e e  eeeeefd_ZGd d d eZd`d d ZddddefddZddZefddZddZe dddZedddZe dddZedddZedd d!Z d"d#Z!d$d%Z"d&d'Z#e dd(d)Z$d*d+Z%dad,d-Z&d.d/Z'd0d1Z(d2d3Z)d4d5Z*d6d7Z+ddd8d9d:Z,ddd8d;d<Z-ddd=d>Z.edd?d@Z/eddAdBZ0dbdDdEZ1eddFdGZ2e3ddHdIZ4dddJdKZ5dddLdMZ6eddNdOZ7dceddQdRZ8dSdTZ9dUdVZ:dWdXZ;dYdZZddddd]d^Z?e2Z@e4ZAe7ZBdS)era{Structured parse results, to provide multiple means of access to the parsed data: - as a list (``len(results)``) - by list index (``results[0], results[1]``, etc.) - by attribute (``results.`` - see :class:`ParserElement.set_results_name`) Example:: integer = Word(nums) date_str = (integer.set_results_name("year") + '/' + integer.set_results_name("month") + '/' + integer.set_results_name("day")) # equivalent form: # date_str = (integer("year") + '/' # + integer("month") + '/' # + integer("day")) # parse_string returns a ParseResults object result = date_str.parse_string("1999/12/31") def test(s, fn=repr): print(f"{s} -> {fn(eval(s))}") test("list(result)") test("result[0]") test("result['month']") test("result.day") test("'month' in result") test("'minutes' in result") test("result.dump()", str) prints:: list(result) -> ['1999', '/', '12', '/', '31'] result[0] -> '1999' result['month'] -> '12' result.day -> '31' 'month' in result -> True 'minutes' in result -> False result.dump() -> ['1999', '/', '12', '/', '31'] - day: '31' - month: '12' - year: '1999' N._name_parent _all_names_modal_toklist_tokdictc@seZdZdZdddZdS)zParseResults.Lista Simple wrapper class to distinguish parsed list results that should be preserved as actual Python lists, instead of being converted to :class:`ParseResults`:: LBRACK, RBRACK = map(pp.Suppress, "[]") element = pp.Forward() item = ppc.integer element_list = LBRACK + pp.DelimitedList(element) + RBRACK # add parse actions to convert from ParseResults to actual Python collection types def as_python_list(t): return pp.ParseResults.List(t.as_list()) element_list.add_parse_action(as_python_list) element <<= item | element_list element.run_tests(''' 100 [2,3,4] [[2, 1],3,4] [(2, 1),3,4] (2,3,4) ''', post_parse=lambda s, r: (r[0], type(r[0]))) prints:: 100 (100, ) [2,3,4] ([2, 3, 4], ) [[2, 1],3,4] ([[2, 1], 3, 4], ) (Used internally by :class:`Group` when `aslist=True`.) NcCs:|dkr g}t|ts0t|jdt|jtj|S)Nz* may only be constructed with a list, not ) isinstancelist TypeErrorrtype__new__)clsZ containedrrrr.s  zParseResults.List.__new__)N)rr r!__doc__r.rrrrr ds%r cKst|tr|Stj|}d|_d|_t|_|dkrsz,ParseResults.__getitem__..)r*r"slicer(r&r)r)rrrrrrs   zParseResults.__getitem__cCs||tr0|jj|t|g|j|<|d}nD||ttfrN||j|<|}n&|jj|tt|dg|j|<|}||tr||_dS)Nr) rr)getr+r"rCr(rr%)rkr@r*subrrr __setitem__s    zParseResults.__setitem__c Cst|ttfs|j|=dSt|j}|j|=t|trT|dkrF||7}t||d}tt|j|}|j xP|jj D]B}x<|D]4}x.t |D]"\}\}}t ||||k||<qWqWqzWdS)Nrr ) r*r"rCr)lenr(r+rangeindicesreversevalues enumerater) rrmylenremoved occurrencesjrEvaluepositionrrr __delitem__s    zParseResults.__delitem__)returncCs ||jkS)N)r))rrErrr __contains__szParseResults.__contains__cCs t|jS)N)rHr()rrrr__len__szParseResults.__len__cCs|jp |j S)N)r(r))rrrr__bool__ szParseResults.__bool__cCs t|jS)N)iterr()rrrr__iter__ szParseResults.__iter__cCst|jdddS)Nr rB)rYr()rrrr __reversed__szParseResults.__reversed__cCs t|jS)N)rYr))rrrrkeysszParseResults.keyscsfddjDS)Nc3s|]}|VqdS)Nr)rrE)rrrrsz&ParseResults.values..)r\)rr)rrrLszParseResults.valuescsfddjDS)Nc3s|]}||fVqdS)Nr)rrE)rrrrsz%ParseResults.items..)r\)rr)rritemsszParseResults.itemscCs |j S)z Since ``keys()`` returns an iterator, this method is helpful in bypassing code that looks for the existence of any defined results names.)r))rrrrhaskeysszParseResults.haskeyscOs|s dg}x8|jD],\}}|dkr2|d|f}qtd|qWt|dtsjt|dksj|d|kr|d}||}||=|S|d}|SdS)a Removes and returns item at specified index (default= ``last``). Supports both ``list`` and ``dict`` semantics for ``pop()``. If passed no argument or an integer argument, it will use ``list`` semantics and pop tokens from the list of parsed tokens. If passed a non-integer argument (most likely a string), it will use ``dict`` semantics and pop the corresponding value from any defined results names. A second default return value argument is supported, just as in ``dict.pop()``. Example:: numlist = Word(nums)[...] print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321'] def remove_first(tokens): tokens.pop(0) numlist.add_parse_action(remove_first) print(numlist.parse_string("0 123 321")) # -> ['123', '321'] label = Word(alphas) patt = label("LABEL") + Word(nums)[1, ...] print(patt.parse_string("AAB 123 321").dump()) # Use pop() in a parse action to remove named result (note that corresponding value is not # removed from list form of results) def remove_LABEL(tokens): tokens.pop("LABEL") return tokens patt.add_parse_action(remove_LABEL) print(patt.parse_string("AAB 123 321").dump()) prints:: ['AAB', '123', '321'] - LABEL: 'AAB' ['AAB', '123', '321'] r defaultrz)pop() got an unexpected keyword argument NrB)r]r,r*r"rH)rrr7rEr@indexret defaultvaluerrrpop"s(&zParseResults.popcCs||kr||S|SdS)a^ Returns named result matching the given key, or if there is no such name, then returns the given ``default_value`` or ``None`` if no ``default_value`` is specified. Similar to ``dict.get()``. Example:: integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") result = date_str.parse_string("1999/12/31") print(result.get("year")) # -> '1999' print(result.get("hour", "not specified")) # -> 'not specified' print(result.get("hour")) # -> None Nr)rkey default_valuerrrrDZszParseResults.getcCsV|jj||xB|jjD]4}x.t|D]"\}\}}t||||k||<q(WqWdS)a; Inserts new element at location index in the list of parsed tokens. Similar to ``list.insert()``. Example:: numlist = Word(nums)[...] print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321'] # use a parse action to insert the parse location in the front of the parsed results def insert_locn(locn, tokens): tokens.insert(0, locn) numlist.add_parse_action(insert_locn) print(numlist.parse_string("0 123 321")) # -> [0, '0', '123', '321'] N)r(insertr)rLrMr)rr`Z ins_stringrPrErRrSrrrrfqs zParseResults.insertcCs|jj|dS)a Add single element to end of ``ParseResults`` list of elements. Example:: numlist = Word(nums)[...] print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321'] # use a parse action to compute the sum of the parsed integers, and add it to the end def append_sum(tokens): tokens.append(sum(map(int, tokens))) numlist.add_parse_action(append_sum) print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321', 444] N)r(append)ritemrrrrgszParseResults.appendcCs&t|tr|j|n |jj|dS)a Add sequence of elements to end of ``ParseResults`` list of elements. Example:: patt = Word(alphas)[1, ...] # use a parse action to append the reverse of the matched strings, to make a palindrome def make_palindrome(tokens): tokens.extend(reversed([t[::-1] for t in tokens])) return ''.join(tokens) patt.add_parse_action(make_palindrome) print(patt.parse_string("lskdj sdlkjf lksd")) # -> 'lskdjsdlkjflksddsklfjkldsjdksl' N)r*r__iadd__r(extend)ritemseqrrrrjs  zParseResults.extendcCs|jdd=|jjdS)z7 Clear all elements and results names. N)r(r)clear)rrrrrls zParseResults.clearc Cs4y||Stk r.|jdr*t|dSXdS)N__r8)r< startswithAttributeError)rr6rrr __getattr__s  zParseResults.__getattr__)otherrUcCs|j}||7}|S)N)copy)rrqrarrr__add__szParseResults.__add__cs|s|S|jrrt|jfdd|jj}fdd|D}x0|D](\}}|||<t|dtrF||d_qFW|j|j7_|j|jO_|S)Ncs|dkr S|S)Nrr)a)offsetrrsz'ParseResults.__iadd__..c s4g|],\}}|D]}|t|d|dfqqS)rr )r)rrEvlistr@) addoffsetrrrAsz)ParseResults.__iadd__..r)r)rHr(r]r*rr%r&)rrq otheritemsotherdictitemsrEr@r)rxrurris    zParseResults.__iadd__cCs&t|tr|dkr|jS||SdS)Nr)r*r"rr)rrqrrr__radd__szParseResults.__radd__cCs"t|jd|jd|jdS)N(z, ))r-rr(as_dict)rrrr__repr__szParseResults.__repr__cCsddjdd|jDdS)N[z, cSs&g|]}t|trt|nt|qSr)r*rr9repr)rrrrrrAsz(ParseResults.__str__..])joinr()rrrr__str__s zParseResults.__str__r8cCsPg}xF|jD]<}|r"|r"|j|t|tr:||j7}q |jt|q W|S)N)r(rgr*r _asStringListr9)rsepoutrhrrrrs   zParseResults._asStringListcCsdd|jDS)ax Returns the parse results as a nested list of matching tokens, all converted to strings. Example:: patt = Word(alphas)[1, ...] result = patt.parse_string("sldkj lsdkj sldkj") # even though the result prints in string-like form, it is actually a pyparsing ParseResults print(type(result), result) # -> ['sldkj', 'lsdkj', 'sldkj'] # Use as_list() to create an actual list result_list = result.as_list() print(type(result_list), result_list) # -> ['sldkj', 'lsdkj', 'sldkj'] cSs"g|]}t|tr|jn|qSr)r*ras_list)rresrrrrA sz(ParseResults.as_list..)r()rrrrrszParseResults.as_listcs&fddtfdd|jDS)a Returns the named parse results as a nested dictionary. Example:: integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") result = date_str.parse_string('12/31/1999') print(type(result), repr(result)) # -> (['12', '/', '31', '/', '1999'], {'day': [('1999', 4)], 'year': [('12', 0)], 'month': [('31', 2)]}) result_dict = result.as_dict() print(type(result_dict), repr(result_dict)) # -> {'day': '1999', 'year': '12', 'month': '31'} # even though a ParseResults supports dict-like access, sometime you just need to have a dict import json print(json.dumps(result)) # -> Exception: TypeError: ... is not JSON serializable print(json.dumps(result.as_dict())) # -> {"month": "31", "day": "1999", "year": "12"} cs4t|tr,|jr|jSfdd|DS|SdS)Ncsg|] }|qSrr)rr@)to_itemrrrA&sz9ParseResults.as_dict..to_item..)r*rr^r~)obj)rrrr$s "z%ParseResults.as_dict..to_itemc3s|]\}}||fVqdS)Nr)rrEr@)rrrr*sz'ParseResults.as_dict..)r4r])rr)rrr~s zParseResults.as_dictcCs:t|j}|jj|_|j|_|j|jO_|j|_|S)a Returns a new shallow copy of a :class:`ParseResults` object. `ParseResults` items contained within the source are shared with the copy. Use :class:`ParseResults.deepcopy()` to create a copy with its own separate content values. )rr(r)rrr%r&r$)rrarrrrr,s   zParseResults.copycCs|j}xt|jD]\}}t|tr6|j|j|<qt|ttfrFqt|trt ||j|<}xV|j D]"\}}t|tr|jn|||<qnWqt|t rt |dd|D|j|<qW|S)zL Returns a new deep copy of a :class:`ParseResults` object. css$|]}t|tr|jn|VqdS)N)r*rdeepcopy)rr@rrrrKsz(ParseResults.deepcopy..) rrrMr(r*rrr9bytesrr-r]r)rrarrdestrEr@rrrr:s    zParseResults.deepcopycsjr jSjr:j}|jj}tfdd|DdStdkrtjdkrttjjdddkrttjjSdSdS)a Returns the results name for this token expression. Useful when several different expressions might match at a particular location. Example:: integer = Word(nums) ssn_expr = Regex(r"\d\d\d-\d\d-\d\d\d\d") house_number_expr = Suppress('#') + Word(nums, alphanums) user_data = (Group(house_number_expr)("house_number") | Group(ssn_expr)("ssn") | Group(integer)("age")) user_info = user_data[1, ...] result = user_info.parse_string("22 111-22-3333 #221B") for item in result: print(item.get_name(), ':', item[0]) prints:: age : 22 ssn : 111-22-3333 house_number : 221B c3s,|]$\}}|D]\}}|kr|VqqdS)Nr)rrErwr@loc)rrrros z(ParseResults.get_name..Nr rrB)rrB) r$r%r)r]nextrHrYrLr\)rparZparent_tokdict_itemsr)rrget_nameOs   zParseResults.get_namerc Csg}d}|j|r |t|jnd|s4dj|S|jrtdd|jD}x|D]~\}} |rn|j||j|d|d|dt| ts|jt | qX| s|jt| qX|j| j ||||dd qXWt d d|Dsdj|S|} d} d} xt | D]\} } t| trr| j ||||dd }|j| || |d | d | || |d| n:|j| || |d | d | || |d| q Wdj|S) aM Diagnostic method for listing out the contents of a :class:`ParseResults`. Accepts an optional ``indent`` argument so that this string can be embedded in a nested display of other data. Example:: integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") result = date_str.parse_string('1999/12/31') print(result.dump()) prints:: ['1999', '/', '12', '/', '31'] - day: '31' - month: '12' - year: '1999'  r8css|]\}}t||fVqdS)N)r9)rrEr@rrrrsz$ParseResults.dump..z z- z: r )indentfull include_list_depthcss|]}t|tVqdS)N)r*r)rvvrrrrsrz]:) rgr9rrr^sortedr]r*rrdumpanyrM)rrrrrrNLr]rEr@incrnlrrZvv_dumprrrrsP      8<zParseResults.dumpcOstj|jf||dS)a$ Pretty-printer for parsed results as a list, using the `pprint `_ module. Accepts additional positional or keyword args as defined for `pprint.pprint `_ . Example:: ident = Word(alphas, alphanums) num = Word(nums) func = Forward() term = ident | num | Group('(' + func + ')') func <<= ident + Group(Optional(DelimitedList(term))) result = func.parse_string("fna a,b,(fnb c,d,200),100") result.pprint(width=40) prints:: ['fna', ['a', 'b', ['(', 'fnb', ['c', 'd', '200'], ')'], '100']] N)pprintr)rrr7rrrrszParseResults.pprintcCs|j|jjd|j|jffS)N)r(r)rrr&r$)rrrrrs zParseResults.__getstate__cCs*|\|_\|_}}|_t||_d|_dS)N)r(r)r$r2r&r%)rstater inAccumNamesrrrrs zParseResults.__setstate__cCs |j|jfS)N)r(r$)rrrr__getnewargs__szParseResults.__getnewargs__cCstt|t|jS)N)dirr-r+r\)rrrr__dir__szParseResults.__dir__cCsvdd}|g}xJ|jD]>\}}t|tr@||j||d7}q|||g|||d7}qW|dk rr||g|d}|S)z Helper classmethod to construct a ``ParseResults`` from a ``dict``, preserving the name-value relations as results names. If an optional ``name`` argument is given, a nested ``ParseResults`` will be returned. c Ss2y t|Wntk r dSXt|t SdS)NF)rY Exceptionr*r;)rrrr is_iterables  z+ParseResults.from_dict..is_iterable)r6)r6r>N)r]r*r from_dict)r/rqr6rrarEr@rrrrs  zParseResults.from_dict)r$r%r&r'r(r))NN)N)r8)r8TTr)N)Crr r!r0r:rrr9r$r%r r&boolr'r r(r r)r#r+r.r*rrrGrTrVr"rWrXrrZr[r\rLr]r^rcrDrfrgrjrlrprsrir{rrrrr4r~rrrrrrrrrr classmethodrr>asDictgetNamerrrrr$sv , 2 & 8  0J r)collections.abcrrrrrrtypingrrr r r utilr r9rr;r-r3rrregisterrrrrs