�
H�g�� � � � d Z ddlmZ ddlZddlZ ej e� � ZddlZddl Z ddl
mZ ddlm
Z
ddlmZmZmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZ dd lm Z dd
l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/ g d�Z0 e1� � Z2d
� Z3 e4dg� � Z5 e6e7e7e7e3e7�� � Z8d� Z9e:dd�� � Z; e4ddg� � Z<dZ= G d� de1� � Z> G d� de1� � Z? G d� de1� � Z@ G d� de@� � ZAdS )z-passlib.context - CryptContext implementation� )�with_statementN)�warn)�exc)�ExpectedStringError�ExpectedTypeError�PasslibConfigWarning)�get_crypt_handler�_validate_handler_name)�handlers�to_bytes�
to_unicode�
splitcomma�as_bool�timer�rng�
getrandstr)�BASE64_CHARS)� iteritems� num_types�irange�PY2�PY3�unicode�SafeConfigParser�NativeStringIO�BytesIO�unicode_or_bytes_types�native_string_types)�deprecated_method�memoized_property)�CryptContext�LazyCryptContext�CryptPolicyc �� � | � d� � r%t | � d� � � � dz S t | � � S # t $ r t | � � cY S w xY w)z>parse vary_rounds string to percent as [0,1) float, or integer�%�{�G�z�?)�endswith�float�rstrip�int�
ValueError��values �_/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/passlib/context.py�_coerce_vary_roundsr/ * ss � ��~�~�c��� ,��U�\�\�#�&�&�'�'��+�+���5�z�z���� � � ��U�|�|�������s �A �A'�&A'�salt)�
min_rounds�
max_rounds�default_rounds�vary_rounds� salt_sizec �0 � t | j d� � | u S )z3detect if handler is registered or a custom handlerN)r �name��handlers r. �_is_handler_registeredr: C s � ��W�\�4�0�0�G�;�;� c � � dS )z
dummy function patched into handler.needs_update() by _CryptConfig
when hash alg has been deprecated for context.
T� )�hash�secrets r. �_always_needs_updater@ G s � � �4r; �truncate_errorr4 zaThe CryptPolicy class has been deprecated as of Passlib 1.6, and will be removed in Passlib 1.8. c �� � e Zd ZdZedd�� � Zedd�� � Zedd�� � Zedd�� � Zd � Z d
Z
dZd� Zd
� Z
d� Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd
S ) r# a
.. deprecated:: 1.6
This class has been deprecated, and will be removed in Passlib 1.8.
All of its functionality has been rolled into :class:`CryptContext`.
This class previously stored the configuration options for the
CryptContext class. In the interest of interface simplification,
all of this class' functionality has been rolled into the CryptContext
class itself.
The documentation for this class is now focused on documenting how to
migrate to the new api. Additionally, where possible, the deprecation
warnings issued by the CryptPolicy methods will list the replacement call
that should be used.
Constructors
============
CryptPolicy objects can be constructed directly using any of
the keywords accepted by :class:`CryptContext`. Direct uses of the
:class:`!CryptPolicy` constructor should either pass the keywords
directly into the CryptContext constructor, or to :meth:`CryptContext.update`
if the policy object was being used to update an existing context object.
In addition to passing in keywords directly,
CryptPolicy objects can be constructed by the following methods:
.. automethod:: from_path
.. automethod:: from_string
.. automethod:: from_source
.. automethod:: from_sources
.. automethod:: replace
Introspection
=============
All of the informational methods provided by this class have been deprecated
by identical or similar methods in the :class:`CryptContext` class:
.. automethod:: has_schemes
.. automethod:: schemes
.. automethod:: iter_handlers
.. automethod:: get_handler
.. automethod:: get_options
.. automethod:: handler_is_deprecated
.. automethod:: get_min_verify_time
Exporting
=========
.. automethod:: iter_config
.. automethod:: to_dict
.. automethod:: to_file
.. automethod:: to_string
.. note::
CryptPolicy are immutable.
Use the :meth:`replace` method to mutate existing instances.
.. deprecated:: 1.6
�passlib�utf-8c � � t t dz t d�� � | t � |||� � �� � S )aW create a CryptPolicy instance from a local file.
.. deprecated:: 1.6
Creating a new CryptContext from a file, which was previously done via
``CryptContext(policy=CryptPolicy.from_path(path))``, can now be
done via ``CryptContext.from_path(path)``.
See :meth:`CryptContext.from_path` for details.
Updating an existing CryptContext from a file, which was previously done
``context.policy = CryptPolicy.from_path(path)``, can now be
done via ``context.load_path(path)``.
See :meth:`CryptContext.load_path` for details.
z�Instead of ``CryptPolicy.from_path(path)``, use ``CryptContext.from_path(path)`` or ``context.load_path(path)`` for an existing CryptContext.� ��
stacklevel��_internal_context)r � _preamble�DeprecationWarningr! � from_path)�cls�path�section�encodings r. rM zCryptPolicy.from_path� sj � �
�Y�M�M� �A� /� /� /� /�
�s�\�%;�%;�D�'�<D�&F� &F� G� G� G� Gr; c � � t t dz t d�� � | t � |||� � �� � S )aU create a CryptPolicy instance from a string.
.. deprecated:: 1.6
Creating a new CryptContext from a string, which was previously done via
``CryptContext(policy=CryptPolicy.from_string(data))``, can now be
done via ``CryptContext.from_string(data)``.
See :meth:`CryptContext.from_string` for details.
Updating an existing CryptContext from a string, which was previously done
``context.policy = CryptPolicy.from_string(data)``, can now be
done via ``context.load(data)``.
See :meth:`CryptContext.load` for details.
z�Instead of ``CryptPolicy.from_string(source)``, use ``CryptContext.from_string(source)`` or ``context.load(source)`` for an existing CryptContext.rF rG rI )r rK rL r! �from_string)rN �sourcerP rQ s r. rS zCryptPolicy.from_string� sj � �
�Y�F�F� �A� /� /� /� /�
�s�\�%=�%=�f�g�>F�&H� &H� I� I� I� Ir; Tc �0 �� |rt t dz t d�� � t �t � � r�S t �t
� � r | t
d
i ����� � S t �t t f� � st dt �� � ��� � �t �fd�dD � � � � s�� d� � s$ | t �
�� � �� � S | t � �� � �� � S )a� create a CryptPolicy instance from some source.
this method autodetects the source type, and invokes
the appropriate constructor automatically. it attempts
to detect whether the source is a configuration string, a filepath,
a dictionary, or an existing CryptPolicy instance.
.. deprecated:: 1.6
Create a new CryptContext, which could previously be done via
``CryptContext(policy=CryptPolicy.from_source(source))``, should
now be done using an explicit method: the :class:`CryptContext`
constructor itself, :meth:`CryptContext.from_path`,
or :meth:`CryptContext.from_string`.
Updating an existing CryptContext, which could previously be done via
``context.policy = CryptPolicy.from_source(source)``, should
now be done using an explicit method: :meth:`CryptContext.update`,
or :meth:`CryptContext.load`.
z�Instead of ``CryptPolicy.from_source()``, use ``CryptContext.from_string(path)`` or ``CryptContext.from_path(source)``, as appropriate.rF rG rI z?source must be CryptPolicy, dict, config string, or file path: c 3 � �K � | ]}|�v V � � d S �Nr= )�.0�crT s �r. � <genexpr>z*CryptPolicy.from_source.<locals>.<genexpr>� s'