Current File : //proc/self/root/lib/python3/dist-packages/twisted/spread/__pycache__/pb.cpython-312.pyc
�

Ϫ�f_���8�dZddlZddlmZddlmZmZddlmZm	Z	m
Z
mZddlm
Z
ddlmZmZddlmZdd	lmZmZmZdd
lmZmZddlmZddlmZdd
lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddl3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:dZ;dZ<Gd�de=�Z>Gd�de>�Z?Gd�de=�Z@Gd�de=�ZAeGd�d��ZBGd�de=�ZCGd�de�ZDeeD�Gd �d!��ZEGd"�d#e$�ZFee5�eGd$�d%e)ej����ZHe1d&eH�Gd'�d(�ZIGd)�d*ej�e �ZKGd+�d,e'ej��ZLe1eKeL�dAd-�ZMGd.�d/ej��ZOd0�ZPd1�ZQGd2�d3ej��ZSGd4�d5ej��ZUGd6�d7e
�ZVee!�Gd8�d9��ZWeeWe
e!�Gd:�d;�ZXGd<�d=e$eX�ZYeeeV�Gd>�d?e$eX��ZZgd@�Z[y)Ba�
Perspective Broker

"This isn't a professional opinion, but it's probably got enough
internet to kill you." --glyph

Introduction
============

This is a broker for proxies for and copies of objects.  It provides a
translucent interface layer to those proxies.

The protocol is not opaque, because it provides objects which represent the
remote proxies and require no context (server references, IDs) to operate on.

It is not transparent because it does I{not} attempt to make remote objects
behave identically, or even similarly, to local objects.  Method calls are
invoked asynchronously, and specific rules are applied when serializing
arguments.

To get started, begin with L{PBClientFactory} and L{PBServerFactory}.

@author: Glyph Lefkowitz
�N)�md5)�	Interface�implementer)�	Anonymous�
IAnonymous�ICredentials�IUsernameHashedPassword)�Portal)�defer�protocol)�styles)�failure�log�reflect)�cmp�
comparable)�registerAdapter)�banana)�	Cacheable�Copyable�IPBRoot�	Jellyable�NoSuchMethod�
Referenceable�RemoteCache�RemoteCacheObserver�
RemoteCopy�Root�Serializable�Viewable�	ViewPoint�copyTags�setCopierForClass�setCopierForClassTree�setFactoryForClass�setUnjellyableFactoryForClass�setUnjellyableForClass�setUnjellyableForClassTree)�
IJellyable�IUnjellyable)�_newInstance�globalSecurity�jelly�unjellyiiS"c��eZdZdZy)�
ProtocolErrorzN
    This error is raised when an invalid protocol statement is received.
    N��__name__�
__module__�__qualname__�__doc__���3/usr/lib/python3/dist-packages/twisted/spread/pb.pyr0r0Ts��r7r0c��eZdZdZy)�DeadReferenceErrorzx
    This error is raised when a method is called on a dead reference (one whose
    broker has been disconnected).
    Nr1r6r7r8r:r:Zs��r7r:c��eZdZdZy)�Errora 
    This error can be raised to generate known error conditions.

    When a PB callable method (perspective_, remote_, view_) raises
    this error, it indicates that a traceback should not be printed,
    but instead, the string representation of the exception should be
    sent.
    Nr1r6r7r8r<r<as��r7r<c��eZdZdZd�Zy)�RemoteErrora�
    This class is used to wrap a string-ified exception from the remote side to
    be able to reraise it. (Raising string exceptions is no longer possible in
    Python 2.6+)

    The value of this exception will be a str() representation of the remote
    value.

    @ivar remoteType: The full import path of the exception class which was
        raised on the remote end.
    @type remoteType: C{str}

    @ivar remoteTraceback: The remote traceback.
    @type remoteTraceback: C{str}

    @note: It's not possible to include the remoteTraceback if this exception is
        thrown into a generator. It must be accessed as an attribute.
    c�L�tj||�||_||_y�N)�	Exception�__init__�
remoteType�remoteTraceback)�selfrC�valuerDs    r8rBzRemoteError.__init__�s!�����4��'�$���.��r7N�r2r3r4r5rBr6r7r8r>r>ls���&/r7r>c�(�eZdZdZd�Zd�Zd�Zd�Zy)�RemoteMethodz>
    This is a translucent reference to a remote message.
    c� �||_||_y)zT
        Initialize with a L{RemoteReference} and the name of this message.
        N)�obj�name)rErKrLs   r8rBzRemoteMethod.__init__�s�������	r7c�F�t|j|jf|�Sr@)rrKrL�rE�others  r8�__cmp__zRemoteMethod.__cmp__�s���D�H�H�d�i�i�(�%�0�0r7c�D�t|j|jf�Sr@)�hashrKrL�rEs r8�__hash__zRemoteMethod.__hash__�s���T�X�X�t�y�y�)�*�*r7c���|jjjd|jj|jj|j
j
d�||�S)z8
        Asynchronously invoke a remote method.
        r7�utf-8)rK�broker�_sendMessage�perspective�luidrL�encode)rE�args�kws   r8�__call__zRemoteMethod.__call__�sR���x�x���+�+���H�H� � ��H�H�M�M��I�I���W�%���

�	
r7N)r2r3r4r5rBrPrTr^r6r7r8rIrI�s����1�+�
r7rIc��eZdZy)�PBConnectionLostN)r2r3r4r6r7r8r`r`�s��r7r`c��eZdZdZd�Zy)�IPerspectivea
    per*spec*tive, n. : The relationship of aspects of a subject to each
    other and to a whole: 'a perspective of history'; 'a need to view
    the problem in the proper perspective'.

    This is a Perspective Broker-specific wrapper for an avatar. That
    is to say, a PB-published view on to the business logic for the
    system's concept of a 'user'.

    The concept of attached/detached is no longer implemented by the
    framework. The realm is expected to implement such semantics if
    needed.
    c��y)a�
        This method is called when a network message is received.

        @arg broker: The Perspective Broker.

        @type message: str
        @arg message: The name of the method called by the other end.

        @type args: list in jelly format
        @arg args: The arguments that were passed by the other end. It
                   is recommend that you use the `unserialize' method of the
                   broker to decode this.

        @type kwargs: dict in jelly format
        @arg kwargs: The keyword arguments that were passed by the
                     other end.  It is recommended that you use the
                     `unserialize' method of the broker to decode this.

        @rtype: A jelly list.
        @return: It is recommended that you use the `serialize' method
                 of the broker on whatever object you need to return to
                 generate the return value.
        Nr6)rW�messager\�kwargss    r8�perspectiveMessageReceivedz'IPerspective.perspectiveMessageReceived���r7N�r2r3r4r5rfr6r7r8rbrb�s���r7rbc��eZdZdZd�Zy)�Avatara
    A default IPerspective implementor.

    This class is intended to be subclassed, and a realm should return
    an instance of such a subclass when IPerspective is requested of
    it.

    A peer requesting a perspective will receive only a
    L{RemoteReference} to a pb.Avatar.  When a method is called on
    that L{RemoteReference}, it will translate to a method on the
    remote perspective named 'perspective_methodname'.  (For more
    information on invoking methods on other objects, see
    L{flavors.ViewPoint}.)
    c��|j||�}|j||�}t|d|z�}	||i|��}|j|||||�S#t$rtj|�d|�d|����wxYw)ai
        This method is called when a network message is received.

        This will call::

            self.perspective_%(message)s(*broker.unserialize(args),
                                         **broker.unserialize(kw))

        to handle the method; subclasses of Avatar are expected to
        implement methods using this naming convention.
        zperspective_%sz didn't accept z and )�unserialize�getattr�	TypeErrorr�msg�	serialize)rErWrdr\r]�method�states       r8rfz!Avatar.perspectiveMessageReceived�s����!�!�$��-��
