$16 GRAYBYTE WORDPRESS FILE MANAGER $54

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

/usr/lib/python3.6/site-packages/rhn/

HOME
Current File : /usr/lib/python3.6/site-packages/rhn//SmartIO.py
#
# Smart IO class
#
# Copyright (c) 2002--2016 Red Hat, Inc.
#
# Author: Mihai Ibanescu <misa@redhat.com>

"""
This module implements the SmartIO class
"""

import os
try: # python2
    from cStringIO import StringIO
except ImportError: # python3
    from io import BytesIO as StringIO

class SmartIO:
    """
    The SmartIO class allows one to put a cap on the memory consumption.
    StringIO objects are very fast, because they are stored in memory, but
    if they are too big the memory footprint becomes noticeable.
    The write method of a SmartIO determines if the data that is to be added
    to the (initially) StrintIO object does not exceed a certain threshold; if
    it does, it switches the storage to a temporary disk file
    """
    def __init__(self, max_mem_size=16384, force_mem=0):
        self._max_mem_size = max_mem_size
        self._io = StringIO()
        # self._fixed is a flag to show if we're supposed to consider moving
        # the StringIO object into a tempfile
        # Invariant: if self._fixed == 0, we have a StringIO (if self._fixed
        # is 1 and force_mem was 0, then we have a file)
        if force_mem:
            self._fixed = 1
        else:
            self._fixed = 0

    def set_max_mem_size(self, max_mem_size):
        self._max_mem_size = max_mem_size

    def get_max_mem_size(self):
        return self._max_mem_size

    def write(self, data):
        if not self._fixed:
            # let's consider moving it to a file
            if len(data) + self._io.tell() > self._max_mem_size:
                # We'll overflow, change to a tempfile
                tmpfile = _tempfile()
                tmpfile.write(self._io.getvalue())
                self._fixed = 1
                self._io = tmpfile

        self._io.write(data)

    def __getattr__(self, name):
        return getattr(self._io, name)

# Creates a temporary file and passes back its file descriptor
def _tempfile():
    import tempfile
    (fd, fname) = tempfile.mkstemp(prefix="_rhn_transports-%d-" \
                                   % os.getpid())
    # tempfile, unlink it
    os.unlink(fname)
    return os.fdopen(fd, "wb+")

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
16 Dec 2025 9.25 PM
root / root
0755
__pycache__
--
14 Aug 2025 9.25 PM
root / root
0755
actions
--
14 Aug 2025 9.26 PM
root / root
0755
SSL.py
10.794 KB
17 Sep 2024 5.10 PM
root / root
0644
SmartIO.py
2.113 KB
19 Feb 2018 3.18 PM
root / root
0644
UserDictCase.py
2.963 KB
19 Feb 2018 3.18 PM
root / root
0644
__init__.py
0.129 KB
19 Feb 2018 3.18 PM
root / root
0644
connections.py
9.484 KB
17 Sep 2024 5.10 PM
root / root
0644
i18n.py
1.731 KB
19 Feb 2018 3.18 PM
root / root
0644
nonblocking.py
2.37 KB
19 Feb 2018 3.18 PM
root / root
0644
rhnLockfile.py
3.347 KB
19 Feb 2018 3.18 PM
root / root
0644
rpclib.py
23.729 KB
17 Sep 2024 5.10 PM
root / root
0644
tb.py
0.816 KB
19 Feb 2018 3.18 PM
root / root
0644
transports.py
31.229 KB
17 Sep 2024 5.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF