§
    cÌc©(  ã                   ór  — d 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 ddlmZ  G d„ de	j        ¦  «        Z	 ddlZn# e$ rZ ee¦  «        ‚dZ[ww xY wdd	lmZmZmZmZ dd
lmZ dZd„ Zd„ Zd„ Z G d„ de	j        ¦  «        Z d„ Z!d„ Z" G d„ de¦  «        Z#ddej$        fd„Z% G d„ d¦  «        Z&dS )z)Tools for dealing with the Launchpad API.é    N)ÚurlparseÚ
urlunparseé   )ÚbranchÚbeddingÚerrorsÚosutilsÚtraceÚ	transport)Úgettextc                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚLaunchpadlibMissingz[launchpadlib is required for Launchpad API access. Please install the launchpadlib package.c                 óL   •— t          ¦   «                              d|¦  «         d S )NÚlaunchpadlib)ÚsuperÚ__init__)ÚselfÚeÚ	__class__s     €úA/usr/lib/python3/dist-packages/breezy/plugins/launchpad/lp_api.pyr   zLaunchpadlibMissing.__init__/   s.   ø€ Ý‰Œ×ÒØ˜Añ	ô 	ð 	ð 	ð 	ó    )Ú__name__Ú
__module__Ú__qualname__Ú_fmtr   Ú__classcell__©r   s   @r   r   r   *   s?   ø€ € € € € ð7€Dðð ð ð ð ð ð ð ð r   r   )ÚRequestTokenAuthorizationEngineÚCredentialStoreÚCredentialsÚAccessToken)Ú	Launchpad)é   é   r   c                  óN   — t          j        t          j        ¦   «         d¦  «        S )z6Return the directory to cache launchpadlib objects in.Ú	launchpad)r	   Úpathjoinr   Ú	cache_dir© r   r   Úget_cache_directoryr*   F   s   € åÔ�GÔ-Ñ/Ô/°Ñ=Ô=Ð=r   c                 ól   — t          t          t          |                      d¦  «        ¦  «        ¦  «        S )z9Parse a version number of the style used by launchpadlib.ú.)ÚtupleÚmapÚintÚsplit)Úversion_numbers    r   Úparse_launchpadlib_versionr2   K   s(   € å••S˜.×.Ò.¨sÑ3Ô3Ñ4Ô4Ñ5Ô5Ð5r   c                  óŽ   — t          t          j        ¦  «        } | t          k     r t	          j        ddt          ›d| ›�¦  «        ‚dS )z<Raise an error if launchpadlib has the wrong version number.r   zAt least launchpadlib z' is required, but installed version is N)r2   r   Ú__version__ÚMINIMUM_LAUNCHPADLIB_VERSIONr   ÚDependencyNotPresent)Úinstalled_versions    r   Ú check_launchpadlib_compatibilityr8   P   sY   € å2µ<Ô3KÑLÔLÐØÕ7Ò7Ð7ÝÔ)ØˆNå+Ð+Ð+Ð->Ð->ð@ñAô Að 	Að 8Ð7r   c                   ó   — e Zd ZdZd„ ZdS )ÚNoLaunchpadBranchz8No launchpad branch could be found for branch "%(url)s".c                 óT   — t           j                             | ||j        ¬¦  «         d S )N)r   Úurl)r   ÚBzrErrorr   Úbase)r   r   s     r   r   zNoLaunchpadBranch.__init__]   s'   € ÝŒ× Ò  ¨f¸&¼+Ð ÑFÔFÐFÐFÐFr   N)r   r   r   r   r   r)   r   r   r:   r:   Z   s-   € € € € € ØE€DðGð Gð Gð Gð Gr   r:   c                 ó,   — t          j        | d¦  «        S )NÚbreezy)r"   Úauthorization_engine_factory)Úbase_urls    r   Úget_auth_enginerC   a   s   € ÝÔ1°(¸HÑEÔEÐEr   c                  ó   — t          ¦   «         S ©N)ÚBreezyCredentialStorer)   r   r   Úget_credential_storerG   e   s   € Ý Ñ"Ô"Ð"r   c                   ó0   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zˆ xZS )rF   zGImplementation of the launchpadlib CredentialStore API for Breezy.
    Nc                 ót   •— t          ¦   «                              |¦  «         ddlm}  |¦   «         | _        d S )Nr   )ÚAuthenticationConfig)r   r   Úbreezy.configrJ   Úauth_config)r   Úcredential_save_failedrJ   r   s      €r   r   zBreezyCredentialStore.__init__o   sE   ø€ Ý‰Œ×ÒÐ/Ñ0Ô0Ð0Ø6Ð6Ð6Ð6Ð6Ð6Ø/Ð/Ñ1Ô1ˆÔÐÐr   c                 ó6  — | j                              |d|j        j        ¦  «         | j                              |d|j        j        ¦  «         | j                              |d|j        j        ¦  «         | j                              |d|j        j        ¦  «         dS )z2Store newly-authorized credentials in the keyring.Úconsumer_keyÚconsumer_secretÚaccess_tokenÚaccess_secretN)rL   Ú_set_optionÚconsumerÚkeyÚsecretrQ   )r   ÚcredentialsÚ
