Ë
    R/jQ  ã                   ó®   — d Z ddlZddlZddlZddlZddlmZmZ ddlm	Z	m
Z
mZmZmZmZmZmZmZ ddlmZmZ ddlmZmZ  G d„ d«      Z G d	„ d
e«      Zy)aÞ  
OpenDrop: an open source AirDrop implementation
Copyright (C) 2018  Milan Stute
Copyright (C) 2018  Alexander Heinrich

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
é    N)ÚArchiveEntryÚnew_archive_entry)	ÚARCHIVE_EOFÚentry_clearÚentry_sourcepathÚread_disk_descendÚread_next_header2Ú
write_dataÚwrite_finish_entryÚwrite_get_bytes_per_blockÚwrite_header)ÚArchiveWriteÚnew_archive_read_disk)ÚExifTagsÚImagec                   óX   — e Zd ZdZedefd„«       Zed„ «       Zedd„«       Zed„ «       Z	y)	ÚAirDropUtilz«
    This class contains a set of utility functions that support the opendrop implementation
    They have been moved, because the opendrop files tend to get too long
    Úreturnc                 óR  — d}t        | j                  «      dk(  st        | j                  «      dk(  r|S | j                  d   }| j                  d   }d|v r.d}d|v rd}|S d|v rd}|S d	|v rd
}|S d|v rd}|S d|v sd|v rd}|S d|v rd}|S d|v rd}|S d|v rd}d|v rd}d|v rd}|S )z›
        Get the Apple conform UTI Type from a flp instance which has been used on the data which should be sent

        :param flp: fleep object
        zpublic.contentr   Úimagezpublic.imageÚjpgzpublic.jpegÚjp2zpublic.jpeg-2000Úgifzcom.compuserve.gifÚpngz
public.pngÚrawzpublic.camera-raw-imageÚaudiozpublic.audioÚvideozpublic.videoÚarchivezpublic.dataÚgzipzorg.gnu.gnu-zip-archiveÚzipzpublic.zip-archive)ÚlenÚmimeÚtype)ÚflpÚuti_typer"   Úf_types       ú?/home/josh/.local/lib/python3.12/site-packages/opendrop/util.pyÚget_uti_typezAirDropUtil.get_uti_type/   s  € ð $ˆÜˆs�x‰x‹=˜AÒ¤ S§X¡X£°!Ò!3ØˆOà�x‰x˜‰{ˆØ—‘˜!‘ˆØ�d‰?Ø%ˆHà˜‰}Ø(�ð* ˆð) ˜$‘Ø-�ð& ˆð% ˜$‘Ø/�ð" ˆð! ˜$‘Ø'�ð ˆð ˜$‘ %¨6¡/Ø4�ð ˆð ˜ÑØ%ˆHð ˆð ˜ÑØ%ˆHð ˆð ˜&Ñ Ø$ˆHà˜‰~Ø4�Ø˜‰}Ø/�àˆó    c                 óÌ  — t        j                  | «      }	 t        d„ |j                  «       j	                  «       D «       «      }ddddœ}|d   }||j                  «       v r|j                  ||   d¬«      }|j                  d	t         j                  «       t        j                  «       }|j                  |d
¬«       |j                  «       }|S # t        t        f$ r Y Œjw xY w)z°
        Generates a small and a big thumbnail of an image
        This will make it possible to preview the sent file

        :param file_path: The path to the image
        c              3   óp   K  — | ].  \  }}|t         j                  v rt         j                  |   |f–— Œ0 y ­w©N)r   ÚTAGS)Ú.0ÚkÚvs      r'   ú	<genexpr>z1AirDropUtil.generate_file_icon.<locals>.<genexpr>e   s6   è ø€ ò á�A�qØœŸ™Ñ%ô —‘˜qÑ! 1Ô%ñùs   ‚46é´   i  éZ   )é   é   é   ÚOrientationT)Úexpand)é  r9   ÚJPEG2000)Úformat)r   ÚopenÚdictÚ_getexifÚitemsÚkeysÚrotateÚAttributeErrorÚKeyErrorÚ	thumbnailÚ	ANTIALIASÚioÚBytesIOÚsaveÚgetvalue)Ú	file_pathÚimÚexifÚanglesÚorientationÚ	img_bytesÚ	file_icons          r'   Úgenerate_file_iconzAirDropUtil.generate_file_iconY   sØ   € ô �Z‰Z˜	Ó"ˆð	Üñ àŸK™K›M×/Ñ/Ó1ôó ˆDð
  ¨Ñ,ˆFØ˜}Ñ-ˆKØ˜fŸk™k›mÑ+Ø—Y‘Y˜v kÑ2¸4�YÓ@�ð
 	�‰�Z¤§¡Ô1Ü—J‘J“Lˆ	Ø
