Server IP : 85.214.239.14 / Your IP : 3.147.77.51 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/root/proc/3/task/3/root/proc/3/root/lib/python3/dist-packages/acme/ |
Upload File : |
"""ACME JSON fields.""" import datetime from typing import Any import logging import josepy as jose import pyrfc3339 logger = logging.getLogger(__name__) class Fixed(jose.Field): """Fixed field.""" def __init__(self, json_name: str, value: Any) -> None: self.value = value super().__init__( json_name=json_name, default=value, omitempty=False) def decode(self, value: Any) -> Any: if value != self.value: raise jose.DeserializationError('Expected {0!r}'.format(self.value)) return self.value def encode(self, value: Any) -> Any: if value != self.value: logger.warning( 'Overriding fixed field (%s) with %r', self.json_name, value) return value class RFC3339Field(jose.Field): """RFC3339 field encoder/decoder. Handles decoding/encoding between RFC3339 strings and aware (not naive) `datetime.datetime` objects (e.g. ``datetime.datetime.now(pytz.utc)``). """ @classmethod def default_encoder(cls, value: datetime.datetime) -> str: return pyrfc3339.generate(value) @classmethod def default_decoder(cls, value: str) -> datetime.datetime: try: return pyrfc3339.parse(value) except ValueError as error: raise jose.DeserializationError(error) def fixed(json_name: str, value: Any) -> Any: """Generates a type-friendly Fixed field.""" return Fixed(json_name, value) def rfc3339(json_name: str, omitempty: bool = False) -> Any: """Generates a type-friendly RFC3339 field.""" return RFC3339Field(json_name, omitempty=omitempty)