
    XZ                      F    d dl Z d dlZd dlZd dlZd dlmZ  G d de      Zy)    N)localeCc                   H   e Zd ZdZe	 	 dd       Zd Zd Zd Ze	d        Z
 e	d d	       Z e	d
 d       Z e	d d       Zedd       Zed        Zed        Zedd       Zedd       Zed        Zed        Zed        Zed        Zedd       Zed        Zd Zy)Geometrya$  Geometry()

       Geometry represents a region on a device in the system - a disk or
       partition.  It is expressed in terms of a starting sector and a length.
       Many methods (read and write methods in particular) throughout pyparted
       take in a Geometry object as an argument.Nc                 V   |rA|| _         |0t        j                  | j                   j                        | _        y|| _        y|s<|| _        t        j                  | j                  j                         ||      | _         y|sI||kD  rD|| _        t        j                  | j                  j                         |||z
  dz   |      | _         y|rG|rE|rC||kD  r>|| _        t        j                  | j                  j                         |||      | _         yt        j                  d      )zCreate a new Geometry object for the given _ped.Device that extends
           for length sectors from the start sector.  Optionally, an end sector
           can also be provided.N)	PedDevice   )endzkmust specify PedGeometry or (device, start, length) or (device, start, end) or (device, start, length, end))
_Geometry__geometrypartedDevicedev_device_pedr   devicegetPedDeviceGeometryException)selfr   startlengthr	   PedGeometrys         1/usr/lib/python3/dist-packages/parted/geometry.py__init__zGeometry.__init__)   s     )DO~%}}t7J7JK%!DL"mmDKK,D,D,FvVDOS5[!DL"mmDKK,D,D,FPSV[P[^_P_fijDOv#3;!DL"mmDKK,D,D,Fv[^_DO**  ,Y  Z  Z    c                 &    | j                  |       S N)__ne__r   others     r   __eq__zGeometry.__eq__B   s    ;;u%%%r   c                     t        | |j                        sy| j                  |j                  k7  xs4 | j                  |j                  k7  xs | j                  |j                  k7  S )NT)
isinstance	__class__r   r   r   r   s     r   r   zGeometry.__ne__E   sM    $0{{ell*fdjjEKK.Gf4;;Z_ZfZfKffr   c                     d| j                   | j                  | j                  | j                  | j                  dz  }|S )Nz{parted.Geometry instance --
  start: %(start)s  end: %(end)s  length: %(length)s
  device: %(device)r  PedGeometry: %(ped)r)r   r	   r   r   ped)r   r	   r   r   r
   )r   ss     r   __str__zGeometry.__str__K   s<    : zz$((dkkDOO==
 r   c                     | j                   S )z#The Device this geometry describes.)r   r   s    r   r   zGeometry.deviceS   s     ||r   c                 .    | j                   j                  S r   )r
   r   r%   s    r   <lambda>zGeometry.<lambda>X   s    q||11 r   c                 8    | j                   j                  |      S r   )r
   	set_startr%   vs     r   r+   zGeometry.<lambda>X   s    @V@VWX@Y r   c                 .    | j                   j                  S r   )r
   r	   r*   s    r   r+   zGeometry.<lambda>Y   s    Q\\-- r   c                 8    | j                   j                  |      S r   )r
   set_endr.   s     r   r+   zGeometry.<lambda>Y   s    ALL<P<PQR<S r   c                 .    | j                   j                  S r   )r
   r   r*   s    r   r+   zGeometry.<lambda>Z   s     3 3 r   c                 b    | j                   j                  | j                   j                  |      S r   )r
   setr   r.   s     r   r+   zGeometry.<lambda>Z   s%    !,,BRBRSTS_S_SeSeghBi r   c                 |    |s| j                   j                  |||      S | j                   j                  ||||      S )a5  Check the region described by self for errors on the disk.
           offset -- The beginning of the region to check, in sectors from the
                     start of the geometry.
           granularity -- How sectors should be grouped together
           count -- How many sectors from the region to check.)r
   check)r   offsetgranularitycounttimers        r   r7   zGeometry.check\   s;     ??((eDD??((eUKKr   c                 T    | j                   j                  |j                               S )zgReturn whether Geometry b is contained entirely within self and on
           the same physical device.)r
   test_insidegetPedGeometryr   bs     r   containszGeometry.containsh   s"     **1+;+;+=>>r   c                 8    | j                   j                  |      S )z=Return whether the sectory is contained entirely within self.)r
   test_sector_inside)r   sectors     r   containsSectorzGeometry.containsSectorn   s     11&99r   c                 L   t        j                  dt               |j                         }| j                  | j
                  j                  z  }|t        j                  j                         vrt        d|z        |t        j                  dt        j                  |         z  S )aW  Return the size of the geometry in the unit specified.  The unit
           is given as a string corresponding to one of the following
           abbreviations:  b (bytes), KB (kilobytes), MB (megabytes), GB
           (gigabytes), TB (terabytes).  An invalid unit string will raise a
           SyntaxError exception.  The default unit is MB.zuse the getLength methodzinvalid unit %s giveng      @)warningswarnDeprecationWarninglowerr   r   
