ó
–‰]c           @@ s¾   d  d l  m Z m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z m	 Z	 d  d l
 m Z d  d l m Z m Z m Z m Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d S(   i    (   t   absolute_importt   unicode_literals(   t   copy(   t	   safe_repr(   t   Strict(   t   MinMaxt   Sequence(   t   Serialisable(   t   range_boundariest   range_to_tuplet   get_column_lettert   quote_sheetnamet	   CellRangec           B@ s  e  Z d  Z e d d d d d e ƒ Z e d d d d d e ƒ Z e d d d d d e ƒ Z e d d d d d e ƒ Z d% d% d% d% d% d% d „ Z
 e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z d d d „ Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z e Z d „  Z d „  Z d „  Z  d „  Z! e! Z" d „  Z# e# Z$ d „  Z% d d d d d „ Z& d d d d d „ Z' e d  „  ƒ Z( e d! „  ƒ Z) e d" „  ƒ Z* e d# „  ƒ Z+ e d$ „  ƒ Z, RS(&   uÜ  
    Represents a range in a sheet: title and coordinates.

    This object is used to perform operations on ranges, like:

    - shift, expand or shrink
    - union/intersection with another sheet range,

    We can check whether a range is:

    - equal or not equal to another,
    - disjoint of another,
    - contained in another.

    We can get:

    - the size of a range.
    - the range bounds (vertices)
    - the coordinates,
    - the string representation,

    t   mini   t   maxifG  t   expected_typei   c         C@ së   | d  k	 rT d | k r9 t | ƒ \ } \ } } } } qT t | ƒ \ } } } } n  | |  _ | |  _ | |  _ | |  _ | |  _ | | k r´ d } t | j	 d | d | ƒ ƒ ‚ n  | | k rç d } t | j	 d | d | ƒ ƒ ‚ n  d  S(   Nu   !u(   {max_col} must be greater than {min_col}t   min_colt   max_colu(   {max_row} must be greater than {min_row}t   min_rowt   max_row(
   t   NoneR	   R   R   R   R   R   t   titlet
   ValueErrort   format(   t   selft   range_stringR   R   R   R   R   t   fmt(    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __init__1   s    !					!c         C@ s   |  j  |  j |  j |  j f S(   u2   
        Vertices of the range as a tuple
        (   R   R   R   R   (   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   boundsG   s    c      	   C@ sm   d } |  j  |  j k r3 |  j |  j k r3 d } n  | j d t |  j  ƒ d |  j d t |  j ƒ d |  j ƒ S(   u9   
        Excel-style representation of the range
        u%   {min_col}{min_row}:{max_col}{max_row}u   {min_col}{min_row}R   R   R   R   (   R   R   R   R   R   R
   (   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   coordO   s    			c         c@ sY   xR t  |  j |  j d ƒ D]7 } g  t  |  j |  j d ƒ D] } | | f ^ q: Vq Wd S(   u1   
        Return cell coordinates as rows
        i   N(   t   rangeR   R   R   R   (   R   t   rowt   col(    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   rows`   s     c         c@ sY   xR t  |  j |  j d ƒ D]7 } g  t  |  j |  j d ƒ D] } | | f ^ q: Vq Wd S(   u4   
        Return cell coordinates as columns
        i   N(   R   R   R   R   R   (   R   R    R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   colsi   s     c         C@ sX   t  | t ƒ s* t t t | ƒ ƒ ƒ ‚ n  | j rT |  j | j k rT t d ƒ ‚ n  d S(   u²   
        Check whether comparisons between ranges are possible.
        Cannot compare ranges from different worksheets
        Skip if the range passed in has no title.
        u1   Cannot work with ranges from different worksheetsN(   t
   isinstanceR   t	   TypeErrort   reprt   typeR   R   (   R   t   other(    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   _check_titler   s    c         C@ sF   d } |  j  r d } n  t | j d |  j j d |  j  d |  j ƒ ƒ S(   Nu   <{cls} {coord}>u   <{cls} {title!r}!{coord}>t   clsR   R   (   R   R   R   t	   __class__t   __name__R   (   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __repr__   s    		c         C@ sC   d } |  j  } | r* d } t | ƒ } n  | j d | d |  j ƒ S(   Nu   {coord}u   {title}!{coord}R   R   (   R   R   R   R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   _get_range_string†   s    	c         C@ s   |  j  ƒ  } t | ƒ S(   N(   R-   R   (   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __str__‘   s    c         C@ s7   |  j  d |  j d |  j d |  j d |  j d |  j ƒ S(   NR   R   R   R   R   (   R*   R   R   R   R   R   (   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __copy__–   s    i    c         C@ s   |  j  | d k s& |  j | d k rA t d j | | ƒ ƒ ‚ n  |  j  | 7_  |  j | 7_ |  j | 7_ |  j | 7_ d S(   u{  
        Shift the focus of the range according to the shift values (*col_shift*, *row_shift*).

        :type col_shift: int
        :param col_shift: number of columns to be moved by, can be negative
        :type row_shift: int
        :param row_shift: number of rows to be moved by, can be negative
        :raise: :class:`ValueError` if any row or column index < 1
        i    u1   Invalid shift value: col_shift={0}, row_shift={1}N(   R   R   R   R   R   R   (   R   t	   col_shiftt	   row_shift(    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   shiftœ   s    c         C@ sl   y |  j  | ƒ Wn t k
 r% t SX| j |  j k pk |  j | j k pk | j |  j k pk |  j | j k S(   uÏ   
        Test whether the ranges are not equal.

        :type other: openpyxl.worksheet.cell_range.CellRange
        :param other: Other sheet range
        :return: ``True`` if *range* != *other*.
        (   R(   R   t   TrueR   R   R   R   (   R   R'   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __ne__°   s    c         C@ s   |  j  | ƒ S(   uË   
        Test whether the ranges are equal.

        :type other: openpyxl.worksheet.cell_range.CellRange
        :param other: Other sheet range
        :return: ``True`` if *range* == *other*.
        (   R4   (   R   R'   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __eq__Å   s    c         C@ so   |  j  | ƒ | j |  j k o; |  j k o; | j k n on | j |  j k ol |  j k ol | j k SS(   uâ   
        Test whether every cell in this range is also in *other*.

        :type other: openpyxl.worksheet.cell_range.CellRange
        :param other: Other sheet range
        :return: ``True`` if *range* <= *other*.
        (   R(   R   R   R   R   (   R   R'   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   issubsetÐ   s    3c         C@ s   |  j  | ƒ o |  j | ƒ S(   ué   
        Test whether *other* contains every cell of this range, and more.

        :type other: openpyxl.worksheet.cell_range.CellRange
        :param other: Other sheet range
        :return: ``True`` if *range* < *other*.
        (   t   __le__R4   (   R   R'   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __lt__ã   s    c         C@ so   |  j  | ƒ |  j | j k o; | j k o; |  j k n on |  j | j k ol | j k ol |  j k SS(   uõ   
        Test whether every cell in *other* is in this range.

        :type other: openpyxl.worksheet.cell_range.CellRange
        :param other: Other sheet range
        :return: ``True`` if *range* >= *other* (or *other* in *range*).
        (   R(   R   R   R   R   (   R   R'   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt
   issupersetî   s    3c         C@ s:   |  j  | ƒ } | j d k r- |  j | _ n  |  j | ƒ S(   uO   
        Check whether the range contains a particular cell coordinate
        N(   R*   R   R   R9   (   R   R   t   cr(    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __contains__  s    c         C@ s   |  j  | ƒ o |  j | ƒ S(   ué   
        Test whether this range contains every cell in *other*, and more.

        :type other: openpyxl.worksheet.cell_range.CellRange
        :param other: Other sheet range
        :return: ``True`` if *range* > *other*.
        (   t   __ge__R4   (   R   R'   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __gt__  s    c         C@ sc   |  j  | ƒ |  j | j k r/ | |  }  } n  |  j | j k  pb |  j | j k  pb | j |  j k  S(   uV  
        Return ``True`` if this range has no cell in common with *other*.
        Ranges are disjoint if and only if their intersection is the empty range.

        :type other: openpyxl.worksheet.cell_range.CellRange
        :param other: Other sheet range.
        :return: ``True`` if the range has no cells in common with other.
        (   R(   R   R   R   R   R   (   R   R'   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt
   isdisjoint  s    	c      	   C@ s   |  j  | ƒ r* t d j |  | ƒ ƒ ‚ n  t |  j | j ƒ } t |  j | j ƒ } t |  j | j ƒ } t |  j | j ƒ } t	 d | d | d | d | ƒ S(   uN  
        Return a new range with cells common to this range and *other*

        :type other: openpyxl.worksheet.cell_range.CellRange
        :param other: Other sheet range.
        :return: the intersecting sheet range.
        :raise: :class:`ValueError` if the *other* range doesn't intersect
            with this range.
        u   Range {0} doesn't intersect {0}R   R   R   R   (
   R>   R   R   R   R   R   R   R   R   R   (   R   R'   R   R   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   intersection*  s    
c         C@ s‰   |  j  | ƒ t |  j | j ƒ } t |  j | j ƒ } t |  j | j ƒ } t |  j | j ƒ } t d | d | d | d | d |  j ƒ S(   u  
        Return the minimal superset of this range and *other*. This new range
        will contain all cells from this range, *other*, and any additional
        cells required to form a rectangular ``CellRange``.

        :type other: openpyxl.worksheet.cell_range.CellRange
        :param other: Other sheet range.
        :return: a ``CellRange`` that is a superset of this and *other*.
        R   R   R   R   R   (	   R(   R   R   R   R   R   R   R   R   (   R   R'   R   R   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   unionB  s    
c         c@ sD   x= |  j  D]2 } | d k r" q
 n  t |  | ƒ } | | f Vq
 Wd S(   uC   
        For use as a dictionary elsewhere in the library.
        u   titleN(   t	   __attrs__t   getattr(   R   t   xt   v(    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __iter__X  s
    c         C@ s@   |  j  | 8_  |  j | 8_ |  j | 7_ |  j | 7_ d S(   u¦  
        Expand the range by the dimensions provided.

        :type right: int
        :param right: expand range to the right by this number of cells
        :type down: int
        :param down: expand range down by this number of cells
        :type left: int
        :param left: expand range to the left by this number of cells
        :type up: int
        :param up: expand range up by this number of cells
        N(   R   R   R   R   (   R   t   rightt   downt   leftt   up(    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   expandc  s    c         C@ s@   |  j  | 7_  |  j | 7_ |  j | 8_ |  j | 8_ d S(   uÀ  
        Shrink the range by the dimensions provided.

        :type right: int
        :param right: shrink range from the right by this number of cells
        :type down: int
        :param down: shrink range from the top by this number of cells
        :type left: int
        :param left: shrink range from the left by this number of cells
        :type up: int
        :param up: shrink range from the bottown by this number of cells
        N(   R   R   R   R   (   R   RF   t   bottomRH   t   top(    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   shrinkv  s    c         C@ s:   |  j  d |  j } |  j d |  j } i | d 6| d 6S(   uC    Return the size of the range as a dictionary of rows and columns. i   u   columnsu   rows(   R   R   R   R   (   R   R"   R!   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   size‰  s    c         C@ s3   g  t  |  j |  j d ƒ D] } |  j | f ^ q S(   u=   A list of cell coordinates that comprise the top of the rangei   (   R   R   R   R   (   R   R    (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyRL   ‘  s    c         C@ s3   g  t  |  j |  j d ƒ D] } |  j | f ^ q S(   u@   A list of cell coordinates that comprise the bottom of the rangei   (   R   R   R   R   (   R   R    (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyRK   —  s    c         C@ s3   g  t  |  j |  j d ƒ D] } | |  j f ^ q S(   uC   A list of cell coordinates that comprise the left-side of the rangei   (   R   R   R   R   (   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyRH     s    c         C@ s3   g  t  |  j |  j d ƒ D] } | |  j f ^ q S(   uD   A list of cell coordinates that comprise the right-side of the rangei   (   R   R   R   R   (   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyRF   £  s    N(-   R+   t
   __module__t   __doc__R   t   intR   R   R   R   R   R   t   propertyR   R   R!   R"   R(   R,   R-   t   __unicode__R.   R/   R2   R4   R5   R6   R7   R8   R9   R<   R;   R=   R>   R?   t   __and__R@   t   __or__RE   RJ   RM   RN   RL   RK   RH   RF   (    (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyR      sP   														
					t   MultiCellRangec           B@ s’   e  Z e d  e ƒ Z d d „ Z d „  Z d „  Z d „  Z e Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z e Z d
 „  Z d „  Z d „  Z RS(   R   c         C@ sD   t  | t ƒ r7 g  | j ƒ  D] } t | ƒ ^ q } n  | |  _ d  S(   N(   R#   t   strt   splitR   t   ranges(   R   RY   t   r(    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyR   ¯  s    (c         C@ s(   x! |  j  D] } | | k r
 t Sq
 Wt S(   N(   RY   R3   t   False(   R   R   RZ   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyR;   µ  s    c         C@ sA   d j  g  |  j D] } t | ƒ ^ q ƒ } d j |  j j | ƒ S(   Nu    u   <{0} [{1}]>(   t   joinRY   RW   R   R*   R+   (   R   RZ   RY   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyR,   ¼  s    +c         C@ s/   d j  g  |  j D] } t | ƒ ^ q ƒ } | S(   Nu    (   R\   RY   RW   (   R   RZ   RY   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyR.   Á  s    +c         C@ st   d } t | t ƒ r' | } | j } n  | |  k rp | d k rN t | ƒ } n  |  j } | j | ƒ | |  _ n  d S(   u4   
        Add a cell coordinate or CellRange
        N(   R   R#   R   R   RY   t   append(   R   R   R:   RY   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   addÈ  s    	c         C@ s   |  j  | ƒ |  S(   N(   R^   (   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __iadd__Ø  s    c         C@ s1   t  | t ƒ r! |  j | ƒ } n  |  j | j k S(   N(   R#   RW   R*   RY   (   R   R'   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyR5   Ý  s    c         C@ s   |  | k S(   N(    (   R   R'   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyR4   ã  s    c         C@ s   t  |  j ƒ S(   N(   t   boolRY   (   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   __bool__ç  s    c         C@ s2   t  | t ƒ s t | ƒ } n  |  j j | ƒ d  S(   N(   R#   R   RY   t   remove(   R   R   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyRb   í  s    c         c@ s   x |  j  D] } | Vq
 Wd  S(   N(   RY   (   R   R:   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyRE   ó  s    c         C@ s7   t  ƒ  } x' |  j D] } | j j t | ƒ ƒ q W| S(   N(   RV   RY   R]   R   (   R   t   nRZ   (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyR/   ø  s    	(    (   R+   RO   R   R   RY   R   R;   R,   R.   RS   R^   R_   R5   R4   Ra   t   __nonzero__Rb   RE   R/   (    (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyRV   ©  s   										N(   t
   __future__R    R   R   t   openpyxl.compat.stringsR   t   openpyxl.descriptorsR   R   R   t!   openpyxl.descriptors.serialisableR   t   openpyxl.utilsR   R	   R
   R   R   RV   (    (    (    s<   lib/python2.7/site-packages/openpyxl/worksheet/cell_range.pyt   <module>   s   "ÿ —