�‰�	 *ˆÔ-Ø×&Ñ&Ó(ˆ	ð Ðøô ¤Ð)ò 	Ùð	ús   —A!C ÃC#Ã"C#c                 ó  — d„ } || «      }|€y|j                   D ]d  }|j                  r&|r$t        j                  |j                  d   «      c S |j
                  sŒB|rŒEt        j                  |j                  «      c S  y)aQ  
        Get the ip address in IPv4 or IPv6 for a specific network interface

        :param str interface_name: declares the network interface name for which the ip should be accessed
        :param bool ipv6: Boolean indicating if the ipv6 address should be retrieved
        :return: IPv4Address or IPv6Address object or None
        c                 ó\   — t        j                  «       D ]  }|j                  | k(  sŒ|c S  y r,   )ÚifaddrÚget_adaptersÚname)rV   Ú	interfaces     r'   Úget_interface_by_namez?AirDropUtil.get_ip_for_interface.<locals>.get_interface_by_name‰   s1   € Ü#×0Ñ0Ó2ò %�	Ø—>‘> TÓ)Ø$Ò$ð%ð r)   Nr   )ÚipsÚis_IPv6Ú	ipaddressÚIPv6AddressÚipÚis_IPv4ÚIPv4Address)Úinterface_nameÚipv6rX   rW   r]   s        r'   Úget_ip_for_interfacez AirDropUtil.get_ip_for_interface   s{   € ò	ñ *¨.Ó9ˆ	ØÐØà—-‘-ò 	4ˆBØ�zŠz™dÜ ×,Ñ,Ø—E‘E˜!‘Hóò ð �z‹z¢$Ü ×,Ñ,¨R¯U©UÓ3Ò3ð	4ð r)   c                 óà  — | j                   sy t        j                  j                  | j                  «      st        j
                  | j                  «       t        j                  j                  | j                  |«      }t        |d«      5 }t        |d«      r1|j                  |j                  «       «       |j                  d«       n|j                  |«       d d d «       y # 1 sw Y   y xY w)NÚwbÚreadr   )ÚdebugÚosÚpathÚexistsÚ	debug_dirÚmakedirsÚjoinr<   ÚhasattrÚwritere   Úseek)ÚconfigÚdataÚ	file_nameÚdebug_file_pathÚfiles        r'   Úwrite_debugzAirDropUtil.write_debug�   s¢   € à�|Š|ØÜ�w‰w�~‰~˜f×.Ñ.Ô/Ü�K‰K˜×(Ñ(Ô)ÜŸ'™'Ÿ,™, v×'7Ñ'7¸ÓCˆÜ�/ 4Ó(ð 	!¨DÜ�t˜VÔ$Ø—
‘
˜4Ÿ9™9›;Ô'Ø—	‘	˜!•à—
‘
˜4Ô ÷	!÷ 	!ñ 	!ús   ÂAC$Ã$C-N)F)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstaticmethodÚstrr(   rQ   rb   ru   © r)   r'   r   r   )   s`   „ ñð
 ð'˜Sò 'ó ð'ðR ñ#ó ð#ðJ òó ðð: ñ!ó ñ!r)   r   c                   ó   — e Zd Zd„ Zy)ÚAbsArchiveWritec           
      óª  — | j                   }t        |«      }|dk  rd}t        «       5 }t        d|«      }t	        |«      5 }	 t        ||«      }|t        k(  rn¡||_        t        |«       t        ||«       	 t        t        |«      d«      5 }		 |	j                  |«      }
|
snt        ||
t        |
«      «       Œ+	 ddd«       t#        |«       t%        |«       t&        j(                  j+                  |«      rnŒ·ddd«       ddd«       y# 1 sw Y   ŒQxY w# t        $ r}|j                   dk7  r‚ Y d}~Œrd}~ww xY w# 1 sw Y   ŒDxY w# 1 sw Y   yxY w)zM
        Read the given paths from disk and add them to the archive.
        r   i (  NÚrbé   )Ú_pointerr   r   r   r   r	   r   Úpathnamer   r   r<   r   re   r
   r!   ÚIOErrorÚerrnor   r   rg   rh   Úisdir)Úselfrh   Ú
store_pathÚwrite_pÚ
block_sizeÚentry_pÚentryÚread_pÚrÚfrq   Úes               r'   Úadd_abs_filezAbsArchiveWrite.add_abs_file­   sR  € ð —-‘-ˆä.¨wÓ7ˆ
Ø˜Š?ØˆJäÓ ð 	 GÜ   wÓ/ˆEÜ& tÓ,ð °ØÜ)¨&°'Ó:�AØœKÒ'ØØ%/�E”NÜ% fÔ-Ü  ¨'Ô2ð	"Ü!Ô"2°7Ó";¸TÓBð EÀaØ"&Ø'(§v¡v¨jÓ'9 Ù'+Ø$)Ü *¨7°D¼#¸d»)Ô Dð	 #'ð %*÷	Eô ' wÔ/Ü Ô(Ü—w‘w—}‘} TÔ*Øð) ÷÷	ð 	÷Eð Eûô #ò "ØŸ7™7 bš=Ø!ô )ûð"ú÷ð ú÷	ð 	úse   ©E	Á6D=Á8DÂ-DÂ;DÃ7D=Ã:E	ÄDÄDÄ	D:Ä D5Ä0D=Ä5D:Ä:D=Ä=E	ÅE	Å	EN)rv   rw   rx   r‘   r|   r)   r'   r~   r~   ¬   s   „ ó!r)   r~   )ry   rF   r[   rg   rT   Úlibarchive.entryr   r   Úlibarchive.ffir   r   r   r   r	   r
   r   r   r   Úlibarchive.writer   r   ÚPILr   r   r   r~   r|   r)   r'   ú<module>r–      sL   ðñó& 
Û Û 	ã ß <÷
÷ 
õ 
÷ Aß ÷@!ñ @!ôF"�lõ "r)   