sectorSizer   	_exponentkeysSyntaxErrormathpow)r   unitlunitsizes       r   getSizezGeometry.getSizes   s     	02DE

{{T[[333((--//5>??txx(8(8(?@@Ar   c                     | j                   }|dk(  r|S t        j                  || j                  j                  z  |      S )zReturn the length of the geometry in sectors. Optionally, a SI or
           IEC prefix followed by a 'B' may be given in order to convert the
           length into bytes. The allowed values include B, kB, MB, GB, TB, KiB,
           MiB, GiB, and TiB.sectors)r   r   formatBytesr   rK   )r   rQ   rV   s      r   	getLengthzGeometry.getLength   s<     ++9N!!'DKK,B,B"BDIIr   c                 h    t        | j                  j                  |j                                     S )zReturn a new Geometry describing the region common to both self
           and Geometry b.  Raises ArithmeticError if the regions do not
           intersect.r   )r   r
   	intersectr>   r?   s     r   r[   zGeometry.intersect   s'    
 DOO$=$=a>N>N>P$QRRr   c                 ~    t        j                  | j                  j                  |j	                         |            S )zGiven a Geometry src that overlaps with self and a sector inside src,
           this method translates the address of the sector into an address
           inside self.  If self does not contain sector, ArithmeticError will
           be raised.rZ   )r   r   r
   mapr>   )r   srcrD   s      r   r]   zGeometry.map   s.     4??+>+>s?Q?Q?SU[+\]]r   c                 v    	 | j                   j                  |j                                y# t        $ r Y yw xY w)zgReturn whether self and b are on the same device and share at least
           some of the same region.TF)r
   r[   r>   ArithmeticErrorr?   s     r   overlapsWithzGeometry.overlapsWith   s7    	OO%%a&6&6&89 		s   ), 	88c                 :    | j                   j                  ||      S )zRead data from the region described by self.
           offset -- The number of sectors from the beginning of the region
                     (not the beginning of the disk) to read.
           count  -- The number of sectors to read.)r
   read)r   r8   r:   s      r   rc   zGeometry.read   s     ##FE22r   c                 n    |r| j                   j                         S | j                   j                         S )zFlushes all caches on the device described by self.  If fast is
           True, the flush will be quicked by cache coherency is not
           guaranteed.)r
   	sync_fastsync)r   fasts     r   rf   zGeometry.sync   s-    
 ??,,..??''))r   c                 <    | j                   j                  |||      S )a1  Write data into the region described by self.
           buf    -- The data to be written.
           offset -- Where to start writing to region, expressed as the number
                     of sectors from the start of the region (not the disk).
           count  -- How many sectors of buf to write out.)r
   write)r   bufr8   r:   s       r   ri   zGeometry.write   s     $$S&%88r   c                     | j                   S )zdReturn the _ped.Geometry object contained in this Geometry.
           For internal module use only.)r
   r(   s    r   r>   zGeometry.getPedGeometry   s     r   )NNNNNr   )MB)rV   )F)__name__
__module____qualname____doc__r   r   r   r   r&   propertyr   r   r	   r   r7   rA   rE   rT   rX   r[   r]   ra   rc   rf   ri   r>    r   r   r   r   "   s\   4 AE!Z Z0&g   13YZE
-/S
TC35ijF	L 	L ? ?
 : : B B J J S S ^ ^   3 3 * * 9 9r   r   )rO   rG   r   r   parted.decoratorsr   objectr   rr   r   r   <module>ru      s$   4     %cv cr   