
    [h                         d Z dZdZddlZddlmZ ddlmZmZm	Z	 ddl
mZmZ ddlmZ d	efd
Zde	eeeedf   d	efdZdeeef   deeef   d	ee   fdZdeeef   deeef   d	efdZy)zCopyright 2021, 3LizzGPL version 3zinfo@3liz.org    N)Path)DictTupleUnion)QgisQgsMessageLog)Loggerreturnc                     t        t              j                  j                  d      } t	        j
                         }	 |j                  | d       |d   d   S # t        $ r( t        j                  ddt        j                         Y yw xY w)	z% Returns the Lizmap current version. zmetadata.txtutf8)encodinggeneralversionzqError, an UnicodeDecodeError occurred while reading the metadata.txt. Is the locale correctly set on the server ?
AtlasPrintNULL)r   __file__parentjoinpathconfigparserConfigParserreadUnicodeDecodeErrorr   
logMessager   Critical)	file_pathconfigs     0/var/www/qgis-server/plugins/atlasprint/tools.pyr   r      s    X%%..~>I&&(F,I/ i ++  	
 	  ,$--	) 	s   A .B
	B
valc                 \    t        | t              r| j                         dv S t        |       S )z! Convert config value to boolean )yestruet1)
isinstancestrlowerbool)r   s    r   to_boolr(   #   s(    #syy{777Cy    paramsheadersc                    g }t               }|r|j                  d       |j                  d      }|m|j                  d      D cg c]  }|j	                          }}|j                  dj                  dj                  |                   n|j                  d       t        |      dk7  rt        |      S |j                  d       | rn| j                  d      }|[|j                  d      D cg c]  }|j	                          }}|j                  d	j                  dj                  |                   t        |      S c c}w c c}w )
z Get Lizmap user groups provided by the request

    COPIED from Lizmap plugin, server side in core.py
    Only the signature is simplified.
    This code is tested in the Lizmap plugin.
    Request headers providedzX-Lizmap-User-Groups,z*Lizmap user groups in request headers : {}No request headers providedr   z(No lizmap user groups in request headersLIZMAP_USER_GROUPSz%Lizmap user groups in parameters : {})	r	   infogetsplitstripformatjoinlentuple)r*   r+   groupsloggeruser_groupsgs         r   get_lizmap_groupsr=   ,   s%    FXF ./kk"89")4):):3)?@Aaggi@F@KKDKKCHHU[L\]^12
6{aV}
KK:; jj!56")4):):3)?@Aaggi@F@KK?FFsxxPVGWXY =) A  As   E2E
c                 :   d}t               }|r;|j                  d       |j                  d      }|(|}|j                  d|        n|j                  d       |r|S |j                  d       | r)| j                  d      }||}|j                  d|        |S )	z Get Lizmap user login provided by the request

    COPIED from Lizmap plugin, server side in core.py
    Only the signature is simplified.
    This code is tested in the Lizmap plugin.
     r-   zX-Lizmap-Userz'Lizmap user login in request headers : r/   z'No lizmap user login in request headersLIZMAP_USERz"Lizmap user login in parameters : )r	   r1   r2   )r*   r+   loginr:   
user_logins        r   get_lizmap_user_loginrC   U   s     EXF ./[[1
!EKKA%IJ12
KK9: ZZ.
!EKK<UGDELr)   )__copyright____license__	__email__r   pathlibr   typingr   r   r   	qgis.corer   r   atlasprint.loggerr	   r%   r   intfloatr'   r(   r=   rC    r)   r   <module>rN      s   &	   % % ) $, ,(sCd23  &d38n &tCH~ &%PS* &R$$sCx. $4S> $c $r)   