Files
old-saburly-wagtail-web/env/lib/python3.10/site-packages/willow/__pycache__/registry.cpython-310.pyc

165 lines
11 KiB
Plaintext
Raw Normal View History

2024-08-27 20:33:44 +02:00
o
<00><><EFBFBD>fs;<00>@stddlmZddlmZmZerddlmZGdd<06>de<07>ZGdd<08>de<07>Z Gd d
<EFBFBD>d
e<07>Z
Gd d <0C>d <0C>Z e <0B>Z d S)<0E>)<01> defaultdict)<02> TYPE_CHECKING<4E>List<73>)<01> OptimizerBasec@<00>eZdZdZdS)<03>UnrecognisedOperationErrorzL
Raised when the operation isn't in any of the known image classes.
N<><04>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__<5F>rr<00>Q/home/amir/Desktop/saburlyweb/env/lib/python3.10/site-packages/willow/registry.pyrsrc@r)<03>UnavailableOperationErrorz<72>
Raised when all the image classes the operation exists in are not available.
(most likely due to a missing image library.)
Nr rrrrr<00>rc@r)<03>UnroutableOperationErrorzo
Raised when there is no way to convert the image into an image class that
supports the operation.
Nr rrrrrrrc@s<>eZdZdd<02>Zdd<04>Zd*dd<07>Zdd <09>Zd
d <0B>Zd+dd<0F>Zdd<11>Z dd<13>Z
dd<15>Z dd<17>Z d,dd<19>Z deded fdd<1D>Zdd<1F>Zge<12>fd d!<21>Zd"d#<23>Zd$d%<25>Zd&d'<27>Zd(d)<29>ZdS)-<2D>WillowRegistrycCs.t<00>|_i|_tt<04>|_i|_i|_g|_dS<00>N) <09>set<65>_registered_image_classes<65>_unavailable_image_classesr<00>dict<63>_registered_operations<6E>_registered_converters<72>_registered_converter_costs<74>_registered_optimizers<72><01>selfrrr<00>__init__#s 

zWillowRegistry.__init__cCs||j||<dSr<00>r)r<00> image_class<73>operation_name<6D>funcrrr<00>register_operation+sz!WillowRegistry.register_operationNcCs,||j||f<|dur||j||f<dSdSr)rr)r<00>from_image_class<73>to_image_classr#<00>costrrr<00>register_converter.s<04>z!WillowRegistry.register_converterc
Cs<>|j<00>|<01>z|<01><02>Wnty#}z ||j|<WYd}~nd}~wwt|<01>D]@}t||<03>}t|d<01>r=|<00>||j |<04>q(t|d<02>rR|j
||j d||j dd<05>q(t|d<06>rh|j D] \}}|j
||||d<05>qZq(dS)N<>_willow_operation<6F>_willow_converter_torr)r'<00>_willow_converter_from) r<00>add<64>check<63> Exceptionr<00>dir<69>getattr<74>hasattrr$r
r(r*r+)rr!<00>e<>attr<74>val<61>converter_fromr'rrr<00>register_image_class4s.  <08><02> 


