[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: event.py
File is not writable. Editing disabled.
#!/opt/alt/python37/bin/python3 -bb # coding=utf-8 # # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT from __future__ import absolute_import import syslog import types # NOQA from traceback import format_exc class Event(object): """ Event is an object that can have several listeners. Register new handler using '.register()' method. When you call '.throw_event(*a, **kw)' , class notifies all registered listeners. This class is logging his actions to syslog. Exceptions happened in hooks are logged as warnings, all other messages have debug level. For debug purposes you can manually change syslog level in /etc/rsyslog.conf file. """ # messages with level 'DEBUG' needed only for developers # so hide them by default in order not to confuse clients WRITE_DEBUG_TO_SYSLOG = False def __init__(self): self._listeners = set() @classmethod def _log_message(cls, level, message): # type: (int, str) -> None if level == syslog.LOG_DEBUG and not cls.WRITE_DEBUG_TO_SYSLOG: return syslog.syslog(level, message) # noinspection PyBroadException def _run_or_log_exception(self, func, *args, **kwargs): # type: (types.FunctionType, list, dict) -> None """Run callable object func and forward exceptions to syslog""" try: func(*args, **kwargs) except BaseException: footprint = self._get_function_footprint(func) message = "WARNING: An error occurred while notifying handler " \ "{} with ({}, {}). Following error raised: {}." \ "Please, contact CloudLinux support if it happens again." \ "".format(footprint, args, kwargs, format_exc()) self._log_message(syslog.LOG_WARNING, message) else: message = "DEBUG: Handler {} notified with params: ({}, {})".format(func, args, kwargs) self._log_message(syslog.LOG_DEBUG, message) @staticmethod def _get_function_footprint(func): # type: (types.FunctionType) -> str return func.__name__ + ':' + func.__module__ # TODO: add arguments match validation here def register(self, func): # type: (types.FunctionType) -> types.FunctionType self._listeners.add(func) self._log_message(syslog.LOG_DEBUG, "DEBUG: Registered new handler {}." "".format(self._get_function_footprint(func))) # return func here in order to be able to use multiple decorators at once # otherwise, decorated function becomes 'None' return func def unregister(self, func): # type: (types.FunctionType) -> None if func in self._listeners: self._listeners.remove(func) self._log_message(syslog.LOG_DEBUG, "DEBUG: Unregister handler {}." "".format(self._get_function_footprint(func))) def throw_event(self, *args, **kwargs): # type: (list, dict) -> None for func in self._listeners: self._run_or_log_exception(func, *args, **kwargs)
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server05.hostinghome.co.in
Server IP: 192.168.74.40
PHP Version: 7.4.33
Server Software: Apache
System: Linux server05.hostinghome.co.in 3.10.0-962.3.2.lve1.5.81.el7.x86_64 #1 SMP Wed May 31 10:36:47 UTC 2023 x86_64
HDD Total: 1.95 TB
HDD Free: 691.03 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Disabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: itsweb
User ID (UID): 1619
Group ID (GID): 1621
Script Owner UID: 1619
Current Dir Owner: N/A