$46 GRAYBYTE WORDPRESS FILE MANAGER $91

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/testfixtures/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/testfixtures//sybil.py
import os
import re
import textwrap

from sybil import Region, Example, Document
from testfixtures import diff

FILEBLOCK_START = re.compile(r'^\.\.\s*topic::?\s*(.+)\b', re.MULTILINE)
FILEBLOCK_END = re.compile(r'(\n\Z|\n(?=\S))')
CLASS = re.compile(r'\s+:class:\s*(read|write)-file')


class FileBlock(object):
    def __init__(self, path, content, action):
        self.path, self.content, self.action = path, content, action


class FileParser(object):
    """
    A `Sybil <http://sybil.readthedocs.io>`__ parser that
    parses certain ReST sections to read and write files in the
    configured :class:`~testfixtures.TempDirectory`.

    :param name: This is the name of the :class:`~testfixtures.TempDirectory` to use
                 in the Sybil test namespace.

    """
    def __init__(self, name: str):
        self.name = name

    def __call__(self, document: Document):
        for start_match, end_match, source in document.find_region_sources(
            FILEBLOCK_START, FILEBLOCK_END
        ):
            lines = source.splitlines()
            class_ = CLASS.match(lines[1])
            if not class_:
                continue
            index = 3
            if lines[index].strip() == '::':
                index += 1
            source = textwrap.dedent('\n'.join(lines[index:])).lstrip()
            if source[-1] != '\n':
                source += '\n'

            parsed = FileBlock(
                path=start_match.group(1),
                content=source,
                action=class_.group(1)
            )

            yield Region(
                start_match.start(),
                end_match.end(),
                parsed,
                self.evaluate
            )

    def evaluate(self, example: Example):
        block: FileBlock = example.parsed
        dir = example.namespace[self.name]
        if block.action == 'read':
            actual = dir.read(block.path, 'ascii').replace(os.linesep, '\n')
            if actual != block.content:
                return diff(
                    block.content,
                    actual,
                    'File %r, line %i:' % (example.path, example.line),
                    'Reading from "%s":' % dir.as_string(block.path)
                )
        if block.action == 'write':
            dir.write(block.path, block.content, 'ascii')

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
17 Dec 2025 3.08 AM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
tests
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
1.194 KB
17 Apr 2025 8.10 PM
root / root
0644
comparison.py
39.142 KB
17 Apr 2025 8.10 PM
root / root
0644
compat.py
0.219 KB
17 Apr 2025 8.10 PM
root / root
0644
components.py
1.306 KB
17 Apr 2025 8.10 PM
root / root
0644
datetime.py
24.423 KB
17 Apr 2025 8.10 PM
root / root
0644
django.py
2.885 KB
17 Apr 2025 8.10 PM
root / root
0644
logcapture.py
10.755 KB
17 Apr 2025 8.10 PM
root / root
0644
mock.py
1.205 KB
17 Apr 2025 8.10 PM
root / root
0644
outputcapture.py
4.688 KB
17 Apr 2025 8.10 PM
root / root
0644
popen.py
9.887 KB
17 Apr 2025 8.10 PM
root / root
0644
replace.py
12.149 KB
17 Apr 2025 8.10 PM
root / root
0644
resolve.py
2.054 KB
17 Apr 2025 8.10 PM
root / root
0644
rmtree.py
2.523 KB
17 Apr 2025 8.10 PM
root / root
0644
shouldraise.py
3.578 KB
17 Apr 2025 8.10 PM
root / root
0644
shouldwarn.py
2.213 KB
17 Apr 2025 8.10 PM
root / root
0644
sybil.py
2.279 KB
17 Apr 2025 8.10 PM
root / root
0644
tempdirectory.py
12.887 KB
17 Apr 2025 8.10 PM
root / root
0644
twisted.py
4.8 KB
17 Apr 2025 8.10 PM
root / root
0644
utils.py
2.737 KB
17 Apr 2025 8.10 PM
root / root
0644
version.txt
0.006 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF