Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/IPython/utils/__pycache__/ipstruct.cpython-39.pyc
Ðазад
a o�hP. � @ s d Z dgZG dd� de�ZdS )z�A dict subclass that supports attribute style access. Authors: * Fernando Perez (original) * Brian Granger (refactoring to a dict subclass) �Structc @ s� e Zd ZdZdZdd� Zdd� Zdd� Zd d � Zdd� Z d d� Z dd� Zdd� Zdd� Z dd� Zdd� Zdd� Zd dd�Zd!dd�ZdS )"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 O s* t �| dd� tj| g|�R i |�� dS )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�kw� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/IPython/utils/ipstruct.pyr ) s zStruct.__init__c C s, | j s|| vrtd| ��t�| ||� dS )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�valuer r r r A s �zStruct.__setitem__c C sn t |t�r*|| jv stt|�r*td| ��z| �||� W n. tyh } zt|�|�W Y d}~n d}~0 0 dS )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 �er r r r X s �zStruct.__setattr__c C sD z| | }W n. t y: } zt|�|�W Y d}~nd}~0 0 |S dS )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 r r r �__getattr__z s zStruct.__getattr__c C s | � |� | 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 �otherr r r �__iadd__� s zStruct.__iadd__c C s | � � }|�|� |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 Zsoutr r r �__add__� s zStruct.__add__c C s | � � }||8 }|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 r r r �__sub__� s zStruct.__sub__c C s |� � D ]}|| v r| |= q| 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 �kr r r �__isub__� s zStruct.__isub__c C s>