�
�
��D�
)����/�'�9�:��	��D�'�B�'�E�����t�V�T�2�>�>���	��G�G�v�h�o�d�V�5���=�>��	�s�A�(A:Nrhr6r7r8rjrj�s��
�?r7rjc��eZdZdZdd�Zy)�AsReferenceablez6
    A reference directed towards another object.
    c�,�t||dz�|_y)N�MessageReceived)rm�remoteMessageReceived)rE�object�messageTypes   r8rBzAsReferenceable.__init__s��%,�V�[�CT�5T�%U��"r7N)�remoterGr6r7r8rtrt�s
���Vr7rtc�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�RemoteReferencea]
    A translucent reference to a remote object.

    I may be a reference to a L{flavors.ViewPoint}, a
    L{flavors.Referenceable}, or an L{IPerspective} implementer (e.g.,
    pb.Avatar).  From the client's perspective, it is not possible to
    tell which except by convention.

    I am a "translucent" reference because although no additional
    bookkeeping overhead is given to the application programmer for
    manipulating a reference, return values are asynchronous.

    See also L{twisted.internet.defer}.

    @ivar broker: The broker I am obtained through.
    @type broker: L{Broker}
    c�J�||_||_||_||_g|_y)z�(internal) Initialize me with a broker and a locally-unique ID.

        The ID is unique only to the particular Perspective Broker
        instance.
        N)rZrW�
doRefCountrY�disconnectCallbacks)rErYrWrZr~s     r8rBzRemoteReference.__init__s)����	����$���&���#%�� r7c���t|�sJ�|jj|�t|j�dk(r&|jj|j�yy)z�
        Register a callback to be called if our broker gets disconnected.

        @param callback: a callable which will be called with one
                         argument, this instance.
        �N)�callabler�append�lenrW�notifyOnDisconnect�
_disconnected�rE�callbacks  r8r�z"RemoteReference.notifyOnDisconnect'sV����!�!�!�� � �'�'��1��t�'�'�(�A�-��K�K�*�*�4�+=�+=�>�.r7c��|jj|�|js&|jj|j�yy)zu
        Remove a callback that was registered with notifyOnDisconnect.

        @param callback: a callable
        N)r�removerW�dontNotifyOnDisconnectr�r�s  r8r�z&RemoteReference.dontNotifyOnDisconnect3s>��	
� � �'�'��1��'�'��K�K�.�.�t�/A�/A�B�(r7c�D�|jD]
}||��d|_y)zN
        Called if we are disconnected and have callbacks registered.
        N)rr�s  r8r�zRemoteReference._disconnected=s(���0�0�	�H��T�N�	�#'�� r7c�x�|jr.|j|jk(sJd��d|jfSy)zc
        If I am being sent back to where I came from, serialize as a local backreference.
        z6Can't send references to brokers other than their own.slocal)s
unpersistablezReferences cannot be serialized)�invokerrWrZ)rE�jelliers  r8�jellyForzRemoteReference.jellyForEs?���?�?����w���.�
H�G�
H�.��T�Y�Y�&�&�Fr7c�p�|j|jj|j|dd�|S)Nr�)rBr��unserializingPerspective)rE�	unjellier�unjellyLists   r8�
unjellyForzRemoteReference.unjellyForQs7���
�
����6�6������N�
�		
��r7c��t|t�s|jd�}|jj	d|j
|j|||�S)a�
        Asynchronously invoke a remote method.

        @type _name: L{str}
        @param _name:  the name of the remote method to invoke
        @param args: arguments to serialize for the remote function
        @param kw:  keyword arguments to serialize for the remote function.
        @rtype:   L{twisted.internet.defer.Deferred}
        @returns: a Deferred which will be fired when the result of
                  this remote call is received.
        �utf8r7)�
isinstance�bytesr[rWrXrYrZ)rE�_namer\r]s    r8�
callRemotezRemoteReference.callRemoteZsL���%��'��L�L��(�E�
�{�{�'�'���!�!�4�9�9�e�T�2�
�	
r7c��t||�S)zX

        @param key: The key.
        @return: A L{RemoteMethod} for this key.
        )rI)rE�keys  r8�remoteMethodzRemoteReference.remoteMethodps���D�#�&�&r7c��t|t�r9|j|jk(r t|j|j�St|j|�S)zM

        @param other: another L{RemoteReference} to compare me to.
        )r�r|rWrrZrNs  r8rPzRemoteReference.__cmp__xsD��
�e�_�-��|�|�t�{�{�*��4�9�9�e�j�j�1�1��4�;�;��&�&r7c��|jS)z
        Hash me.
        )rZrSs r8rTzRemoteReference.__hash__�s���y�y�r7c�h�|jr&|jj|j�yy)zD
        Do distributed reference counting on finalization.
        N)r~rW�
sendDecRefrZrSs r8�__del__zRemoteReference.__del__�s&���?�?��K�K�"�"�4�9�9�-�r7N)r2r3r4r5rBr�r�r�r�r�r�r�rPrTr�r6r7r8r|r|s@���$
&�
?�C�(�
G��
�,'�'��.r7r|rzc�0�eZdZdZdd�Zdefd�Zd�Zd�Zy)	�Localz3
    (internal) A reference to a local object.
    Nc�.�||_||_d|_y)z
        Initialize.
        r�N)rxrY�refcount)rErxrYs   r8rBzLocal.__init__�s�����&�����
