File: //lib/python3/dist-packages/pikepdf/__pycache__/_methods.cpython-38.pyc
U
~^=T � @ s2 d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z m
Z
ddlmZ dd l
mZmZmZmZmZmZmZ dd
lmZmZmZmZ ddlmZmZmZ g Zdd
� Zdd� Z dd� Z!ee�G dd� d��Z"ee�G dd� d��Z#ee�G dd� d��Z$dd� Z%ee�G dd� d��Z&ee�G dd� d��Z'dS )z�
In several cases the implementation of some higher levels features might as
well be in Python. Fortunately we can attach Python methods to C++ class
bindings after the fact.
We can also move the implementation to C++ if desired.
� N)�
namedtuple��KeysView)�BytesIO)�PIPE�run)�NamedTemporaryFile� )�Array�
Dictionary�Name�Object�Page�Pdf�Stream)�PdfError�StreamParser�Token�_ObjectMapping)�EncryptionInfo�PdfMetadata�Permissionsc C s | fdd�}|S )at Attach methods of a Python support class to an existing class
This monkeypatches all methods defined in the support class onto an
existing class. Example:
.. code-block:: python
@augments(ClassDefinedInCpp)
class SupportClass:
def foo(self):
pass
The Python method 'foo' will be monkeypatched on ClassDefinedInCpp. SupportClass
has no meaning on its own and should not be used, but gets returned from
this function so IDE code inspection doesn't get too confused.
We don't subclass because it's much more convenient to monkeypatch Python
methods onto the existing Python binding of the C++ class. For one thing,
this allows the implementation to be moved from Python to C++ or vice
versa. It saves having to implement an intermediate Python subclass and then
ensures that the C++ superclass never 'leaks' to pikepdf users. Finally,
wrapper classes and subclasses can become problematic if the call stack
crosses the C++/Python boundary multiple times.
Any existing methods may be used, regardless of whether they defined
elsewhere in the support class or in the target class.
The target class does not have to be C++ or derived from pybind11.
THIS DOES NOT work for static methods or class methods. pybind11 does not seem
to support this sort of runtime modification.
c S sh t �| �D ]J\}}t �|�r>|j�| j|j�|_t|||� q
t �|�r
t|||� q
dd� }|| _| S )Nc S s t | jjd ��d S )Nz .__init__)�NotImplementedError� __class__�__name__��self� r �2/usr/lib/python3/dist-packages/pikepdf/_methods.py�
block_initK s z3augments.<locals>.class_augment.<locals>.block_init) �inspectZ
getmembersZ
isfunction�__qualname__�replacer �setattrZisdatadescriptor�__init__)�cls�cls_cpp�name�memberr r r r �
class_augmentA s
�
zaugments.<locals>.class_augmentr )r&