unique_keys      r   Údo_savezBreezyCredentialStore.do_savet   s»   € àÔ×$Ò$Ø˜¨Ô(<Ô(@ñ	Bô 	Bð 	BàÔ×$Ò$ØÐ)¨;Ô+?Ô+Fñ	Hô 	Hð 	HàÔ×$Ò$Ø˜¨Ô(@Ô(Dñ	Fô 	Fð 	FàÔ×$Ò$Ø˜¨Ô)AÔ)Hñ	Jô 	Jð 	Jð 	Jð 	Jr   c                 ój  — | j                              ¦   «                              |¦  «        }|r„|                     d¦  «        rot          |                     d¦  «        |                     d¦  «        ¦  «        }t	          |                     d¦  «        |                     d¦  «        |d¬¦  «        S dS )z&Retrieve credentials from the keyring.rR   rQ   rO   rP   ÚBreezy)Úconsumer_namerP   rQ   Úapplication_nameN)rL   Ú_get_configÚgetr!   r    )r   rX   Úauth_defrQ   s       r   Údo_loadzBreezyCredentialStore.do_load   s±   € àÔ#×/Ò/Ñ1Ô1×5Ò5°jÑAÔAˆØð 	+˜Ÿš _Ñ5Ô5ð 	+Ý&Ø—’˜^Ñ,Ô,Ø—’˜_Ñ-Ô-ñ/ô /ˆLõ Ø&Ÿlšl¨>Ñ:Ô:Ø (§¢Ð->Ñ ?Ô ?Ø)Ø!)ð	+ñ +ô +ð +ð
 ˆtr   rE   )r   r   r   Ú__doc__r   rY   ra   r   r   s   @r   rF   rF   k   sh   ø€ € € € € ðð ð2ð 2ð 2ð 2ð 2ð 2ð
	Jð 	Jð 	Jðð ð ð ð ð ð r   rF   c           
      ón  — |€ddl }|                     d¦  «        }	 t          ¦   «         }n# t          $ r d}Y nw xY wt	          ¦   «         }t          | ¦  «        }ddlm}  |¦   «         }	|	€.t          j	        d¦  «         t          j        d| ||||¬¦  «        S t          j        d| ||||||¬	¦  «        S )
z^Log in to the Launchpad API.

    :return: The root `Launchpad` object from launchpadlib.
    Nr   Úhttpsr#   )Úget_lp_loginz>Accessing launchpad API anonymously, since no username is set.r@   )r\   Úservice_rootÚlaunchpadlib_dirÚtimeoutÚ
proxy_infoÚversion)r]   rf   rg   rh   Úcredential_storeÚauthorization_engineri   rj   )Úhttplib2Úproxy_info_from_environmentr*   ÚOSErrorrG   rC   Úaccountre   r
   Úmutterr"   Úlogin_anonymouslyÚ
login_with)
rB   rh   ri   rj   rm   Úcache_directoryrk   rl   re   Úlp_users
             r   Úconnect_launchpadrv   Ž   s  € ð ÐØˆˆˆØ×9Ò9¸'ÑBÔBˆ
ðÝ-Ñ/Ô/ˆˆøÝð ð ð Øˆˆˆðøøøå+Ñ-Ô-ÐÝ*¨8Ñ4Ô4ÐØ%Ð%Ð%Ð%Ð%Ð%Øˆl‰nŒn€GØ€ÝŒØLñ	Nô 	Nð 	NåÔ*Ø"Ø!Ø,ØØ!Øðñ ô ð 	õ Ô#Ø%°HØ,°gØ-Ø!5Ø!¨7ð4ñ 4ô 4ð 	4s   �, ¬;º;c                   ó„   — e Zd ZdZdd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
d	„ Zd
„ Zd„ ZdS )ÚLaunchpadBranchz4Provide bzr and lp API access to a Launchpad branch.NTc                 óL   — || _         || _        d| _        || _        || _        dS )z¹Constructor.

        :param lp_branch: The Launchpad branch.
        :param bzr_url: The URL of the Bazaar branch.
        :param bzr_branch: An instance of the Bazaar branch.
        N)Úbzr_urlÚ_bzrÚ	_push_bzrÚ_check_updateÚlp)r   Ú	lp_branchrz   Ú
