File: //usr/lib/fm-agent/dependencies/linux/python3.9/jpype/__pycache__/_jcustomizer.cpython-39.pyc
a
��iU( � @ s� d dl Z ddgZeeeefZddd�Zddd�Zdd� Z d d
� Z
dd� Zd
d� ZG dd� de j
�Zdd� Zi e _ed��e� ed��e� dS )� N�JImplementationFor�JConversionc s2 t | ��|dur��|� d� ���fdd� }|S )a� Decorator to define a method as a converted a Java type.
Whenever a method resolution is called the JPype internal rules
are applied, but this may be insufficient. If only a
single method requires modification then a class customizer can
be applied. But if many interfaces require the same conversion
than a user conversion may be a better option.
To add a user conversion define a method which take the requested
Java type as the first argument, the target object to be converted
as the second argument and returns a Java object or Java proxy that
matches the required type. If the type is not a Java type then
a TypeError will be raised. This method is only evaluated
after the match has been determine prior to calling.
Care should be used when defining a user conversion. If example
if one has an interface that requires a specific class and you
want it to take a Python string, then a user conversion can
do that. On the other hand, if you define a generic converter
of any Python object to a Java string, then every interface
will attempt to call the conversion method whenever a Java string
is being matched, which can cause many methods to potentially
become ambiguous.
Conversion are not inherited. If the same converter needs to
apply to multiple types, then multiple decorators can
be applied to the same method.
Args:
cls(str, JClass): The class that will be produced by this
conversion.
exact(type): This conversion applies only to objects that have
a type exactly equal to the argument.
instanceof(type or protocol): This conversion applies to
any object that passes isinstance(obj, type).
attribute(str): This conversion applies to any object that has
passes hasattr(obj, arg). (deprecated)
excludes(type): Prevents a conversion for a specified type.
Can be used to prevent a specific type from being converted.
For example, to prevent maps or strings from passing
a check for Sequence. Exclusions are applied before all
other user specificied conversions.
Nc sD �d ur�� �| d� �d ur,�� �| d� � d ur@��� | � | S )NTF)�_addTypeConversion�_addAttributeConversion)�func�� attribute�exact�hints�
instanceof� �D/usr/lib/fm-agent/dependencies/linux/python3.9/jpype/_jcustomizer.py�
customizerJ s zJConversion.<locals>.customizer)N)�
getClassHints�_excludeConversion)�clsr r r Zexcludesr r r r
r s
,
Fc s$ t �t�std��� �fdd�}|S )ag Decorator to define an implementation for a class.
Applies to a class which will serve as a prototype as for the Java class
wrapper. If it is registered as a base class, then the class must
derive from JObject. Otherwise, the methods are copied from
the prototype to the Java class wrapper.
The method ``__jclass_init__(cls)`` will be called with the constructed
class as the argument. This call is used to set methods for all classes
that derive from the specified class. Use ``jclass._customize()`` to
alter the class methods.
Using the prototype class as a base class is used mainly to support
classes which must be derived from a Python type by design. Use
of a base class will produce a RuntimeError if the class has already
been created.
For non-base class customizers, the customizer will be applied
retroactively if the class is already created. Conflicts are
resolved by the last customizer applied.
Args:
clsname (str): name of java class.
base (bool, optional): if True this will be a base class.
Default is False.
z2ImplementationFor requires a java classname stringc s( t ��}� r|�| � n|��| � | S �N)r �registerClassBase�registerClassImplementation)r r
��base�clsnamer r
r t s
z&JImplementationFor.<locals>.customizer)�
isinstance�str� TypeError)r r r r r r
r U s
c C sR |D ]H}t |d�}|�dd �}|j}|r@t�| |�}| �||� | �||� qd S )N�
__joverride__�rename)�getattr�get�__name__�type�__getattribute__�
_customize)r �sticky�method�attrr �name�origr r r
�_applyStickyMethods~ s
r( c C s� |j �� D ]�\}}t|�s$t|t�r
t|dd�}|dur�|�dd�rP|�|� q
|�dd| �}|| v r�t| | tj tj
f�r�||| | � |||� q
dS )a (internal) Apply a customizer to a class.
This "borrows" methods from a prototype class.
Current behavior is:
- Copy any string or property.
- Copy any callable applying @JOverride
if applicable with conflict renaming.
- Copy __new__ method.
r Nr# Fr �_)�__dict__�items�callabler �
_jcopymembersr r �append�_jpype�_JField�_JMethod)�members�protor# �setter�p�vr% r r r r
�_applyCustomizerImpl� s
r7 c C sJ t � }| g}|rF|�d�}||v r$q|�|�� � |�|� ||� qd S )Nr )�set�pop�extend�__subclasses__�add)r r$ ZappliedZtodo�cr r r
� _applyAll� s
r>