r7�returnc�<�d|j�d|j�d�S)Nz
<pb.Local z ref:�>)rxr�rSs r8�__repr__zLocal.__repr__�s���D�K�K�?�%��
�
��a�@�@r7c�B�|jdz|_|jS)zi
        Increment the reference count.

        @return: the reference count after incrementing
        r��r�rSs r8�increfzLocal.incref�����
�
��)��
��}�}�r7c�B�|jdz
|_|jS)zi
        Decrement the reference count.

        @return: the reference count after decrementing
        r�r�rSs r8�decrefzLocal.decref�r�r7r@)	r2r3r4r5rB�strr�r�r�r6r7r8r�r��s$����A�#�A��r7r�c��eZdZdZdZd�Zy)�CopyableFailurez}
    A L{flavors.RemoteCopy} and L{flavors.Copyable} version of
    L{twisted.python.failure.Failure} for serialization.
    rc��|jj�}d|d<g|d<g|d<t|j�|d<t	|j
t�r|j
|d<n1tj|j
�jd�|d<|jr|j�|d<|Sd	|d<|S)
z�
        Collect state related to the exception which occurred, discarding
        state which cannot reasonably be serialized.
        N�tb�frames�stackrF�typerV�	tracebackzTraceback unavailable
)�__dict__�copyr�rFr�r�r�r�qualr[�unsafeTracebacks�getTraceback)rErrs  r8�getStateToCopyzCopyableFailure.getStateToCopy�s���
�
�
�"�"�$����d����h����g���T�Z�Z���g���d�i�i��'� �I�I�E�&�M�#�L�L����3�:�:�7�C�E�&�M�� � �!%�!2�!2�!4�E�+����";�E�+���r7N)r2r3r4r5r�r�r6r7r8r�r��s���
��r7r�c�&�eZdZdZdd�Zd�ZeZeZy)�
CopiedFailurea�
    A L{CopiedFailure} is a L{pb.RemoteCopy} of a L{failure.Failure}
    transferred via PB.

    @ivar type: The full import path of the exception class which was raised on
        the remote end.
    @type type: C{str}

    @ivar value: A str() representation of the remote value.
    @type value: L{CopiedFailure} or C{str}

    @ivar traceback: The remote traceback.
    @type traceback: C{str}
    Nc��|�tj}|j}t|t�s|jd�}|j
d�|j
|dz|jz�|j
d�y)NrVzTraceback from remote host -- z: �
)r�logfiler�r�r��decode�writerF)rE�file�elideFrameworkCode�detail�failureTypes     r8�printTracebackzCopiedFailure.printTraceback�sf���<��;�;�D��i�i���+�s�+�%�,�,�W�5�K��
�
�3�4��
�
�;��%��
�
�2�3��
�
�4�r7c�v�|jt|j|j|j��S)a�
        Throw the original exception into the given generator, preserving
        traceback information if available. In the case of a L{CopiedFailure}
        where the exception type is a string, a L{pb.RemoteError} is thrown
        instead.

        @return: The next value yielded from the generator.
        @raise StopIteration: If there are no more values in the generator.
        @raise RemoteError: The wrapped remote exception.
        )�throwr>r�rFr�)rE�gs  r8�throwExceptionIntoGeneratorz)CopiedFailure.throwExceptionIntoGenerator�s(���w�w�{�4�9�9�d�j�j�$�.�.�I�J�Jr7)Nr�default)r2r3r4r5r�r��printBriefTraceback�printDetailedTracebackr6r7r8r�r��s ��
��K�)��+�r7r�c�H�tt|j�}||_|Sr@)r+r�r�r�)�failr��fs   r8�failure2Copyabler�s���_�d�m�m�4�A�)�A���Hr7c�8�eZdZdZdZdZdZdefd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�ZdZd�Zd�Zd�Zd�Zd�Zd�ZdZd�Zd�Zd�Zd2d�Zd�Zd�Z d�Z!d�Z"d3d�Z#d4d �Z$d!�Z%d"�Z&d#�Z'd$�Z(d%�Z)d&�Z*d'�Z+d(�Z,d)�Z-d*�Z.d+�Z/d,�Z0d-�Z1d.�Z2d/�Z3d0�Z4d1�Z5y)5�Brokerz$
    I am a broker for objects.
    �Nr�c�$�tjj||�d|_g|_g|_g|_i|_||_g|_	d|_
d|_d|_i|_
i|_i|_i|_i|_i|_y�Nr)r�BananarB�disconnected�disconnects�failures�connects�localObjects�security�
pageProducers�currentRequestID�currentLocalIDr��luids�remotelyCachedObjects�remotelyCachedLUIDs�locallyCachedObjects�waitingForAnswers�
_localCleanup)rE�isClientr�s   r8rBzBroker.__init__s����
�
���t�X�.���������
���
���� ��
���� !������(,��%���
�&(��"�#%�� �$&��!�!#���
 ��r7c��tt|j�dz
dd�D]?}|j|}|j�|j	�r�3|j|=�A|js|j
j
�yy)zM
        Called when the consumer attached to me runs out of buffer.
        r����N)�ranger�r��sendNextPage�stillPaging�	transport�unregisterProducer)rE�pageridx�pagers   r8�resumeProducingzBroker.resumeProducing7s���
�c�$�"4�"4�5��9�2�r�B�	1�H��&�&�x�0�E���� ��$�$�&��&�&�x�0�		1�
�!�!��N�N�-�-�/�"r7c��yr@r6rSs r8�pauseProducingzBroker.pauseProducingD���r7c��yr@r6rSs r8�
stopProducingzBroker.stopProducingHr�r7c��|jj|�t|j�dk(r|jj	|d�yy)Nr�r)r�r�r�r��registerProducer)rEr�s  r8�registerPageProducerzBroker.registerPageProducerLsB�����!�!�%�(��t�!�!�"�a�'��N�N�+�+�D�!�4�(r7c���t|t�rV|d}t|t�s|jd�}d|z}t	||d�}|r	||dd�y|jd|�yt
d��)z:
        Evaluate an expression as it's received.
        rr�zproto_%sNr�sdidNotUnderstandzNon-list expression received.)r��listr�r�rm�sendCallr0)rE�sexp�command�
