PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/self/root/opt/saltstack/salt/extras-3.10/rads/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/self/root/opt/saltstack/salt/extras-3.10/rads/context.py

"""backwards compat for rads.context"""

# pylint: disable=wrong-import-position,wrong-import-order
import __main__ as main_obj
import time
import warnings
from contextlib import contextmanager
import socket
import hashlib
import pymysql
from ._locking import LockError as S_LockError
from .compat import RadsDeprecation


@contextmanager
def db_cur(_autocommit=False, _yield_conn=False, **kwargs):
    """deprecated"""
    warnings.warn(
        'rads.context.db_cur is deprecated. Use pymysql.connect',
        RadsDeprecation,
        stacklevel=3,
    )
    kwargs['autocommit'] = _autocommit
    if 'db' in kwargs:
        warnings.warn(
            'The db= kwarg is deprecated in PyMySQL. Please use database=',
            RadsDeprecation,
            stacklevel=3,
        )
        kwargs['database'] = kwargs.pop('db')
    with pymysql.connect(**kwargs) as conn:
        with conn.cursor() as cur:
            if _yield_conn:
                yield conn, cur
            else:
                yield cur


@contextmanager
def s_lock(name=None):
    """deprecated"""
    warnings.warn(
        'rads.context.s_lock is deprecated. see rads.lock',
        RadsDeprecation,
        stacklevel=3,
    )
    if name is None:
        # caveat: this will crash if run in an interactive python shell
        name = main_obj.__file__
    name = name.encode('utf-8')
    lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
    try:
        lock_socket.bind('\0%s' % hashlib.sha256(name).hexdigest())
    except socket.error as exc:
        raise S_LockError(name) from exc
    try:
        yield
    finally:
        lock_socket.close()


@contextmanager
def wait_lock(name=None, sleep=0.5, max_sleep=None):
    """deprecated"""
    warnings.warn(
        'rads.context.wait_lock is deprecated. see rads.wait_lock',
        RadsDeprecation,
        stacklevel=3,
    )
    if name is None:
        # caveat: this will crash if run in an interactive python shell
        name = main_obj.__file__
    slept = 0.0
    while True:
        try:
            with s_lock(name):
                yield
                return
        except S_LockError:
            time.sleep(sleep)
            slept += sleep
            if max_sleep is not None and slept >= max_sleep:
                raise