bzr_branchÚcheck_updates        r   r   zLaunchpadBranch.__init__¶   s,   € ð ˆŒØˆŒ	ØˆŒØ)ˆÔØˆŒˆˆr   c                 óp   — | j         €)t          j                             | j        ¦  «        | _         | j         S )z&Return the bzr branch for this branch.)r{   r   ÚBranchÚopenrz   ©r   s    r   ÚbzrzLaunchpadBranch.bzrÃ   s-   € ð Œ9ÐÝœ×*Ò*¨4¬<Ñ8Ô8ˆDŒIØŒyÐr   c                 óz   — | j         €.t          j                             | j        j        ¦  «        | _         | j         S )z'Return the push branch for this branch.)r|   r   rƒ   r„   r~   Úbzr_identityr…   s    r   Úpush_bzrzLaunchpadBranch.push_bzrÊ   s0   € ð Œ>Ð!Ý#œ]×/Ò/°´Ô0DÑEÔEˆDŒNØŒ~Ðr   c                 ó¤   — | €dS |                       d¦  «        rdS t          j        d¦  «        }t          |                     | ¦  «        ¦  «        S )z Is 'url' something that could conceivably be pushed to LP?

        :param url: A URL that may refer to a Launchpad branch.
        :return: A boolean.
        NFzlp:Tz3([a-z]*\+)*(bzr\+ssh|http)://bazaar.*.launchpad.net)Ú
startswithÚreÚcompileÚboolÚmatch)r<   Úregexs     r   Úplausible_launchpad_urlz'LaunchpadBranch.plausible_launchpad_urlÑ   sW   € ð ˆ;Ø�5Ø�>Š>˜%Ñ Ô ð 	Ø�4Ý”
ð 7ñ 8ô 8ˆå�E—K’K Ñ$Ô$Ñ%Ô%Ð%r   c              #   ó¸   K  — |                       ¦   «         }|�|V — |                      ¦   «         }|�|V — |                      ¦   «         }|�|V — | j        V — dS )z¯Iterate through related URLs that might be Launchpad URLs.

        :param bzr_branch: A Bazaar branch to find URLs from.
        :return: a generator of URL strings.
        N)Úget_public_branchÚget_push_locationÚ
get_parentr>   )r€   r<   s     r   Úcandidate_urlszLaunchpadBranch.candidate_urlsà   sy   è è € ð ×*Ò*Ñ,Ô,ˆØˆ?ØˆIˆIˆIØ×*Ò*Ñ,Ô,ˆØˆ?ØˆIˆIˆIØ×#Ò#Ñ%Ô%ˆØˆ?ØˆIˆIˆIØŒoÐÐÐÐÐr   c                 ó   — | j         }|j        �e|j        j        }|€)t          j        t          d¦  «        |j        z  ¦  «        ‚|j        }|€$t          j        t          d¦  «        |z  ¦  «        ‚nw|j        �G|j         	                    d¬¦  «        }|€)t          j        t          d¦  «        |j        z  ¦  «        ‚n)t          j        t          d¦  «        |j        z  ¦  «        ‚t          ||j        ¦  «        S )z8Return the 'LaunchpadBranch' for the target of this one.Nz%s has no development focus.z#development focus %s has no branch.ÚRelease)Úpocketz source package %s has no branch.z/%s has no associated product or source package.)r~   ÚprojectÚdevelopment_focusr   r=   r   rˆ   r   ÚsourcepackageÚ	getBranchrx   )r   r   Ú	dev_focusÚtargets       r   Ú
get_targetzLaunchpadBranch.get_targetò   s3  € à”Gˆ	ØÔÐ(Ø!Ô)Ô;ˆIØÐ Ý”o¥gÐ.LÑ&MÔ&MØ&/Ô&<ñ'=ñ >ô >ð >àÔ%ˆFØˆ~Ý”o¥gØ9ñ';ô ';Ø=Fñ'Gñ Hô Hð Hð ð Ô$Ð0ØÔ,×6Ò6¸iÐ6ÑHÔHˆFØˆ~Ý”o¥gØ&Hñ'Jô 'Jà&/Ô&=ñ'>ñ ?ô ?ð ?ð õ
 ”/¥'ØAñ#Cô #CàÔ&ñ#'ñ (ô (ð (õ ˜v vÔ':Ñ;Ô;Ð;r   c                 ó  — | j         sdS | j                             ¦   «         5  | j        j        ��| j                             ¦   «         | j        j        k    r<t          j        t          d¦  «        | j        j	        z  ¦  «         	 ddd¦  «         dS | j        j
                             ¦   «         }|                     t          j        | j        j        ¦  «        | j                             ¦   «         ¦  «        st          j        | j        | j        ¦  «        ‚t          j        t          d¦  «        | j        j	        z  ¦  «         | j                             | j        ¦  «         ddd¦  «         dS # 1 swxY w Y   dS )z)Update the Launchpad copy of this branch.Nz%s is already up-to-date.zPushing to %s)r}   r†   Ú	lock_readr~   Úlast_scanned_idÚlast_revisionr
   Únoter   rˆ   Ú
repositoryÚ	get_graphÚis_ancestorr	   Ú	safe_utf8r   ÚDivergedBranchesr‰   Úpush)r   Úgraphs     r   Ú	update_lpzLaunchpadBranch.update_lp
  s¯  € àÔ!ð 	ØˆFØŒX×ÒÑ!Ô!ð 	)ð 	)ØŒwÔ&Ñ2Ø”8×)Ò)Ñ+Ô+¨t¬wÔ/FÒFÐFÝ”J�wÐ'BÑCÔCØ#œwÔ3ñ 4ñ 5ô 5ð 5àð	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð œÔ+×5Ò5Ñ7Ô7�Ø×(Ò(­Ô):¸4¼7Ô;RÑ)SÔ)SØ)-¬×)?Ò)?Ñ)AÔ)AñCô Cð Kå Ô1°$´(¸D¼MÑJÔJÐJÝ”