methodNamerqs     r8�expressionReceivedzBroker.expressionReceivedQss���d�D�!��1�g�G��g�s�+�!�.�.��0��#�g�-�J��T�:�t�4�F����Q�R��!��
�
�1�7�;�� ?�@�@r7c�X�||jk7rtd|j�d|����y)z�
        Protocol message: (version version-number)

        Check to make sure that both ends of the protocol are speaking
        the same version dialect.

        @param vnum: The version number.
        zVersion Incompatibility: � N)�versionr0)rE�vnums  r8�
proto_versionzBroker.proto_versiones2���4�<�<���";�D�L�L�>��4�&� Q�R�R� r7c�&�|j|�y)z�
        Utility method to send an expression to the other side of the connection.

        @param exp: The expression.
        N)�sendEncoded)rE�exps  r8rzBroker.sendCallrs��	
����r7c�4�tjd|z�y)a 
        Respond to stock 'C{didNotUnderstand}' message.

        Log the command that was not understood and continue. (Note:
        this will probably be changed to close the connection or raise
        an exception in the future.)

        @param command: The command to log.
        zDidn't understand command: %rN)rro)rErs  r8�proto_didNotUnderstandzBroker.proto_didNotUnderstandzs��	���/�'�9�:r7c��|jd|j�|jD]
}	|��d|_|jj|�y#t$rt	j
�Y�OwxYw)zF
        Initialize. Called after Banana negotiation is done.
        sversionN)rr	r��
BaseExceptionr�deferr�factory�clientConnectionMade�rE�notifiers  r8�connectionReadyzBroker.connectionReady�sh��	
�
�
�j�$�,�,�/��
�
�	�H�
��
�	�
��
����)�)�$�/��!�
��
�
��
�s�A�A9�8A9c��|jD]
}	|��d|_y#t$rtj�Y�4wxYwr@)r�rrrrs  r8�connectionFailedzBroker.connectionFailed�sB���
�
�	�H�
��
�	�
��
��!�
��
�
��
�s�"�A�Ac	��d|_d|_|jrM|jj�D]0}	|j	tjt|����2|jj�D]8}|j}|j}	|j|t|||���:|j ddD]
}	|��d|_d|_d|_d|_d|_d|_d|_d|_y#t$rtj�Y��wxYw#t$rtj�Y��wxYw#t$rtj�Y��wxYw)zg
        The connection was lost.

        @param reason: message to put in L{failure.Failure}
        r�N)r�r�r��values�errbackr�Failurer`rrrr�rxrY�stoppedObservingrr��
localSecurity�remoteSecurityr�r�r�)rE�reason�d�lobj�	cacheablerYrs       r8�connectionLostzBroker.connectionLost�sd�������
��!�!��+�+�2�2�4�
!��!��I�I�g�o�o�.>�v�.F�G�H�
!��.�.�5�5�7�	�D����I��*�*�K�
��*�*��!4�T�9�k�!R��		��(�(��+�	�H�
��
�	�
 ���!%���!���"���%)��"�#'�� �$(��!� ����5%�!��J�J�L�!��!�
��
�
��
��!�
��
�
��
�s5�-D�D5�E�D2�1D2�5E�E�E8�7E8c�T�t|�sJ�|jj|�y)zQ

        @param notifier: callback to call when the Broker disconnects.
        N)r�r�r�rs  r8r�zBroker.notifyOnDisconnect�s&��
��!�!�!�������)r7c�T�t|�sJ�|jj|�y)zT

        @param notifier: callback to call if the Broker fails to connect.
        N)r�r�r�rs  r8�notifyOnFailzBroker.notifyOnFail�s$��
��!�!�!��
�
���X�&r7c���t|�sJ�|j�		|�y|jj|�y#t$rtj�YywxYw)zN

        @param notifier: callback to call when the Broker connects.
        N)r�r�rr�errr�rs  r8�notifyOnConnectzBroker.notifyOnConnect�sT��
��!�!�!��=�=� �
��
�
�M�M� � ��*��!�
����	�
�s�?�A�Ac�Z�	|jj|�y#t$rYywxYw)zY

        @param notifier: callback to remove from list of disconnect callbacks.
        N)r�r��
ValueErrorrs  r8r�zBroker.dontNotifyOnDisconnect�s-��
	����#�#�H�-���	��	�s��	*�*c��t|t�r|jd�}|jj	|�}|�y|j
S)z�
        Get a local object for a locally unique ID.

        @return: An object previously stored with L{registerReference} or
            L{None} if there is no object which corresponds to the given
            identifier.
        r�N)r�r�r[r��getrx)rErZ�lobs   r8�localObjectForIDzBroker.localObjectForID�sD���d�C� ��;�;�v�&�D����#�#�D�)���;���z�z�r7rc���|�J�|j�}|jj|�}|��t|j�t
kDrS|jdz|_|jdkDr%|jj�td��td��|j�}t|�|j|<||j|<|S|j|j�|S)z�
        Store a persistent reference to a local object and map its
        id() to a generated, session-unique ID.

        @param object: a local object
        @return: the generated ID
        r��z.Maximum PB reference count exceeded.  Goodbye.z$Maximum PB reference count exceeded.)
�processUniqueIDr�r0r�r��MAX_BROKER_REFS�maxBrokerRefsViolationsr��loseConnectionr<�
newLocalIDr�r�)rErx�puidrZs    r8�registerReferencezBroker.registerReferences����!�!�!��%�%�'���z�z�~�~�d�#���<��4�$�$�%��7�/3�/K�/K�a�/O��,��/�/�!�3��N�N�1�1�3�� S�T�T��B�C�C��?�?�$�D�&+�F�m�D���d�#�#�D�J�J�t����
���d�#�*�*�,��r7c�~�t|t�r|jd�}|�J�t|�|j|<y)z�
        Store a special (string) ID for this object.

        This is how you specify a 'base' set of objects that the remote
        protocol can connect to.

        @param name: An ID.
        @param object: The object.
        r�N)r�r�r[r�r�)rErLrxs   r8�setNameForLocalzBroker.setNameForLocals<���d�C� ��;�;�v�&�D��!�!�!�"'��-����$�r7c�`�t|t�r|jd�}td||d�S)a
        Returns an object from the remote name mapping.

        Note that this does not check the validity of the name, only
        creates a translucent reference for it.

        @param name: The name to look up.
        @return: An object which maps to the name.
        r�Nr)r�r�r[r|)rErLs  r8�
