tests/filtertraceback.py
author Sandu Turcan <idlsoft@gmail.com>
Tue, 03 May 2022 21:44:30 -0400
branchstable
changeset 49241 6b10151b9621
parent 45830 c102b704edb5
child 48875 6000f5b25c9b
permissions -rwxr-xr-x
narrow_widen_acl: enforce narrowacl in narrow_widen (SEC) Reviewer note: this was sent by the author as a simple bugfix, but can be considered a security patch, since it allows users to access things outside of the ACL, hence the (SEC) prefix. However, this affects the `narrow` extention which is still marked as experimental and has relatively few users aside from large companies with their own security layers on top from what we can gather. We feel (Alphare: or at least, I feel) like pinging the packaging list is enough in this case.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45830
c102b704edb5 global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44654
diff changeset
     1
#!/usr/bin/env python3
41462
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# Filters traceback lines from stdin.
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
from __future__ import absolute_import, print_function
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
44654
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
     7
import io
41462
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
import sys
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
44654
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    10
if sys.version_info[0] >= 3:
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    11
    # Prevent \r from being inserted on Windows.
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    12
    sys.stdout = io.TextIOWrapper(
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    13
        sys.stdout.buffer,
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    14
        sys.stdout.encoding,
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    15
        sys.stdout.errors,
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    16
        newline="\n",
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    17
        line_buffering=sys.stdout.line_buffering,
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    18
    )
d359f0d1a3d3 tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41462
diff changeset
    19
41462
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    20
state = 'none'
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    21
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
for line in sys.stdin:
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    23
    if state == 'none':
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    24
        if line.startswith('Traceback '):
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
            state = 'tb'
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    27
    elif state == 'tb':
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    28
        if line.startswith('  File '):
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    29
            state = 'file'
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    30
            continue
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
        elif not line.startswith(' '):
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
            state = 'none'
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
    elif state == 'file':
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    36
        # Ignore lines after "  File "
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    37
        state = 'tb'
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
        continue
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
9b2b8794f801 hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    40
    print(line, end='')