�7 ?Ñ3Ô3°d´gÔ6JÑJÑKÔKÐKØŒH�MŠM˜$œ-Ñ(Ô(Ð(ð	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)øøøð 	)ð 	)ð 	)ð 	)ð 	)ð 	)s   £A$E4ÂCE4Å4E8Å;E8c                 ó  — | j         j                             |j         j        ¦  «        }|                     | j                              ¦   «         |j                              ¦   «         ¦  «        }| j         j                             |¦  «        S )z»Find the revision tree for the LCA of this branch and other.

        :param other: Another LaunchpadBranch
        :return: The RevisionTree of the LCA of this branch and other.
        )r†   r¦   r§   Úfind_unique_lcar¤   Úrevision_tree)r   Úotherr¬   Úlcas       r   Úfind_lca_treezLaunchpadBranch.find_lca_tree  sp   € ð ”Ô#×-Ò-¨e¬iÔ.BÑCÔCˆØ×#Ò# D¤H×$:Ò$:Ñ$<Ô$<Ø$)¤I×$;Ò$;Ñ$=Ô$=ñ?ô ?ˆàŒxÔ"×0Ò0°Ñ5Ô5Ð5r   )NT)r   r   r   rb   r   Úpropertyr†   r‰   Ústaticmethodr‘   r–   r    r­   r³   r)   r   r   rx   rx   ³   sÇ   € € € € € Ø>Ð>ðð ð ð ð ðð ñ „Xðð ðð ñ „Xðð ð&ð &ñ „\ð&ð ðð ñ „\ðð"<ð <ð <ð0)ð )ð )ð"	6ð 	6ð 	6ð 	6ð 	6r   rx   )'rb   Úbase64rŒ   Úurllib.parser   r   Ú r   r   r   r	   r
   r   Úi18nr   r6   r   r   ÚModuleNotFoundErrorr   Úlaunchpadlib.credentialsr   r   r    r!   Úlaunchpadlib.launchpadr"   r5   r*   r2   r8   r=   r:   rC   rG   rF   ÚDEFAULT_VERSIONrv   rx   r)   r   r   ú<module>r¾      sŽ  ðð" 0Ð /ð €€€Ø 	€	€	€	ðð ð ð ð ð ð ð ð
ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð Ð Ð Ð Ð Ð ðð ð ð ð ˜&Ô5ñ ô ð ð!ØÐÐÐÐøØð !ð !ð !Ø
Ð
˜aÑ
 Ô
 Ð øøøøð!øøøðð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð
  )Ð ð>ð >ð >ð
6ð 6ð 6ð
Að Að AðGð Gð Gð Gð G˜œñ Gô Gð GðFð Fð Fð#ð #ð #ð ð  ð  ð  ð  ˜Oñ  ô  ð  ðF )-¸Ø'Ô7ð!4ð !4ð !4ð !4ðJq6ð q6ð q6ð q6ð q6ñ q6ô q6ð q6ð q6ð q6s   ½A ÁAÁAÁA