remoteForNamezBroker.remoteForName,s-���d�C� ��;�;�v�&�D��t�T�4��3�3r7c��|j�}|jj|�}|�|r|j|j	�|S)a

        @param instance: The instance to look up.
        @param incref: Flag to specify whether to increment the
                       reference.
        @return: An ID that says what this instance is cached as
                 remotely, or L{None} if it's not.
        )r5r�r0r�r�)rE�instancer�r:rZs     r8�cachedRemotelyAszBroker.cachedRemotelyAs;sL���'�'�)���'�'�+�+�D�1����6��&�&�t�,�3�3�5��r7c�4�|j|jS)zk

        @param luid: The LUID to look up.
        @return: An instance which is cached remotely.
        )r�rx)rErZs  r8�remotelyCachedForLUIDzBroker.remotelyCachedForLUIDKs���)�)�$�/�6�6�6r7c��|j�}|j�}t|j�tkDrS|j
dz|_|j
dkDr%|jj�td��td��||j|<t||j�|j|<|S)z3
        XXX

        @return: A new LUID.
        r�r4z*Maximum PB cache count exceeded.  Goodbye.z Maximum PB cache count exceeded.)r5r9r�r�r6r7r�r8r<r�r��serializingPerspective)rErAr:rZs    r8�
cacheRemotelyzBroker.cacheRemotelySs����'�'�)����� ���t�)�)�*�_�<�+/�+G�+G�!�+K�D�(��+�+�a�/����-�-�/��K�L�L��:�;�;�)-�� � ��&�,1��4�;V�;V�+W��"�"�4�(��r7c�"�||j|<y)zL(internal)

        Store a non-filled-out cached instance locally.
        N�r��rE�cidrAs   r8�cacheLocallyzBroker.cacheLocallyhs��
*2��!�!�#�&r7c�$�|j|}|Sr@rIrJs   r8�cachedLocallyAszBroker.cachedLocallyAsos���,�,�S�1���r7c	�f�t|tj�r&|j|jd�||||d���|S||_||_||_||_	t||jd|�d|_d|_d|_d|_S#d|_d|_d|_d|_wxYw)a
        Jelly an object according to the remote security rules for this broker.

        @param object: The object to jelly.
        @param perspective: The perspective.
        @param method: The method.
        @param args: Arguments.
        @param kw: Keyword arguments.
        c��|Sr@r6)�xs r8�<lambda>z"Broker.serialize.<locals>.<lambda>�s��!�r7)rYrqr\r])�callbackKeywordsN)r�r�Deferred�addCallbacksrprF�jellyMethod�	jellyArgs�jellyKwr-r�)rErxrYrqr\r]s      r8rpzBroker.serializess����f�e�n�n�-��������#.�$� ��	"�
 �	
��M�'2��#�!���������	 �������d�;�*.�D�'�#�D��!�D�N��D�L��+/�D�'�#�D��!�D�N��D�L�s�B�B0c�h�||_	t||jd|�d|_S#d|_wxYw)z�
        Unjelly an sexp according to the local security rules for this broker.

        @param sexp: The object to unjelly.
        @param perspective: The perspective.
        N)r�r.r�)rErrYs   r8rlzBroker.unserialize�s4��)4��%�	1��4�����d�;�,0�D�)��D�D�)�s�(�	1c�B�|jdz|_|jS)z3

        @return: A newly generated LUID.
        r�)r�rSs r8r9zBroker.newLocalID�s#��
#�1�1�A�5����"�"�"r7c�B�|jdz|_|jS)z9

        @return: A newly generated request ID.
        r�)r�rSs r8�newRequestIDzBroker.newRequestID�s#��
!%� 5� 5�� 9����$�$�$r7c	�V�d}d}d}	d|vr|d}|d=d|vr|d}|d=d|vr|s|rJd��|d}	|d=|jrtd��	|j|||��}
|j|||��}|j�}|	rOt	j�}
|
|j|<|s|r*tjd�|
j||�nd}
|j|d	z||||	|
|�|
S#t$r*t	j
t
j��cYSwxYw)
Nr��
pbcallback�	pberrback�pbanswerz*You can't specify a no-answer requirement.zCalling Stale Broker)rYrqz&warning! using deprecated "pbcallback"smessage)r�r:rprrr�rrr\rTr�rrorUr)rE�prefixrY�objectIDrdr\r]�pbc�pbe�answerRequired�netArgs�netKw�	requestID�rvals              r8rXzBroker._sendMessage�sX���������2���\�"�C��<� ��"���[�/�C��;������c�X�,X�X�*��
�^�N��:�����$�%;�<�<�	1��n�n�T�{�7�n�S�G��N�N�2�;�w�N�O�E��%�%�'�	���>�>�#�D�04�D�"�"�9�-��c����@�A��!�!�#�s�+��D��
�
��Z��������	
����)�	1��:�:�g�o�o�/�0�0�	1�s�(C5�50D(�'D(c	�F�|j|j||||||�yr@)�_recvMessager2�rErhrbrdrerfrgs       r8�
proto_messagezBroker.proto_message�s-��	
����!�!�������	
r7c	�F�|j|j||||||�yr@)rkrNrls       r8�proto_cachemessagezBroker.proto_cachemessage�s-��	
���� � �������	
r7c��t|t�s|jd�}	||�}|�td��|j	||||�}	|rZt|	t
j�r-|f}
|	j|j|j|
|
��y|j|	|�yy#t$ry}|rmt|t�s%|jj|j�r|j||�n |jt|�|�Yd}~yYd}~yYd}~yd}~wt $rL|r3t#j$dd��t�}|j||�t#j&�YywxYw)a�
        Received a message-send.

        Look up message based on object, unserialize the arguments, and
        invoke it with args, and send an 'answer' or 'error' response.

        @param findObjMethod: A callable which takes C{objectID} as argument.
        @param requestID: The requiest ID.
        @param objectID: The object ID.
        @param message: The message.
        @param answerRequired:
        @param netArgs: Arguments.
        @param netKw: Keyword arguments.
        r�NzInvalid Object ID)�callbackArgs�errbackArgs�)Peer will receive following PB traceback:T)�isError)r�r�r�r<rwrrTrU�_sendAnswer�_sendFailureOrErrorrr��isClassAllowed�	__class__�
