ó
çQc           @   s«   d  Z  d d l Z d d l Z d d l m Z m Z m Z m Z d d l m	 Z	 d Z
 d e f d     YZ d   Z i d	 d
 6d d 6d d 6d d 6d d 6Z d   Z d S(   s'  extend schemes with shortcuts to repository swarms

This extension allows you to specify shortcuts for parent URLs with a
lot of repositories to act like a scheme, for example::

  [schemes]
  py = http://code.python.org/hg/

After that you can use it like::

  hg clone py://trunk/

Additionally there is support for some more complex schemas, for
example used by Google Code::

  [schemes]
  gcode = http://{1}.googlecode.com/hg/

The syntax is taken from Mercurial templates, and you have unlimited
number of variables, starting with ``{1}`` and continuing with
``{2}``, ``{3}`` and so on. This variables will receive parts of URL
supplied, split by ``/``. Anything not specified as ``{part}`` will be
just appended to an URL.

For convenience, the extension adds these schemes by default::

  [schemes]
  py = http://hg.python.org/
  bb = https://bitbucket.org/
  bb+ssh = ssh://hg@bitbucket.org/
  gcode = https://{1}.googlecode.com/hg/
  kiln = https://{1}.kilnhg.com/Repo/

You can override a predefined scheme by defining a new scheme with the
same name.
iÿÿÿÿN(   t
   extensionst   hgt	   templatert   util(   t   _t   internalt   ShortRepositoryc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   sg   | |  _  | |  _ | |  _ y+ t t t t j d |  j    |  _ Wn t	 k
 rb d |  _ n Xd  S(   Ns	   \{(\d+)\}i    (
   t   schemeR   t   urlt   maxt   mapt   intt   ret   findallt   partst
   ValueError(   t   selfR   R   R   (    (    s1   /sys/lib/python2.7/site-packages/hgext/schemes.pyt   __init__3   s    			+c         C   s   d |  j  S(   Ns   <ShortRepository: %s>(   R   (   R   (    (    s1   /sys/lib/python2.7/site-packages/hgext/schemes.pyt   __repr__<   s    c         C   së   y | j  d d  d } Wn* t k
 rF t j t d  |   n X| j  d |  j  } t |  |  j k r | d } | d  } n d } t d   t |  D  } d j	 |  j
 j |  j |   | } t j |  j | | |  S(   Ns   ://i   s   no '://' in scheme url '%s't   /iÿÿÿÿt    c         s   s+   |  ]! \ } } t  | d   | f Vq d S(   i   N(   t   str(   t   .0t   it   v(    (    s1   /sys/lib/python2.7/site-packages/hgext/schemes.pys	   <genexpr>K   s    (   t   splitt
   IndexErrorR   t   AbortR   R   t   lent   dictt	   enumeratet   joinR   t   processR   R   t   _peerlookupt   instance(   R   t   uiR   t   createR   t   tailt   context(    (    s1   /sys/lib/python2.7/site-packages/hgext/schemes.pyR"   ?   s    
%(   t   __name__t
   __module__R   R   R"   (    (    (    s1   /sys/lib/python2.7/site-packages/hgext/schemes.pyR   2   s   			c         C   s;   | r1 x( t  D] } | j | d  r t Sq Wn  |  |  S(   Nt   :(   t   schemest
   startswitht   False(   t   origt   pathR   (    (    s1   /sys/lib/python2.7/site-packages/hgext/schemes.pyt   hasdriveletterO   s
    s   http://hg.python.org/t   pys   https://bitbucket.org/t   bbs   ssh://hg@bitbucket.org/s   bb+sshs   https://{1}.googlecode.com/hg/t   gcodes   https://{1}.kilnhg.com/Repo/t   kilnc         C   sæ   t  j t |  j d    t j d    } x t  j   D] \ } } t j d k r² t	 |  d k r² | j
   r² t j j d |  r² t j t d  | | j   f   n  t | | |  t j  | <q; Wt j t d t  d  S(   NR*   c         S   s   |  S(   N(    (   t   x(    (    s1   /sys/lib/python2.7/site-packages/hgext/schemes.pyt   <lambda>`   s    t   nti   s   %s:\s5   custom scheme %s:// conflicts with drive letter %s:\
R/   (   R*   t   updateR   t   configitemsR   t   enginet   itemst   ost   nameR   t   isalphaR.   t   existsR   R   R   t   upperR   R   R    t   wrapfunctionR/   (   R#   t   tR   R   (    (    s1   /sys/lib/python2.7/site-packages/hgext/schemes.pyt   extsetup^   s    -(   t   __doc__R;   R   t	   mercurialR    R   R   R   t   mercurial.i18nR   t
   testedwitht   objectR   R/   R*   RB   (    (    (    s1   /sys/lib/python2.7/site-packages/hgext/schemes.pyt   <module>)   s   "	
