/usr/lib64/python3.9/site-packages/systemd/__pycache__
NameSizeModeActions
daemon.cpython-39.opt-1.pyc25210644editdlrm
daemon.cpython-39.pyc25210644editdlrm
journal.cpython-39.opt-1.pyc212110644editdlrm
journal.cpython-39.pyc212110644editdlrm
__init__.cpython-39.opt-1.pyc1450644editdlrm
__init__.cpython-39.pyc1450644editdlrm
Edit: /usr/lib64/python3.9/site-packages/systemd/__pycache__/journal.cpython-39.pyc (21211B)
a ‡×XáVã"@sÖddlmZddlZddlZddlZddlZ ddl Z ddl Z ddlmZmZmZmZmZmZmZmZejdkrzddlmZddlmZmZmZddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*dd l+m,Z-ejd krædd lm.Z.ne/Z.d d „Z0dd„Z1dd„Z2dd„Z3dd„Z4ejd k�r(dd„Z5nej6Z5e5e5e5e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e3e2e1e0e4e8e7e7e7e7e7e3dœ!Z9e:dƒZ;dd„Zd d!„Z?d)d"d#„Z@ded$fd%d&„ZAGd'd(„d(e jBƒZCdS)*é)ÚdivisionN)Ú LOG_EMERGÚ LOG_ALERTÚLOG_CRITÚLOG_ERRÚ LOG_WARNINGÚ LOG_NOTICEÚLOG_INFOÚ LOG_DEBUG©ér )ÚChainMapé)Ú __version__ÚsendvÚ stream_fd) Ú_ReaderÚNOPÚAPPENDÚ INVALIDATEÚ LOCAL_ONLYÚ RUNTIME_ONLYÚSYSTEMÚ SYSTEM_ONLYÚ CURRENT_USERÚOS_ROOTÚ _get_catalog)Úid128©r )Ú MonotoniccCs$ttj|dd�tj|dd�fƒS)Nr©Z microsecondsr)Úbytes)rÚ _datetimeÚ timedeltaÚ_uuidÚUUID)Úm©r'ú5/usr/lib64/python3.9/site-packages/systemd/journal.pyÚ_convert_monotonic0sÿr)cCstjt|ƒd�S)Nr )r"r#Úint©Úsr'r'r(Ú_convert_source_monotonic5sr-cCstj |d¡S©Né@B)r"ÚdatetimeÚ fromtimestamp)Útr'r'r(Ú_convert_realtime9sr3cCstj t|ƒd¡Sr.)r"r0r1r*r+r'r'r(Ú_convert_timestamp=sr4cCs|S©Nr')Úxr'r'r(Ú_convert_trivialAsr7cCst | ¡¡Sr5)r$r%Údecoder+r'r'r(Ú _convert_uuidEsr9)!Ú MESSAGE_IDÚ _MACHINE_IDÚ_BOOT_IDÚPRIORITYZLEADERZ SESSION_IDZUSERSPACE_USECZ INITRD_USECZ KERNEL_USECZ_UIDZ_GIDZ_PIDZSYSLOG_FACILITYZ SYSLOG_PIDZ_AUDIT_SESSIONZ_AUDIT_LOGINUIDZ_SYSTEMD_SESSIONZ_SYSTEMD_OWNER_UIDÚ CODE_LINEZERRNOZ EXIT_STATUSZ_SOURCE_REALTIME_TIMESTAMPÚ__REALTIME_TIMESTAMPZ_SOURCE_MONOTONIC_TIMESTAMPÚ__MONOTONIC_TIMESTAMPÚ__CURSORZCOREDUMPZ COREDUMP_PIDZ COREDUMP_UIDZ COREDUMP_GIDZCOREDUMP_SESSIONZCOREDUMP_SIGNALZCOREDUMP_TIMESTAMPZ%ABCDEFGHIJKLMNOPQRTSUVWXYZ_0123456789cCst|ƒt Sr5)ÚsetÚ_IDENT_CHARACTERr+r'r'r(Ú_valid_field_nameqsrDcsÌeZdZdZd%‡fdd„ Zdd„Zdd„Zd d „Zd d „Ze j d krHeZ ‡fdd„Z d&‡fdd„ Z d'dd„Z‡fdd„Zd(‡fdd„ Z‡fdd„Zd)‡fdd„ Zdd„Zdd „Zd*d!d"„Zd+d#d$„Z‡ZS),ÚReaderaˆAccess systemd journal entries. Entries are subject to filtering and limits, see `add_match`, `this_boot`, `this_machine` functions and the `data_treshold` attribute. Note that in order to access the system journal, a non-root user must have the necessary privileges, see journalctl(1) for details. Unprivileged users can access only their own journal. Example usage to print out all informational or higher level messages for systemd-udevd for this boot: >>> from systemd import journal >>> j = journal.Reader() >>> j.this_boot() >>> j.log_level(journal.LOG_INFO) >>> j.add_match(_SYSTEMD_UNIT="systemd-udevd.service") >>> for entry in j: # doctest: +SKIP ... print(entry['MESSAGE']) starting version ... See systemd.journal-fields(7) for more info on typical fields found in the journal. Ncs�|dur"|dur|durt}nd}tt|ƒ |||¡tjdkrntƒ|_|dur^|jj  |¡|jj  t ¡nt   ¡|_|durŒ|j  |¡dS)a¿Create a new Reader. Argument `flags` defines the open flags of the journal, which can be one of, or ORed combination of constants: LOCAL_ONLY (default) opens journal on local machine only; RUNTIME_ONLY opens only volatile journal files; and SYSTEM_ONLY opens only journal files of system services and the kernel. Argument `path` is the directory of journal files, either a file system path or a file descriptor. Note that `flags`, `path`, and `files` are exclusive. Argument `converters` is a dictionary which updates the DEFAULT_CONVERTERS to convert journal field values. Field names are used as keys into this dictionary. The values must be single argument functions, which take a `bytes` object and return a converted value. When there's no entry for a field name, then the default UTF-8 decoding will be attempted. If the conversion fails with a ValueError, unconverted bytes object will be returned. (Note that ValueEror is a superclass of UnicodeDecodeError). Reader implements the context manager protocol: the journal will be closed when exiting the block. Nrr ) rÚsuperrEÚ__init__Ú_sysÚ version_infoÚ _ChainMapÚ convertersÚmapsÚappendÚDEFAULT_CONVERTERSÚcopyÚupdate)ÚselfÚflagsÚpathÚfilesrK©Ú __class__r'r(rG�s  zReader.__init__cCs6|j |tj¡}z ||ƒWSty0|YS0dS)a/Convert value using self.converters[key]. If `key` is not present in self.converters, a standard unicode decoding will be attempted. If the conversion (either key-specific or the default one) fails with a ValueError, the original bytes object will be returned. N)rKÚgetr!r8Ú ValueError)rQÚkeyÚvalueZconvertr'r'r(Ú_convert_field¹s   zReader._convert_fieldcsNi}| ¡D]<\‰}t|tƒr8‡‡fdd„|Dƒ|ˆ<q ˆ ˆ|¡|ˆ<q |S)z6Convert entire journal entry utilising _convert_field.csg|]}ˆ ˆ|¡‘qSr'©r[)Ú.0Úval©rYrQr'r(Ú Íóz)Reader._convert_entry..)ÚitemsÚ isinstanceÚlistr[)rQÚentryÚresultrZr'r_r(Ú_convert_entryÈs  zReader._convert_entrycCs|S)z=Return self. Part of the iterator protocol. r')rQr'r'r(Ú__iter__ÒszReader.__iter__cCs| ¡}|r|Stƒ‚dS)z�Return the next entry in the journal. Returns self.get_next() or raises StopIteration. Part of the iterator protocol. N)Úget_nextÚ StopIteration)rQZansr'r'r(Ú__next__ÙszReader.__next__rcs>t|ƒ}| dd„| ¡Dƒ¡|D]}tt|ƒ |¡q$dS)aHAdd one or more matches to the filter journal log entries. All matches of different field are combined with logical AND, and matches of the same field are automatically combined with logical OR. Matches can be passed as strings of form "FIELD=value", or keyword arguments FIELD="value". css|]\}}t||ƒVqdSr5©Ú _make_line©r]rYr^r'r'r(Ú òraz#Reader.add_match..N)rdÚextendrbrFrEÚ add_match)rQÚargsÚkwargsÚargrUr'r(rqészReader.add_matchrcsVtt|ƒ |¡rPtt|ƒ ¡}|rP| ¡|d<| ¡|d<| ¡|d<| |¡StƒS)a°Return the next log entry as a dictionary. Entries will be processed with converters specified during Reader creation. Optional `skip` value will return the `skip`-th log entry. Currently a standard dictionary of fields is returned, but in the future this might be changed to a different mapping type, so the calling code should not make assumptions about a specific type. r?r@rA) rFrEZ_nextZ_get_allZ _get_realtimeZ_get_monotonicZ _get_cursorrgÚdict)rQÚskiprerUr'r(riös     zReader.get_nextcCs | | ¡S)aÍReturn the previous log entry. Equivalent to get_next(-skip). Optional `skip` value will return the -`skip`-th log entry. Entries will be processed with converters specified during Reader creation. Currently a standard dictionary of fields is returned, but in the future this might be changed to a different mapping type, so the calling code should not make assumptions about a specific type. )ri)rQrvr'r'r(Ú get_previous szReader.get_previouscs$t‡‡fdd„ttˆƒ ˆ¡DƒƒS)zõReturn a list of unique values appearing in the journal for the given `field`. Note this does not respect any journal matches. Entries will be processed with converters specified during Reader creation. c3s|]}ˆ ˆ|¡VqdSr5r\)r]rZ©ÚfieldrQr'r(ro$sÿz&Reader.query_unique..)rBrFrEÚ query_unique)rQryrUrxr(rzs ÿzReader.query_uniquecs(|dur dn t|dƒ}tt|ƒ |¡S)aEWait for a change in the journal. `timeout` is the maximum time in seconds to wait, or None which means to wait forever. Returns one of NOP (no change), APPEND (new entries have been added to the end of the journal), or INVALIDATE (journal files have been added or removed). Néÿÿÿÿr/)r*rFrEÚwait)rQÚtimeoutÚusrUr'r(r|'s z Reader.waitcsJt|tjƒr$tt| d¡ƒdƒ}nt|tƒs:t|dƒ}tt|ƒ |¡S)a(Seek to a matching journal entry nearest to `timestamp` time. Argument `realtime` must be either an integer UNIX timestamp (in microseconds since the beginning of the UNIX epoch), or an float UNIX timestamp (in seconds since the beginning of the UNIX epoch), or a datetime.datetime instance. The integer form is deprecated. >>> import time >>> from systemd import journal >>> yesterday = time.time() - 24 * 60**2 >>> j = journal.Reader() >>> j.seek_realtime(yesterday) z%s.%fr/) rcr"r0r*ÚfloatÚstrftimerFrEÚ seek_realtime)rQZrealtimerUr'r(r�4s    zReader.seek_realtimecsDt|tjƒr| ¡}t|dƒ}t|tjƒr2|j}tt |ƒ  ||¡S)aGSeek to a matching journal entry nearest to `monotonic` time. Argument `monotonic` is a timestamp from boot in either seconds or a datetime.timedelta instance. Argument `bootid` is a string or UUID representing which boot the monotonic time is reference to. Defaults to current bootid. r/) rcr"r#Z total_secondsr*r$r%ÚhexrFrEÚseek_monotonic)rQÚ monotonicÚbootidrUr'r(rƒIs    zReader.seek_monotoniccCsHd|krdkr>> from systemd import journal >>> journal.send('Hello world') >>> journal.send('Hello, again, world', FIELD2='Greetings!') >>> journal.send('Binary message', BINARY=b'\xde\xad\xbe\xef') Value of the MESSAGE argument will be used for the MESSAGE= field. MESSAGE must be a string and will be sent as UTF-8 to the journal. MESSAGE_ID can be given to uniquely identify the type of message. It must be a string or a uuid.UUID object. CODE_LINE, CODE_FILE, and CODE_FUNC can be specified to identify the caller. Unless at least on of the three is given, values are extracted from the stack frame of the caller of send(). CODE_FILE and CODE_FUNC must be strings, CODE_LINE must be an integer. Additional fields for the journal entry can only be specified as keyword arguments. The payload can be either a string or bytes. A string will be sent as UTF-8, and bytes will be sent as-is to the journal. Other useful fields include PRIORITY, SYSLOG_FACILITY, SYSLOG_IDENTIFIER, SYSLOG_PID. zMESSAGE=Nr‚z MESSAGE_ID=é)Úlimitrr z CODE_FILE=zCODE_LINE={:d}z CODE_FUNC=css|]\}}t||ƒVqdSr5rlrnr'r'r(roÈrazsend..)r�rMÚ _tracebackÚ extract_stackÚformatrprbr)ZMESSAGEr:Ú CODE_FILEr>Ú CODE_FUNCrsrrÚidr'r'r(Úsendœs  "r£FcCsP|dur6tjr&tjdr&tjddkr,d}n tjd}t|||ƒ}t |dd¡S)aøReturn a file object wrapping a stream to journal. Log messages written to this file as simple newline sepearted text strings are written to the journal. The file will be line buffered, so messages are actually sent after a newline character is written. >>> from systemd import journal >>> stream = journal.stream('myapp') # doctest: +SKIP >>> res = stream.write('message...\n') # doctest: +SKIP will produce the following message in the journal:: PRIORITY=7 SYSLOG_IDENTIFIER=myapp MESSAGE=message... If identifier is None, a suitable default based on sys.argv[0] will be used. This interface can be used conveniently with the print function: >>> from __future__ import print_function >>> stream = journal.stream() # doctest: +SKIP >>> print('message...', file=stream) # doctest: +SKIP priority is the syslog priority, one of `LOG_EMERG`, `LOG_ALERT`, `LOG_CRIT`, `LOG_ERR`, `LOG_WARNING`, `LOG_NOTICE`, `LOG_INFO`, `LOG_DEBUG`. level_prefix is a boolean. If true, kernel-style log priority level prefixes (such as '<1>') are interpreted. See sd-daemon(3) for more information. Nrz-cZpythonÚwr)rHÚargvrÚ_osÚfdopen)Z identifierÚpriorityZ level_prefixÚfdr'r'r(ÚstreamÌs "  rªcs@eZdZdZejef‡fdd„ Zdd„Ze dd„ƒZ e Z ‡Z S)ÚJournalHandlera’Journal handler class for the Python logging framework. Please see the Python logging module documentation for an overview: http://docs.python.org/library/logging.html. To create a custom logger whose messages go only to journal: >>> import logging >>> log = logging.getLogger('custom_logger_name') >>> log.propagate = False >>> log.addHandler(JournalHandler()) >>> log.warning("Some message: %s", 'detail') Note that by default, message levels `INFO` and `DEBUG` are ignored by the logging framework. To enable those log levels: >>> log.setLevel(logging.DEBUG) To redirect all logging messages to journal regardless of where they come from, attach it to the root logger: >>> logging.root.addHandler(JournalHandler()) For more complex configurations when using `dictConfig` or `fileConfig`, specify `systemd.journal.JournalHandler` as the handler class. Only standard handler configuration options are supported: `level`, `formatter`, `filters`. To attach journal MESSAGE_ID, an extra field is supported: >>> import uuid >>> mid = uuid.UUID('0123456789ABCDEF0123456789ABCDEF') >>> log.warning("Message with ID", extra={'MESSAGE_ID': mid}) Fields to be attached to all messages sent through this handler can be specified as keyword arguments. This probably makes sense only for SYSLOG_IDENTIFIER and similar fields which are constant for the whole program: >>> JournalHandler(SYSLOG_IDENTIFIER='my-cool-app') <...JournalHandler ...> The following journal fields will be sent: `MESSAGE`, `PRIORITY`, `THREAD_NAME`, `CODE_FILE`, `CODE_LINE`, `CODE_FUNC`, `LOGGER` (name as supplied to getLogger call), `MESSAGE_ID` (optional, see above), `SYSLOG_IDENTIFIER` (defaults to sys.argv[0]). The function used to actually send messages can be overridden using the `sender_function` parameter. c sTtt|ƒ |¡|D]}t|ƒstd|ƒ‚qd|vrDtjd|d<||_||_dS)NzInvalid field name: ZSYSLOG_IDENTIFIERr) rFr«rGrDrXrHr¥r£Ú_extra)rQrˆZsender_functionrsÚnamerUr'r(rG,szJournalHandler.__init__c Cs¸z–| |¡}| |j¡}|j ¡}|jr2|j|d<|jrB|j|d<|jrVt|jƒ|d<|  |j ¡|j |ft|ƒ|j |j |j|j|j|jdœ|¤ŽWnty²| |¡Yn0dS)aWrite `record` as a journal event. MESSAGE is taken from the message provided by the user, and PRIORITY, LOGGER, THREAD_NAME, CODE_{FILE,LINE,FUNC} fields are appended automatically. In addition, record.MESSAGE_ID will be used if present. ZEXCEPTION_TEXTZEXCEPTION_INFOZ CODE_ARGS)r=ZLOGGERZ THREAD_NAMEZ PROCESS_NAMEr r>r¡N)rŸÚ map_priorityÚlevelnor¬rOZexc_textÚexc_inforrršrPÚ__dict__r£r­Z threadNameZ processNameÚpathnameÚlinenoZfuncNameÚ ExceptionZ handleError)rQÚrecordÚmsgZpriÚextrasr'r'r(Úemit8s0      ùø zJournalHandler.emitcCsN|tjkrtS|tjkrtS|tjkr*tS|tjkr8tS|tj krFt St SdS)z¬Map logging levels to journald priorities. Since Python log level numbers are "sparse", we have to map numbers in between the standard levels too. N) Ú_loggingÚDEBUGr ÚINFOr ZWARNINGrZERRORrZCRITICALrr)r¯r'r'r(r®^s     zJournalHandler.map_priority) r�r‘r’r“r¹ZNOTSETr£rGr¸Ú staticmethodr®Z mapPriorityr•r'r'rUr(r«øs 3 & r«)NNNN)DZ __future__rÚsysrHr0r"Zuuidr$Ú tracebackr�Úosr¦Zloggingr¹Zsyslogrrrrrrr r rIÚ collectionsr rJZ_journalrrrZ_readerrrrrrrrrrrrÚrrŒrÚtupler)r-r3r4r7r9r%r*r!rNrBrCrDrEr–rmr£rªZHandlerr«r'r'r'r(ÚsŠ (  4    ß$  ÿ 0,