_sendErrorr�rrror+)
rE�
findObjMethodrhrbrdrerfrgrx�	netResultr\�er�s
             r8rkzBroker._recvMessage�sS��0�'�3�'��n�n�V�,�G�%	;�"�8�,�F��~��/�0�0��4�4�T�7�G�U�S�I�,��i����8�%�<�D��*�*��(�(��0�0�%)�$(�	+���$�$�Y�	�:���+�
	C���a��+�t�}�}�/K�/K��K�K�0��O�O�A�y�1��O�O�O�A�$6�	�B�B�2����	�����C�T�R�#�%������9�-��G�G�I�	�s�)B)�)	E>�2A%D&�&AE>�=E>c�*�|jd||�y)z�
        (internal) Send an answer to a previously sent message.

        @param netResult: The answer.
        @param requestID: The request ID.
        sanswerN�r)rEr{rhs   r8ruzBroker._sendAnswer@s��	
�
�
�i��I�6r7c�|�|j|}|j|=|j|j|��y)z�
        (internal) Got an answer to a previously sent message.

        Look up the appropriate callback and call it.

        @param requestID: The request ID.
        @param netResult: The answer.
        N)r�r�rl)rErhr{r#s    r8�proto_answerzBroker.proto_answerIs9��
�"�"�9�-���"�"�9�-�	�
�
�4�#�#�I�.�/r7c�x�|jt��|j||�y|j||�y)z�
        Call L{_sendError} or L{_sendFailure}, depending on whether C{fail}
        represents an L{Error} subclass or not.

        @param fail: The failure.
        @param requestID: The request ID.
        N)�checkr<�_sendFailurery�rEr�rhs   r8rvzBroker._sendFailureOrErrorVs1���:�:�e��$����d�I�.��O�O�D�)�,r7c�|�tjd�tj|�|j||�y)zz
        Log error and then send it.

        @param fail: The failure.
        @param requestID: The request ID.
        rsN)rror+ryr�s   r8r�zBroker._sendFailurecs*��	���;�<�����
�����i�(r7c���t|tj�r�t|jt�s/|j
j
|jj�r
|j}n0t|t�s t||jj�}t|t�r|jj|_|jd||j|��y)z�
        (internal) Send an error for a previously sent message.

        @param fail: The failure.
        @param requestID: The request ID.
        serrorN)r�rrrFrr�rwrxr�r�rr�rrpr�s   r8ryzBroker._sendErrorns����d�G�O�O�,��$�*�*�i�0�D�M�M�4P�4P��
�
�$�$�5��z�z����o�6�'��d�l�l�.K�.K�L���d�O�,�$(�L�L�$A�$A�D�!��
�
�h�	�4�>�>�$�+?�@r7c�|�|j|}|j|=|j|j|��y)z}
        (internal) Deal with an error.

        @param requestID: The request ID.
        @param fail: The failure.
        N)r�rrl)rErhr�r#s    r8�proto_errorzBroker.proto_error�s9��
�"�"�9�-���"�"�9�-�	�	�	�$�"�"�4�(�)r7c�(�|jd|�y)z^
        (internal) Send a DECREF directive.

        @param objectID: The object ID.
        sdecrefNr~�rErbs  r8r�zBroker.sendDecRef�s��	
�
�
�i��*r7c�R�t|t�r|jd�}|j|j	�}|dk(rd|j|j
j
�}|j|=|j|=|jj|d���yy)z�
        (internal) Decrement the reference count of an object.

        If the reference count is zero, it will free the reference to this
        object.

        @param objectID: The object ID.
        r�rc��yr@r6r6r7r8rRz%Broker.proto_decref.<locals>.<lambda>�rgr7N)
r�r�r[r�r�rxr5r�r��pop)rErb�refsr:s    r8�proto_decrefzBroker.proto_decref�s����h��$����v�.�H�� � ��*�1�1�3���1�9��$�$�X�.�5�5�E�E�G�D��
�
�4� ��!�!�(�+�6�D���"�"�4��6�8�	r7c�(�|jd|�y)z_
        (internal) Send a DECACHE directive.

        @param objectID: The object ID.
        sdecacheNr~r�s  r8�decCacheRefzBroker.decCacheRef�s��	
�
�
�j�(�+r7c��|j|j�}|dk(r�|j|}|j}|j}	|j	|t|||��|j�}|j|=|j|=|jd|�yy#t$rtj�Y�]wxYw)z�
        (internal) Decrement the reference count of a cached object.

        If the reference count is zero, free the reference, then send an
        'uncached' directive.

        @param objectID: The object ID.
        rsuncacheN)r�r�rxrYrrrrrr5r�r)rErbr�r$r%rYr:s       r8�
proto_decachezBroker.proto_decache�s����)�)�(�3�:�:�<���1�9��-�-�h�7�D����I��*�*�K�
��*�*��!4�T�9�k�!R��
�,�,�.�D��(�(��.��*�*�8�4��M�M�*�h�/���!�
��
�
��
�s�B&�&C�Cc�J�|j|}d|_|j|=y)zx
        (internal) Tell the client it is now OK to uncache an object.

        @param objectID: The object ID.
        N)r�rW)rErbrKs   r8�
proto_uncachezBroker.proto_uncache�s+���'�'��1����
�
�%�%�h�/r7�r)NNNNr@)6r2r3r4r5r	�usernamerr,rBr�r�r�r�rrrrrrr�r&r�r)r,r�r2r7r;r=r?rBrDrGrLrNrprlr9r\rXrmrorkrur�rvr�ryr�r�r�r�r�r�r6r7r8r�r�s����G��H��G� !�N�$ �L0�
�
�5�
A�(S��
;�0����'!�R*�'�+���  ���60� 
4�� 7��*2��( �T1�#�%�'�R
�
�@;�D7�0�-�	)�A�(	*�+�9�$,�0�80r7r�c���t�}|j|�|j�}t�}|j|�|j|�|j�}|S)z�
    Respond to a challenge.

    This is useful for challenge/response authentication.

    @param challenge: A challenge.
    @param password: A password.
    @return: The password hashed twice.
    )r�update�digest)�	challenge�password�m�hashedPassword�doubleHashedPasswords     r8�respondr��sS��	��A��H�H�X���X�X�Z�N���A��H�H�^���H�H�Y���8�8�:���r7c	��td�ttjdd��D��}t	|�j�}|S)z%

    @return: Some random data.
    c3�HK�|]}tjdd����y�w)�A�ZN)�random�randint)�.0rQs  r8�	<genexpr>zchallenge.<locals>.<genexpr>�s����Q�A�����B�'�Q�s� "��)r�r�r��	randrangerr�)�craps r8r�r��s=��
�Q��v�7G�7G��B�7O�1P�Q�Q�D��t�9����D��Kr7c�p�eZdZdZeZdZdefd�Zd�Z	d�Z
d�Zd�Zdd�Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zdd�Zy)�PBClientFactoryz�
    Client factory for PB brokers.

    As with all client factories, use with reactor.connectTCP/SSL/etc..
    getPerspective and getRootObject can be called either before or
    after the connect.
    Fc�@�||_||_|j�y)aE
        @param unsafeTracebacks: if set, tracebacks for exceptions will be sent
            over the wire.
        @type unsafeTracebacks: C{bool}

        @param security: security options used by the broker, default to
            C{globalSecurity}.
        @type security: L{twisted.spread.jelly.SecurityOptions}
        N)r�r��_reset)rEr�r�s   r8rBzPBClientFactory.__init__s��!1��� ��
