Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/monara/public_html/test.athavaneng.com/themes.php on line 99
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 226
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 227
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 228
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 229
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 230
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 231
# DEBUG and error logging
from lxml.includes cimport xmlerror
from lxml cimport cvarargs
DEF GLOBAL_ERROR_LOG = u"_GlobalErrorLog"
DEF XSLT_ERROR_LOG = u"_XSLTErrorLog"
# module level API functions
def clear_error_log():
u"""clear_error_log()
Clear the global error log. Note that this log is already bound to a
fixed size.
Note: since lxml 2.2, the global error log is local to a thread
and this function will only clear the global error log of the
current thread.
"""
_getThreadErrorLog(GLOBAL_ERROR_LOG).clear()
# setup for global log:
cdef void _initThreadLogging():
# Disable generic error lines from libxml2.
_connectGenericErrorLog(None)
# Divert XSLT error messages to the global XSLT error log instead of stderr.
xslt.xsltSetGenericErrorFunc(NULL, _receiveXSLTError)
# Logging classes
@cython.final
@cython.freelist(16)
cdef class _LogEntry:
"""A log message entry from an error log.
Attributes:
- message: the message text
- domain: the domain ID (see lxml.etree.ErrorDomains)
- type: the message type ID (see lxml.etree.ErrorTypes)
- level: the log level ID (see lxml.etree.ErrorLevels)
- line: the line at which the message originated (if applicable)
- column: the character column at which the message originated (if applicable)
- filename: the name of the file in which the message originated (if applicable)
- path: the location in which the error was found (if available)
"""
cdef readonly int domain
cdef readonly int type
cdef readonly int level
cdef readonly int line
cdef readonly int column
cdef basestring _message
cdef basestring _filename
cdef char* _c_message
cdef xmlChar* _c_filename
cdef xmlChar* _c_path
def __dealloc__(self):
tree.xmlFree(self._c_message)
tree.xmlFree(self._c_filename)
tree.xmlFree(self._c_path)
@cython.final
cdef _setError(self, xmlerror.xmlError* error):
self.domain = error.domain
self.type = error.code
self.level = error.level
self.line = error.line
self.column = error.int2
self._c_message = NULL
self._c_filename = NULL
self._c_path = NULL
if (error.message is NULL or
error.message[0] == b'\0' or
error.message[0] == b'\n' and error.message[1] == b'\0'):
self._message = u"unknown error"
else:
self._message = None
self._c_message = tree.xmlStrdup(
error.message)
if not self._c_message:
raise MemoryError()
if error.file is NULL:
self._filename = u''
else:
self._filename = None
self._c_filename = tree.xmlStrdup( error.file)
if not self._c_filename:
raise MemoryError()
if error.node is not NULL:
self._c_path = tree.xmlGetNodePath( error.node)
@cython.final
cdef _setGeneric(self, int domain, int type, int level, int line,
message, filename):
self.domain = domain
self.type = type
self.level = level
self.line = line
self.column = 0
self._message = message
self._filename = filename
self._c_path = NULL
def __repr__(self):
return u"%s:%d:%d:%s:%s:%s: %s" % (
self.filename, self.line, self.column, self.level_name,
self.domain_name, self.type_name, self.message)
@property
def domain_name(self):
"""The name of the error domain. See lxml.etree.ErrorDomains
"""
return ErrorDomains._getName(self.domain, u"unknown")
@property
def type_name(self):
"""The name of the error type. See lxml.etree.ErrorTypes
"""
if self.domain == ErrorDomains.RELAXNGV:
getName = RelaxNGErrorTypes._getName
else:
getName = ErrorTypes._getName
return getName(self.type, u"unknown")
@property
def level_name(self):
"""The name of the error level. See lxml.etree.ErrorLevels
"""
return ErrorLevels._getName(self.level, u"unknown")
@property
def message(self):
"""The log message string.
"""
cdef size_t size
if self._message is not None:
return self._message
if self._c_message is NULL:
return None
size = cstring_h.strlen(self._c_message)
if size > 0 and self._c_message[size-1] == '\n':
size -= 1 # strip EOL
# cannot use funicode() here because the message may contain
# byte encoded file paths etc.
try:
self._message = self._c_message[:size].decode('utf8')
except UnicodeDecodeError:
try:
self._message = self._c_message[:size].decode(
'ascii', 'backslashreplace')
except UnicodeDecodeError:
self._message = u''
if self._c_message:
# clean up early
tree.xmlFree(self._c_message)
self._c_message = NULL
return self._message
@property
def filename(self):
"""The file path where the report originated, if any.
"""
if self._filename is None:
if self._c_filename is not NULL:
self._filename = _decodeFilename(self._c_filename)
# clean up early
tree.xmlFree(self._c_filename)
self._c_filename = NULL
return self._filename
@property
def path(self):
"""The XPath for the node where the error was detected.
"""
return funicode(self._c_path) if self._c_path is not NULL else None
cdef class _BaseErrorLog:
cdef _LogEntry _first_error
cdef readonly object last_error
def __init__(self, first_error, last_error):
self._first_error = first_error
self.last_error = last_error
cpdef copy(self):
return _BaseErrorLog(self._first_error, self.last_error)
def __repr__(self):
return u''
cpdef receive(self, _LogEntry entry):
pass
@cython.final
cdef void _receive(self, xmlerror.xmlError* error):
cdef bint is_error
cdef _LogEntry entry
cdef _BaseErrorLog global_log
entry = _LogEntry.__new__(_LogEntry)
entry._setError(error)
is_error = error.level == xmlerror.XML_ERR_ERROR or \
error.level == xmlerror.XML_ERR_FATAL
global_log = _getThreadErrorLog(GLOBAL_ERROR_LOG)
if global_log is not self:
global_log.receive(entry)
if is_error:
global_log.last_error = entry
self.receive(entry)
if is_error:
self.last_error = entry
@cython.final
cdef void _receiveGeneric(self, int domain, int type, int level, int line,
message, filename):
cdef bint is_error
cdef _LogEntry entry
cdef _BaseErrorLog global_log
entry = _LogEntry.__new__(_LogEntry)
entry._setGeneric(domain, type, level, line, message, filename)
is_error = level == xmlerror.XML_ERR_ERROR or \
level == xmlerror.XML_ERR_FATAL
global_log = _getThreadErrorLog(GLOBAL_ERROR_LOG)
if global_log is not self:
global_log.receive(entry)
if is_error:
global_log.last_error = entry
self.receive(entry)
if is_error:
self.last_error = entry
@cython.final
cdef _buildParseException(self, exctype, default_message):
code = xmlerror.XML_ERR_INTERNAL_ERROR
if self._first_error is None:
return exctype(default_message, code, 0, 0)
message = self._first_error.message
if message:
code = self._first_error.type
else:
message = default_message
line = self._first_error.line
column = self._first_error.column
filename = self._first_error.filename
if line > 0:
if column > 0:
message = f"{message}, line {line}, column {column}"
else:
message = f"{message}, line {line}"
return exctype(message, code, line, column, filename)
@cython.final
cdef _buildExceptionMessage(self, default_message):
if self._first_error is None:
return default_message
if self._first_error.message:
message = self._first_error.message
elif default_message is None:
return None
else:
message = default_message
if self._first_error.line > 0:
if self._first_error.column > 0:
message = f"{message}, line {self._first_error.line}, column {self._first_error.column}"
else:
message = f"{message}, line {self._first_error.line}"
return message
cdef class _ListErrorLog(_BaseErrorLog):
u"Immutable base version of a list based error log."
cdef list _entries
cdef int _offset
def __init__(self, entries, first_error, last_error):
if entries:
if first_error is None:
first_error = entries[0]
if last_error is None:
last_error = entries[-1]
_BaseErrorLog.__init__(self, first_error, last_error)
self._entries = entries
cpdef copy(self):
u"""Creates a shallow copy of this error log. Reuses the list of
entries.
"""
cdef _ListErrorLog log = _ListErrorLog(
self._entries, self._first_error, self.last_error)
log._offset = self._offset
return log
def __iter__(self):
entries = self._entries
if self._offset:
entries = islice(entries, self._offset)
return iter(entries)
def __repr__(self):
return u'\n'.join([repr(entry) for entry in self])
def __getitem__(self, index):
if self._offset:
index += self._offset
return self._entries[index]
def __len__(self):
return len(self._entries) - self._offset
def __contains__(self, error_type):
cdef Py_ssize_t i
for i, entry in enumerate(self._entries):
if i < self._offset:
continue
if entry.type == error_type:
return True
return False
def __nonzero__(self):
return len(self._entries) > self._offset
def filter_domains(self, domains):
u"""Filter the errors by the given domains and return a new error log
containing the matches.
"""
cdef _LogEntry entry
if isinstance(domains, (int, long)):
domains = (domains,)
filtered = [entry for entry in self if entry.domain in domains]
return _ListErrorLog(filtered, None, None)
def filter_types(self, types):
u"""filter_types(self, types)
Filter the errors by the given types and return a new error
log containing the matches.
"""
cdef _LogEntry entry
if isinstance(types, (int, long)):
types = (types,)
filtered = [entry for entry in self if entry.type in types]
return _ListErrorLog(filtered, None, None)
def filter_levels(self, levels):
u"""filter_levels(self, levels)
Filter the errors by the given error levels and return a new
error log containing the matches.
"""
cdef _LogEntry entry
if isinstance(levels, (int, long)):
levels = (levels,)
filtered = [entry for entry in self if entry.level in levels]
return _ListErrorLog(filtered, None, None)
def filter_from_level(self, level):
u"""filter_from_level(self, level)
Return a log with all messages of the requested level of worse.
"""
cdef _LogEntry entry
filtered = [entry for entry in self if entry.level >= level]
return _ListErrorLog(filtered, None, None)
def filter_from_fatals(self):
u"""filter_from_fatals(self)
Convenience method to get all fatal error messages.
"""
return self.filter_from_level(ErrorLevels.FATAL)
def filter_from_errors(self):
u"""filter_from_errors(self)
Convenience method to get all error messages or worse.
"""
return self.filter_from_level(ErrorLevels.ERROR)
def filter_from_warnings(self):
u"""filter_from_warnings(self)
Convenience method to get all warnings or worse.
"""
return self.filter_from_level(ErrorLevels.WARNING)
@cython.final
@cython.internal
cdef class _ErrorLogContext:
"""
Error log context for the 'with' statement.
Stores a reference to the current callbacks to allow for
recursively stacked log contexts.
"""
cdef xmlerror.xmlStructuredErrorFunc old_error_func
cdef void* old_error_context
cdef xmlerror.xmlGenericErrorFunc old_xslt_error_func
cdef void* old_xslt_error_context
cdef _BaseErrorLog old_xslt_error_log
cdef int push_error_log(self, _BaseErrorLog log) except -1:
self.old_error_func = xmlerror.xmlStructuredError
self.old_error_context = xmlerror.xmlStructuredErrorContext
xmlerror.xmlSetStructuredErrorFunc(
log, _receiveError)
# xslt.xsltSetGenericErrorFunc() is not thread-local => keep error log in TLS
self.old_xslt_error_func = xslt.xsltGenericError
self.old_xslt_error_context = xslt.xsltGenericErrorContext
self.old_xslt_error_log = _getThreadErrorLog(XSLT_ERROR_LOG)
_setThreadErrorLog(XSLT_ERROR_LOG, log)
xslt.xsltSetGenericErrorFunc(
NULL, _receiveXSLTError)
return 0
cdef int pop_error_log(self) except -1:
xmlerror.xmlSetStructuredErrorFunc(
self.old_error_context, self.old_error_func)
xslt.xsltSetGenericErrorFunc(
self.old_xslt_error_context, self.old_xslt_error_func)
_setThreadErrorLog(XSLT_ERROR_LOG, self.old_xslt_error_log)
self.old_xslt_error_log= None
return 0
cdef class _ErrorLog(_ListErrorLog):
cdef list _logContexts
def __cinit__(self):
self._logContexts = []
def __init__(self):
_ListErrorLog.__init__(self, [], None, None)
@cython.final
cdef int __enter__(self) except -1:
return self.connect()
def __exit__(self, *args):
# TODO: make this a cdef function when Cython supports it
self.disconnect()
@cython.final
cdef int connect(self) except -1:
self._first_error = None
del self._entries[:]
cdef _ErrorLogContext context = _ErrorLogContext.__new__(_ErrorLogContext)
context.push_error_log(self)
self._logContexts.append(context)
return 0
@cython.final
cdef int disconnect(self) except -1:
cdef _ErrorLogContext context = self._logContexts.pop()
context.pop_error_log()
return 0
cpdef clear(self):
self._first_error = None
self.last_error = None
self._offset = 0
del self._entries[:]
cpdef copy(self):
u"""Creates a shallow copy of this error log and the list of entries.
"""
return _ListErrorLog(
self._entries[self._offset:],
self._first_error, self.last_error)
def __iter__(self):
return iter(self._entries[self._offset:])
cpdef receive(self, _LogEntry entry):
if self._first_error is None and entry.level >= xmlerror.XML_ERR_ERROR:
self._first_error = entry
self._entries.append(entry)
cdef class _DomainErrorLog(_ErrorLog):
def __init__(self, domains):
_ErrorLog.__init__(self)
self._accepted_domains = tuple(domains)
cpdef receive(self, _LogEntry entry):
if entry.domain in self._accepted_domains:
_ErrorLog.receive(self, entry)
cdef class _RotatingErrorLog(_ErrorLog):
cdef int _max_len
def __init__(self, max_len):
_ErrorLog.__init__(self)
self._max_len = max_len
cpdef receive(self, _LogEntry entry):
if self._first_error is None and entry.level >= xmlerror.XML_ERR_ERROR:
self._first_error = entry
self._entries.append(entry)
if len(self._entries) > self._max_len:
self._offset += 1
if self._offset > self._max_len // 3:
offset = self._offset
self._offset = 0
del self._entries[:offset]
cdef class PyErrorLog(_BaseErrorLog):
u"""PyErrorLog(self, logger_name=None, logger=None)
A global error log that connects to the Python stdlib logging package.
The constructor accepts an optional logger name or a readily
instantiated logger instance.
If you want to change the mapping between libxml2's ErrorLevels and Python
logging levels, you can modify the level_map dictionary from a subclass.
The default mapping is::
ErrorLevels.WARNING = logging.WARNING
ErrorLevels.ERROR = logging.ERROR
ErrorLevels.FATAL = logging.CRITICAL
You can also override the method ``receive()`` that takes a LogEntry
object and calls ``self.log(log_entry, format_string, arg1, arg2, ...)``
with appropriate data.
"""
cdef readonly dict level_map
cdef object _map_level
cdef object _log
def __init__(self, logger_name=None, logger=None):
_BaseErrorLog.__init__(self, None, None)
import logging
self.level_map = {
ErrorLevels.WARNING : logging.WARNING,
ErrorLevels.ERROR : logging.ERROR,
ErrorLevels.FATAL : logging.CRITICAL
}
self._map_level = self.level_map.get
if logger is None:
if logger_name:
logger = logging.getLogger(logger_name)
else:
logger = logging.getLogger()
self._log = logger.log
cpdef copy(self):
u"""Dummy method that returns an empty error log.
"""
return _ListErrorLog([], None, None)
def log(self, log_entry, message, *args):
u"""log(self, log_entry, message, *args)
Called by the .receive() method to log a _LogEntry instance to
the Python logging system. This handles the error level
mapping.
In the default implementation, the ``message`` argument
receives a complete log line, and there are no further
``args``. To change the message format, it is best to
override the .receive() method instead of this one.
"""
self._log(
self._map_level(log_entry.level, 0),
message, *args
)
cpdef receive(self, _LogEntry log_entry):
u"""receive(self, log_entry)
Receive a _LogEntry instance from the logging system. Calls
the .log() method with appropriate parameters::
self.log(log_entry, repr(log_entry))
You can override this method to provide your own log output
format.
"""
self.log(log_entry, repr(log_entry))
# thread-local, global list log to collect error output messages from
# libxml2/libxslt
cdef _BaseErrorLog __GLOBAL_ERROR_LOG = _RotatingErrorLog(__MAX_LOG_SIZE)
cdef _BaseErrorLog _getThreadErrorLog(name):
u"""Retrieve the current error log with name 'name' of this thread."""
cdef python.PyObject* thread_dict
thread_dict = python.PyThreadState_GetDict()
if thread_dict is NULL:
return __GLOBAL_ERROR_LOG
try:
return (