← Back
Editing: rebuild.cpython-38.pyc
U W[4$ � @ s� d Z ddlZddlZddlZddlZddlmZ zddlmZ W n ek rT Y nX ddl m Z mZ ddlm Z e�� add� ZG d d � d e�Zi Zdd� Zd d� ZG dd� de�Zdd� Zdd� Zddd�ZdS )z& *Real* reloading support for Python. � N)�reload)�InstanceType)�log�reflect)�_PY3c C s t tdd�}|dkrdS | |kS )a� Compare to types.ClassType in a py2/3-compatible way Python 2 used comparison to types.ClassType to check for old-style classes Python 3 has no concept of old-style classes, so if ClassType doesn't exist, it can't be an old-style class - return False in that case. Note that the type() of new-style classes is NOT ClassType, and so this should return False for new-style classes in python 2 as well. Z ClassTypeNF)�getattr�types)�tZ _ClassType� r �8/usr/lib/python3/dist-packages/twisted/python/rebuild.py�_isClassType s r c @ s, e Zd ZdZeZdd� Zdd� Zdd� ZdS ) � Sensitivez� A utility mixin that's sensitive to rebuilds. This is a mixin for classes (usually those which represent collections of callbacks) to make sure that their code is up-to-date before running. c C s | j t k }|S �N)�lastRebuild)�selfZynr r r �needRebuildUpdate= s zSensitive.needRebuildUpdatec C s t � � | _d S r )�timer �r r r r �rebuildUpToDateB s zSensitive.rebuildUpToDatec C s� t |�}|tjkrt|�S |tjkrL|jdkr<t|j|j�S t|j|j�S n:t sh|t krht|dd� |S t|�rxt|�S t �d� |S dS )z� Get the latest version of an object. This can handle just about anything callable; instances, functions, methods, and classes. NZnothingzwarning returning anObject!)�typer �FunctionType�latestFunction� MethodType�__self__r Zim_class�__name__r r r �latestClassr �msg)r ZanObjectr r r r �latestVersionOfF s zSensitive.latestVersionOfN)r � __module__�__qualname__�__doc__r r r r r r r r r 3 s r c C s, t | j�}t�|�}|dkr | S t|| j�S )z/ Get the latest version of a function. N)�id�__globals__� _modDictIDMap�getr r )ZoldFuncZdictID�moduler r r r a s r c C s� t �| j�}t|| j�}dd� |jD �}zt|�|_|W S tk r� |jdkrZ| Y S t|�}t |�rvt|dt�}||jt|�t |j�� Y S X dS )z, Get the latest version of a class. c S s g | ]}t |��qS r )r )�.0�baser r r � <listcomp>u s zlatestClass.<locals>.<listcomp>)Z__builtin__�builtinsZ __metaclass__N)r ZnamedModuler r r � __bases__�tuple� TypeErrorr r �dict�__dict__)ZoldClassr% ZnewClassZnewBasesZctorr r r r o s �r c @ s e Zd ZdZdS )�RebuildErrorzT Exception raised when trying to rebuild a class whereas it's not possible. N)r r r r r r r r r/ � s r/ c C s t | j�| _dS )z, Updates an instance to be current. N)r � __class__r r r r �updateInstance� s r1 c C s@ |dkrt d��t| � t�d�t�| j�|�� t| |�}|S )z< A getattr method to cause a class to be refreshed. �__del__zWithout this, Python segfaults.z#(rebuilding stale {} instance ({}))) �AttributeErrorr1 r r �formatr �qualr0 r )r �name�resultr r r �__injectedgetattr__� s � r8 � c C s� t � � at| d�r | js td��|r:t�d�t| j ��� ddl m} d|_| j }| tt|�<