����
r7c�N�|jd|j��}||_|S)zP
        Build the broker instance, passing the security options to it.
        T�r�r�)rr�r)rE�addr�ps   r8�
buildProtocolzPBClientFactory.buildProtocols&��
�M�M�4�$�-�-�M�@����	��r7c�.�g|_d|_d|_yr@)�rootObjectRequests�_broker�_rootrSs r8r�zPBClientFactory._resets��"$��������
r7c�l�|j}|j�|D]}|j|��yr@)r�r�r)rEr"�	deferredsr#s    r8�_failAllzPBClientFactory._failAlls1���+�+�	����
��	�A�
�I�I�f��	r7c�&�|j|�yr@)r�)rE�	connectorr"s   r8�clientConnectionFailedz&PBClientFactory.clientConnectionFailed%s���
�
�f�r7c�H�|rd|_d|_y|j|�y)zJ
        Reconnecting subclasses should call with reconnecting=1.
        N)r�r�r�)rEr�r"�reconnectings    r8�clientConnectionLostz$PBClientFactory.clientConnectionLost(s#��� �D�L��D�J��M�M�&�!r7c��||_|jd�|_|j}g|_|D]}|j	|j��y)N�root)r�r?r�r�r�)rErW�dsr#s    r8rz$PBClientFactory.clientConnectionMade4sM������)�)�&�1��
�
�
$�
$��"$����	#�A�
�J�J�t�z�z�"�	#r7c���|jr5|jjstj|j�Stj
�}|jj|�|S)ze
        Get root object of remote PB server.

        @return: Deferred of the root object.
        )r�r�r�succeedr�rTr�r�)rEr#s  r8�
getRootObjectzPBClientFactory.getRootObject<sO���<�<���� 9� 9��=�=����,�,��N�N������&�&�q�)��r7c�f�|jr%|jjj�yy)z�
        If the factory is connected, close the connection.

        Note that if you set up the factory to reconnect, you will need to
        implement extra logic to prevent automatic reconnection after this
        is called.
        N)r�r�r8rSs r8�
disconnectzPBClientFactory.disconnectHs&���<�<��L�L�"�"�1�1�3�r7c�\�|jd|�j|j||�S)N�login)r��addCallback�_cbResponse)rEr�r�r��clients     r8�_cbSendUsernamezPBClientFactory._cbSendUsernameSs-�����w��1�=�=����h��
�	
r7c�F�|\}}|jdt||�|�S)Nr�)r�r�)rE�
challengesr�r�r��
challengers      r8r�zPBClientFactory._cbResponseXs(�� *��	�:��$�$�Y��	�8�0L�f�U�Ur7c�&�|jd|�S)ab
        Attempt an anonymous login on the given remote root object.

        @type root: L{RemoteReference}
        @param root: The object on which to attempt the login, most likely
            returned by a call to L{PBClientFactory.getRootObject}.

        @param client: A jellyable object which will be used as the I{mind}
            parameter for the login attempt.

        @rtype: L{Deferred}
        @return: A L{Deferred} which will be called back with a
            L{RemoteReference} to an avatar when anonymous login succeeds, or
            which will errback if anonymous login fails.
        �loginAnonymous)r�)rEr�r�s   r8�_cbLoginAnonymousz!PBClientFactory._cbLoginAnonymous\s�� ���/��8�8r7Nc���|j�}tj|�r|j|j|�|S|j|j
|j|j|�|S)a�
        Login and get perspective from remote PB server.

        Currently the following credentials are supported::

            L{twisted.cred.credentials.IUsernamePassword}
            L{twisted.cred.credentials.IAnonymous}

        @rtype: L{Deferred}
        @return: A L{Deferred} which will be called back with a
            L{RemoteReference} for the avatar logged in to, or which will
            errback if login fails.
        )r�r�
providedByr�r�r�r�r�)rE�credentialsr�r#s    r8r�zPBClientFactory.loginnsl��
��� ��� � ��-�
�M�M�$�0�0�&�9�
��
�M�M��$�$�k�&:�&:�K�<P�<P�RX�
��r7r�r@)r2r3r4r5r�rr�r,rBr�r�r�r�r�rr�r�r�r�r�r�r6r7r8r�r��s[����H���(-�����
��
"�#�
�	4�
�
V�9�$r7r�c�0�eZdZdZdZeZdefd�Zd�Z	d�Z
y)�PBServerFactorya�
    Server factory for perspective broker.

    Login is done using a Portal object, whose realm is expected to return
    avatars implementing IPerspective. The credential checkers in the portal
    should accept IUsernameHashedPassword or IUsernameMD5Password.

    Alternatively, any object providing or adaptable to L{IPBRoot} can be
    used instead of a portal to provide the root object of the PB server.
    Fc�@�t|�|_||_||_y)a�
        @param root: factory providing the root Referenceable used by the broker.
        @type root: object providing or adaptable to L{IPBRoot}.

        @param unsafeTracebacks: if set, tracebacks for exceptions will be sent
            over the wire.
        @type unsafeTracebacks: C{bool}

        @param security: security options used by the broker, default to
            C{globalSecurity}.
        @type security: L{twisted.spread.jelly.SecurityOptions}
        N)rr�r�r�)rEr�r�r�s    r8rBzPBServerFactory.__init__�s���D�M��	� 0��� ��
r7c��|jd|j��}||_|jd|jj|��|S)zT
        Return a Broker attached to the factory (as the service provider).
        Fr�r�)rr�rr=r��
rootObject)rEr��protos   r8r�zPBServerFactory.buildProtocol�sE���
�
�u�t�}�}�
�E����
�
���f�d�i�i�&:�&:�5�&A�B��r7c��yr@r6)rErs  r8rz$PBServerFactory.clientConnectionMade�r�r7N)r2r3r4r5r�r�rr,rBr�rr6r7r8r�r��s*��	����H�.3�n�!�"�
r7r�c��eZdZdZd�Zd�Zy)�IUsernameMD5Passwordab
    I encapsulate a username and a hashed password.

    This credential is used for username/password over PB. CredentialCheckers
    which check this kind of credential must store the passwords in plaintext
    form or as a MD5 digest.

    @type username: C{str} or C{Deferred}
    @ivar username: The username associated with these credentials.
    c��y)a�
        Validate these credentials against the correct password.

        @type password: C{str}
        @param password: The correct, plaintext password against which to
            check.

        @rtype: C{bool} or L{Deferred}
        @return: C{True} if the credentials represented by this object match the
            given password, C{False} if they do not, or a L{Deferred} which will
            be called back with one of these values.
        Nr6�r�s r8�
