Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

why this code giving recursion error????

17 views
Skip to first unread message

נתי שטרן

unread,
Jun 26, 2022, 6:49:15 AM6/26/22
to
def compile(p, flags=0):
# internal: convert pattern list to internal format

if (isinstance(p,str)):
pattern = p
p = sre_parse.parse(p, flags)
else:
pattern = None

code = _code(p, flags)

if flags & SRE_FLAG_DEBUG:
print()
dis(code)

# map in either direction
groupindex = p.state.groupdict
indexgroup = [None] * p.state.groups
for k, i in groupindex.items():
indexgroup[i] = k

return sre_compile.compile(
pattern, flags | p.state.flags, code,
p.state.groups-1,
groupindex, tuple(indexgroup)
)


--
<https://netanel.ml>

נתי שטרן

unread,
Jun 26, 2022, 6:50:45 AM6/26/22
to
stack trace:



File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 5387, in <module>
class bottle:
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 5694, in bottle
class Router(object):
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 5736, in Router
rule_syntax = re.compile('(\\\\*)'
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 375, in compile
return sre_compile.compile(pattern, flags)
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 2752, in compile
return sre_compile.compile(
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 2752, in compile
return sre_compile.compile(
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 2752, in compile
return sre_compile.compile(
[Previous line repeated 1005 more times]
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 2736, in compile
p = sre_parse.parse(p, flags)
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1822, in parse
p = sre_parse._parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1234, in _parse_sub
itemsappend(sre_parse._parse(source, state, verbose, nested + 1,
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1708, in _parse
p = sre_parse._parse_sub(source, state, sub_verbose, nested + 1)
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1234, in _parse_sub
itemsappend(sre_parse._parse(source, state, verbose, nested + 1,
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1708, in _parse
p = sre_parse._parse_sub(source, state, sub_verbose, nested + 1)
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1234, in _parse_sub
itemsappend(sre_parse._parse(source, state, verbose, nested + 1,
File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1707, in _parse
not (del_flags & SRE_FLAG_VERBOSE))
File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\enum.py",
line 987, in __and__
if not isinstance(other, (self.__class__, int)):

‫בתאריך יום א׳, 26 ביוני 2022 ב-13:48 מאת נתי שטרן <‪nsh...@gmail.com‬‏>:‬
--
<https://netanel.ml>

dn

unread,
Jun 26, 2022, 6:55:45 AM6/26/22
to
On 26/06/2022 22.48, נתי שטרן wrote:
> def compile(p, flags=0):
> # internal: convert pattern list to internal format
>
> if (isinstance(p,str)):
> pattern = p
> p = sre_parse.parse(p, flags)
> else:
> pattern = None
>
> code = _code(p, flags)
>
> if flags & SRE_FLAG_DEBUG:
> print()
> dis(code)
>
> # map in either direction
> groupindex = p.state.groupdict
> indexgroup = [None] * p.state.groups
> for k, i in groupindex.items():
> indexgroup[i] = k
>
> return sre_compile.compile(
> pattern, flags | p.state.flags, code,
> p.state.groups-1,
> groupindex, tuple(indexgroup)
> )


Why would any code give a recursion error?

With recursion problems, the first question to ask is: how does this
thing stop?

Have you built some test-data with only a handful of items, and thus a
predictable result. Does that result occur? If not, where are the
differences occurring?
--
Regards,
=dn

נתי שטרן

unread,
Jun 26, 2022, 6:57:07 AM6/26/22
to
and i ask also what's the problem with this function:


def _code(p, flags):

flags = p.state.flags | flags
code = []

# compile info block
sre_compile._compile_info(code, p, flags)

# compile the pattern
sre_compile._compile(code, p.data, flags)

code.append(SUCCESS)

return code


‫בתאריך יום א׳, 26 ביוני 2022 ב-13:48 מאת נתי שטרן <‪nsh...@gmail.com‬‏>:‬

> def compile(p, flags=0):
> # internal: convert pattern list to internal format
>
> if (isinstance(p,str)):
> pattern = p
> p = sre_parse.parse(p, flags)
> else:
> pattern = None
>
> code = _code(p, flags)
>
> if flags & SRE_FLAG_DEBUG:
> print()
> dis(code)
>
> # map in either direction
> groupindex = p.state.groupdict
> indexgroup = [None] * p.state.groups
> for k, i in groupindex.items():
> indexgroup[i] = k
>
> return sre_compile.compile(
> pattern, flags | p.state.flags, code,
> p.state.groups-1,
> groupindex, tuple(indexgroup)
> )
>
>

נתי שטרן

unread,
Jun 26, 2022, 7:00:38 AM6/26/22
to
I FIXED THE CODE

‫בתאריך יום א׳, 26 ביוני 2022 ב-13:57 מאת ‪dn‬‏ <‪
Pytho...@danceswithmice.info‬‏>:‬

> On 26/06/2022 22.48, נתי שטרן wrote:
> > def compile(p, flags=0):
> > # internal: convert pattern list to internal format
> >
> > if (isinstance(p,str)):
> > pattern = p
> > p = sre_parse.parse(p, flags)
> > else:
> > pattern = None
> >
> > code = _code(p, flags)
> >
> > if flags & SRE_FLAG_DEBUG:
> > print()
> > dis(code)
> >
> > # map in either direction
> > groupindex = p.state.groupdict
> > indexgroup = [None] * p.state.groups
> > for k, i in groupindex.items():
> > indexgroup[i] = k
> >
> > return sre_compile.compile(
> > pattern, flags | p.state.flags, code,
> > p.state.groups-1,
> > groupindex, tuple(indexgroup)
> > )
>
>
> Why would any code give a recursion error?
>
> With recursion problems, the first question to ask is: how does this
> thing stop?
>
> Have you built some test-data with only a handful of items, and thus a
> predictable result. Does that result occur? If not, where are the
> differences occurring?
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
>


--
<https://netanel.ml>

dn

unread,
Jun 26, 2022, 7:02:26 AM6/26/22
to
On 26/06/2022 23.00, נתי שטרן wrote:
> I FIXED THE CODE 

For the benefit of future-readers: how did you go about fixing it? What
was wrong?

--
Regards,
=dn
0 new messages