<08>
<02><04>z#WillowRegistry.register_image_classcCs<>t|dg<00>}t|dg<00>}t|dg<00>}|D]}|<00>|<05>q|D]}|<00>|d|d|d<00>q|D]}|<00>|d|d|d<00>q0dS)N<>willow_image_classes<65>willow_operations<6E>willow_convertersrr<00>)r0r6r$r()r<00>plugin<69> image_classes<65>
operations<EFBFBD>
convertersr!<00> operation<6F> converterrrr<00>register_pluginMs    <04>zWillowRegistry.register_plugin<69>optimizer_classrcCs<>zddlm}t|dd<04>}Wnty"ddl}|j<05>dd<04>}Ynw|s'dSt|t<08>rB|<03> <09>dkr4dS|<03> <09>dkr=d}n|<03>
d <09>}|durId}n|j |v}|ra|<01> <0C>rc||j vre|j <0A>|<01>dSdSdSdS)
zRegisters an optimizer class.r)<01>settings<67>WILLOW_OPTIMIZERSFN<46>false<73>trueT<65>,)<0F> django.confrCr0<00> ImportError<6F>os<6F>environ<6F>get<65>
isinstance<EFBFBD>str<74>lower<65>split<69> library_name<6D> check_libraryr<00>append)rrBrC<00>enabled_optimizersrJ<00> add_optimizerrrr<00>register_optimizer[s4  <02>
  

<02><02>
<08>z!WillowRegistry.register_optimizercCs|j||Srr )rr!r"rrr<00> get_operation<6F><00>zWillowRegistry.get_operationcCs"|j<00><01>D] }||vrdSqdS)NTF)r<00>values)rr"<00>image_class_operationsrrr<00>operation_exists<74>s
<02>zWillowRegistry.operation_existscCs|j||fSr)r<00>rr%r&rrr<00> get_converter<65>rXzWillowRegistry.get_convertercCs|j<00>||fd<01>S)N<>d)rrLr\rrr<00>get_converter_cost<73>s<04>z!WillowRegistry.get_converter_costcs<><00>j<00><01>}<03>rtt<03><00>fdd<02>|<03><02>}|std<03><01>d<04><03><01>|r@|t<02>j<05><06><00>}|s>td<05>d<06> <09><01>g<01>fdd<08>|D<00><00><01><01>|S|S) Ncs|<00>jvo <0B><01>j|vSrr )r!<00>r<00>with_operationrr<00><lambda><3E>s
z2WillowRegistry.get_image_classes.<locals>.<lambda>z%Could not find image class with the 'z ' operation<6F>
zZThe operation '{}' is available in the following image classes but they all raised errors:c s*g|]}dj|jt<02>j<03>|d<01><02>d<02><02>qS)z#{image_class_name}: {error_message}z Unknown error)<02>image_class_name<6D> error_message)<05>formatr
rNrrL<00><02>.0r!rrr<00>
<listcomp><3E>s <04><02><02><04><06>z4WillowRegistry.get_image_classes.<locals>.<listcomp>)
r<00>copyr<00>filterrr<00>keysr<00>joinrf)rra<00> availabler<<00>available_image_classesrr`r<00>get_image_classes<65>s>
 <02><04>
<04><06><02><02>
 <04><02><02><04>z WillowRegistry.get_image_classes<65> image_format<61>returncCs(g}|jD] }|<03>|<01>r|<02>|<03>q|Sr)r<00>
applies_torS)rrq<00>
optimizers<EFBFBD> optimizerrrr<00>get_optimizers_for_format<61>s 


<02>z(WillowRegistry.get_optimizers_for_formatccs0<00>|j<00><01>D]\\}}}||ur||fVqdS)a<>
Yields a tuple for each image class that can be directly converted
from the specified image classes. The tuple contains the converter
function and the image class.
For example:
>>> list(registry.get_converters_from(Pillow))
[
(convert_pillow_to_wand, Wand),
(save_as_jpeg, JpegFile)
...
]
N)r<00>items)rr%<00>c_from<6F>c_tor@rrr<00>get_converters_from<6F>s <02>
<02><04>z"WillowRegistry.get_converters_fromc Cs<>||kr|gS||vr gS||jvs||jvrgSg}|<00>|<01>D]\}}||vr>|<00>|||||fg|<04>|h<01><01>}|<05>|<08>q |S)a<>
Returns all paths between two image classes.
Each path is a list of tuples representing the steps to take in order to
convert to the new class. Each tuple contains two items: The converter
function to call and the class that step converts to.
The order of the paths returned is undefined.
For example:
>>> registry.find_all_paths(JpegFile, OpenCV)
[
[
(load_jpeg_into_pillow, Pillow),
(convert_pillow_to_opencv, OpenCV)
],
[
(load_jpeg_into_wand, Wand),
(convert_wand_to_opencv, OpenCV)
]
]
)rrrz<00>find_all_paths<68>union<6F>extend) r<00>start<72>end<6E>path<74> seen_classes<65>pathsr@<00>
next_class<EFBFBD>newpathsrrrr{<00>s&

 
<04>
<02>zWillowRegistry.find_all_pathscCs.|}d}|D]\}}||<00>||<06>7}|}q|S)zE
Costs up a path and returns the cost as an integer.
r)r_)rr~r<><00>
last_class<EFBFBD>
total_costr@r<>rrr<00> get_path_costs  zWillowRegistry.get_path_costcCsFd}d}|<00>||<02>D]}|<00>||<05>}|dus||kr|}|}q
||fS)z<>
Finds the shortest path between two image classes.
This is similar to the find_all_paths function, except it only returns
the path with the lowest cost.
N)r{r<>)rr~r<00> current_path<74> current_costr<74>r'rrr<00>find_shortest_path+s <02>z!WillowRegistry.find_shortest_pathc CsVd}d}d}|D]}|<00>||<06>\}}|durq|dus||kr%|}|}|}q|||fS)z<>
Finds which of the specified image classes is the closest, based on the
sum of the costs for the conversions needed to convert the image into it.
N)r<>) rr~r<<00> current_classr<73>r<>r!r<>r'rrr<00>find_closest_image_class>s<02>
z'WillowRegistry.find_closest_image_classc Cs<>z|<00>||<02>}|}g}d}Wn5tyC|j|dd<03>}|<00>||<07>\}}}|dur;td<05>|d<06>dd<08>|D<00><01>|j<07><03><01>|<00>||<02>}Ynw||||fS) a<>
Finds an operation that can be used by an image in the specified from_class.
This function returns four values:
- The operation function
- The class which the operation is implemented on
- A path to convert the image into the correct class for the operation
- The total cost of all the conversions
The path (third value) is a list of two-element tuple. Each tuple contains
a function to call and a reference to the class that step converts to. See
below for an example.
How it works:
If the specified operation_name is implemented for from_class, that is returned
with an empty conversion path.
If the specified operation_name is implemented on another class (but not from_class)
that operation is returned with the conversion path to that new class.
If it's implemented on multiple image classes, the closest one is chosen (based
on the sum of the costs of each conversion step).
If the operation_name is not implemented anywhere, there is no route to
any image class that implements it or all the image classes that implement
it are unavailable, a LookupError will be raised.
Basic example:
>>> func, cls, path, cost = registry.find_operation(JPEGImageFile, 'resize')
>>> func
PillowImage.resize
>>> cls
PillowImage
>>> path
[
(PillowImage.open, PillowImage)
]
>>> cost
100
To run the found operation on an image, run each conversion function on that
image then run the operation function:
>>> image = Image.open(...)
>>> func, cls, path, cost = registry.find_operation(type(image), operation_name)
>>> for converter, new_class in path:
... image = converter(image)
...
>>> func(image, *args, **kwargs)
rT)rarnNz^The operation '{}' is available in the image class '{}' but it can't be converted to from '{}'z, css<00>|]}|jVqdSr)r
rgrrr<00> <genexpr><3E>s<02>
<EFBFBD>z0WillowRegistry.find_operation.<locals>.<genexpr>)rW<00> LookupErrorrpr<>rrfrmr
)r<00>
from_classr"r#<00>clsr<73>r'r<rrr<00>find_operationUs05  <06>
<06><02><04> <02> zWillowRegistry.find_operationr)rBr)NN)r
r r rr$r(r6rArVrWr[r]r_rprNrrvrzrr{r<>r<>r<>r<>rrrrr"s&

%
23  rN) <0A> collectionsr<00>typingrrrtrr<>rrrr<00>registryrrrr<00><module>s