checkPasswordz"IUsernameMD5Password.checkPassword�rgr7c��y)a�
        Validate these credentials against the correct MD5 digest of the
        password.

        @type password: C{str}
        @param password: The correct MD5 digest of a password against which to
            check.

        @rtype: C{bool} or L{Deferred}
        @return: C{True} if the credentials represented by this object match the
            given digest, C{False} if they do not, or a L{Deferred} which will
            be called back with one of these values.
        Nr6r�s r8�checkMD5Passwordz%IUsernameMD5Password.checkMD5Password�rgr7N)r2r3r4r5r�r�r6r7r8r�r��s��	��
r7r�c��eZdZdZd�Zd�Zy)�_PortalRootz/
    Root object, used to login to portal.
    c��||_yr@)�portal)rEr�s  r8rBz_PortalRoot.__init__�s	����r7c�.�t|j|�Sr@)�_PortalWrapperr�)rErWs  r8r�z_PortalRoot.rootObject�s���d�k�k�6�2�2r7N)r2r3r4r5rBr�r6r7r8r�r��s����3r7r�c��eZdZdZd�Zy)�_JellyableAvatarMixinzk
    Helper class for code which deals with avatars which PB must be capable of
    sending to a peer.
    c����|\}}�tj|�st|d�}|j�}�g��fd�}||jj
|<|jj
|�|S)z�
        Ensure that the avatar to be returned to the client is jellyable and
        set up disconnection notification to call the realm's logout object.
        rYc�*���sy�d}�d=|�yr�r6)�fn�logouts �r8�maybeLogoutz3_JellyableAvatarMixin._cbLogin.<locals>.maybeLogouts��������B��q�	��Dr7)r)r�rtr5rWr�r�)rE�result�	interface�avatarr:r�r�s      @r8�_cbLoginz_JellyableAvatarMixin._cbLogin�st���
'-�#��F�F��$�$�V�,�$�V�]�;�F��%�%�'��
���	�+6����!�!�$�'����&�&�{�3��
r7N)r2r3r4r5r�r6r7r8r�r��s���
r7r�c�"�eZdZdZd�Zd�Zd�Zy)r�z=
    Root Referenceable object, used to login to portal.
    c� �||_||_yr@)r�rW)rEr�rWs   r8rBz_PortalWrapper.__init__s�������r7c�^�t�}|t|j|j||�fS)z[
        Start of username/password login.

        @param username: The username.
        )r��_PortalAuthChallengerr�rW)rEr��cs   r8�remote_loginz_PortalWrapper.remote_logins*��
�K���'����T�[�[�(�A�N�N�Nr7c��|jjt�|t�}|j	|j
�|S)aU
        Attempt an anonymous login.

        @param mind: An object to use as the mind parameter to the portal login
            call (possibly None).

        @rtype: L{Deferred}
        @return: A Deferred which will be called back with an avatar when login
            succeeds or which will be errbacked if login fails somehow.
        )r�r�rrbr�r�)rE�mindr#s   r8�remote_loginAnonymousz$_PortalWrapper.remote_loginAnonymous&s3��
�K�K���i�k�4��>��	�
�
�d�m�m�$��r7N)r2r3r4r5rBr�rr6r7r8r�r�s����O�
r7r�c�(�eZdZdZd�Zd�Zd�Zd�Zy)r�z5
    Called with response to password challenge.
    c�<�||_||_||_||_yr@)r�rWr�r�)rEr�rWr�r�s     r8rBz_PortalAuthChallenger.__init__<s�������� ��
�"��r7c��||_|jj||t�}|j	|j
�|Sr@)�responser�r�rbr�r�)rErrr#s    r8�remote_respondz$_PortalAuthChallenger.remote_respondBs6�� ��
��K�K���d�D�,�7��	�
�
�d�m�m�$��r7c�R�|jt|�j��S)z�
        L{IUsernameHashedPassword}

        @param password: The password.
        @return: L{_PortalAuthChallenger.checkMD5Password}
        )r�rr�)rEr�s  r8r�z#_PortalAuthChallenger.checkPasswordHs"���$�$�S��]�%9�%9�%;�<�<r7c��t�}|j|�|j|j�|j�}|j|k(S)z�
        L{IUsernameMD5Password}

        @param md5Password:
        @rtype: L{bool}
        @return: L{True} if password matches.
        )rr�r�r�r)rE�md5Password�md�corrects    r8r�z&_PortalAuthChallenger.checkMD5PasswordQsA���U��
�	�	�+��
�	�	�$�.�.�!��)�)�+���}�}��'�'r7N)r2r3r4r5rBrr�r�r6r7r8r�r�6s���#��=�(r7r�)(rrrrrr!r rrrrrrr"r'r&r(r#r%r$r6�portnor0r:r<r`rIrbrjrtr|r�r�r�r�r�r�r�r�r�r�)\r5r��hashlibr�zope.interfacerr�twisted.cred.credentialsrrrr	�twisted.cred.portalr
�twisted.internetrr�twisted.persistedr
�twisted.pythonrrr�twisted.python.compatrr�twisted.python.componentsr�twisted.spreadr�twisted.spread.flavorsrrrrrrrrrrrr r!r"r#r$r%r&r'r(�twisted.spread.interfacesr)r*�twisted.spread.jellyr+r,r-r.r6rrAr0r:r<r>rIr`rbrjrt�	Ephemeralr|r�rr�r�r�r�r�r�r��
ClientFactoryr��
ServerFactoryr�r�r�r�r�r��__all__r6r7r8�<module>rsG��
�4��1���'�,�$�1�0�1�5�!�������,?�M�M���	
���I������I��/�)�/�4�
�
��
�@	�y�	�&�9�&�R
�\��%?�%?��%?�PV�m�V�
�\���E.�l�F�$4�$4�E.���E.�P�x��1� � �H�g�o�o�x��:(,�J����(,�V��
�6�
�O0�V�]�]�O0�d �(�L�h�,�,�L�^-
�h�,�,�-
�`'�<�'�T
�W��	3�	3��	3���V�W�-� � �F�]�$9��D
�
$�&:�;�&(�M�+@�&(�<�&(�R*�r7
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!