SILENT KILLERPanel

Current Path: > > lib > python3.6 > site-packages > rhn


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //lib/python3.6/site-packages/rhn

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
actions Directory - -
SSL.py File 11053 bytes September 17 2024 10:10:54.
SmartIO.py File 2164 bytes February 19 2018 08:18:29.
UserDictCase.py File 3034 bytes February 19 2018 08:18:29.
__init__.py File 132 bytes February 19 2018 08:18:29.
connections.py File 9712 bytes September 17 2024 10:10:54.
i18n.py File 1773 bytes February 19 2018 08:18:29.
nonblocking.py File 2427 bytes February 19 2018 08:18:29.
rhnLockfile.py File 3427 bytes February 19 2018 08:18:29.
rpclib.py File 24298 bytes September 17 2024 10:10:55.
tb.py File 836 bytes February 19 2018 08:18:29.
transports.py File 31979 bytes September 17 2024 10:10:55.

Reading File: //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+")

SILENT KILLER Tool