| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/IPython/utils/__pycache__/ |
Upload File : |
�
}�eP. � �$ � d Z dgZ G d� de� Zy)z�A dict subclass that supports attribute style access.
Authors:
* Fernando Perez (original)
* Brian Granger (refactoring to a dict subclass)
�Structc �l � e Zd ZdZdZd� Zd� Zd� Zd� Zd� Z d� Z
d � Zd
� Zd� Z
d� Zd
� Zd� Zdd�Zdd�Zy)r aY A dict subclass with attribute style access.
This dict subclass has a a few extra features:
* Attribute style access.
* Protection of class members (like keys, items) when using attribute
style access.
* The ability to restrict assignment to only existing keys.
* Intelligent merging.
* Overloaded operators.
Tc �d � t j | dd� t j | g|��i |�� y)a� Initialize with a dictionary, another Struct, or data.
Parameters
----------
*args : dict, Struct
Initialize with one dict or Struct
**kw : dict
Initialize with key, value pairs.
Examples
--------
>>> s = Struct(a=10,b=30)
>>> s.a
10
>>> s.b
30
>>> s2 = Struct(s,c=30)
>>> sorted(s2.keys())
['a', 'b', 'c']
� _allownewTN)�object�__setattr__�dict�__init__)�self�args�kws �8/usr/lib/python3/dist-packages/IPython/utils/ipstruct.pyr zStruct.__init__) s, � �* ���4��d�3��
�
�d�(�T�(�R�(� c �n � | j s|| vrt d|z � �t j | ||� y)az Set an item with check for allownew.
Examples
--------
>>> s = Struct()
>>> s['a'] = 10
>>> s.allow_new_attr(False)
>>> s['a'] = 10
>>> s['a']
10
>>> try:
... s['b'] = 20
... except KeyError:
... print('this is not allowed')
...
this is not allowed
z8can't create new attribute %s when allow_new_attr(False)N)r �KeyErrorr �__setitem__)r
�key�values r
r zStruct.__setitem__A s: � �$ �~�~�#�T�/��J�S�P�R�
R�����s�E�*r c �� � t |t � r,|| j v st t |� rt d|z � � | j
||� y# t $ r}t |� |�d}~ww xY w)a� Set an attr with protection of class members.
This calls :meth:`self.__setitem__` but convert :exc:`KeyError` to
:exc:`AttributeError`.
Examples
--------
>>> s = Struct()
>>> s.a = 10
>>> s.a
10
>>> try:
... s.get = 10
... except AttributeError:
... print("you can't set a class member")
...
you can't set a class member
z.attr %s is a protected member of class Struct.N)�
isinstance�str�__dict__�hasattrr �AttributeErrorr r )r
r r �es r
r zStruct.__setattr__X sl � �( �c�3��
�d�m�m�#�w�v�s�';�$�D�s�J�� � +����S�%�(��� +� ��#��*�� +�s �A � A+�A&�&A+c �L � | | }|S # t $ r}t |� |�d}~ww xY w)a� Get an attr by calling :meth:`dict.__getitem__`.
Like :meth:`__setattr__`, this method converts :exc:`KeyError` to
:exc:`AttributeError`.
Examples
--------
>>> s = Struct(a=10)
>>> s.a
10
>>> type(s.get)
<...method'>
>>> try:
... s.b
... except AttributeError:
... print("I don't have that key")
...
I don't have that key
N)r r )r
r �resultr s r
�__getattr__zStruct.__getattr__z s6 � �( ��#�Y�F� �M�� � -� ��%�1�,�� -�s � � #��#c �( � | j |� | S )z�s += s2 is a shorthand for s.merge(s2).
Examples
--------
>>> s = Struct(a=10,b=30)
>>> s2 = Struct(a=20,c=40)
>>> s += s2
>>> sorted(s.keys())
['a', 'b', 'c']
)�merge)r
�others r
�__iadd__zStruct.__iadd__� s � �
�
�
�5���r c �H � | j � }|j |� |S )z�s + s2 -> New Struct made from s.merge(s2).
Examples
--------
>>> s1 = Struct(a=10,b=30)
>>> s2 = Struct(a=20,c=40)
>>> s = s1 + s2
>>> sorted(s.keys())
['a', 'b', 'c']
)�copyr �r
r �souts r
�__add__zStruct.__add__� s � � �y�y�{���
�
�5���r c �0 � | j � }||z }|S )z�s1 - s2 -> remove keys in s2 from s1.
Examples
--------
>>> s1 = Struct(a=10,b=30)
>>> s2 = Struct(a=40)
>>> s = s1 - s2
>>> s
{'b': 30}
)r# r$ s r
�__sub__zStruct.__sub__� s � � �y�y�{����
���r c �@ � |j � D ]
}|| v s�| |= � | S )z�Inplace remove keys from self that are in other.
Examples
--------
>>> s1 = Struct(a=10,b=30)
>>> s2 = Struct(a=40)
>>> s1 -= s2
>>> s1
{'b': 30}
)�keys)r
r �ks r
�__isub__zStruct.__isub__� s. � � ���� �A��D�y���G� � �r c � � i }|j � D ]1 \ }}t |t � r|j � }|D ] }|||<