
    ^W                         d dl mZ d dlZd dlZ	 e  G d dej                        Zedk(  r ed      Z	de	_
         ee	       yy# e$ r eZY <w xY w)    )absolute_importNc                   b    e Zd ZdZej
                  j                  j                  d        Zd Zy)SerialzOJust inherit the native Serial port implementation and patch the port property.c                    t        |t              rK|j                  d      r:t        j                  j
                  j                  | | j                  |             yt        j                  j
                  j                  | |       y)z%translate port name before storing it	hwgrep://N)
isinstance
basestring
startswithserialr   port__set__from_url)selfvalues     C/usr/lib/python3/dist-packages/serial/urlhandler/protocol_hwgrep.pyr   zSerial.port&   sX     eZ(U-=-=k-JMM&&tT]]5-ABMM&&tU3    c                    |j                         j                  d      r|dd }d}d}|j                  d      }|j                  d      }|D ]t  }d|v r|j                  dd      \  }}n|}d}|d	k(  r.t	        |      dz
  }|dk  s:t        d
j                  |            |dk(  rd}\t        dj                  |             t        t        j                  j                  j                  |            D ]9  \  }	}
}|r&	 t        j                  |	      }|j                          |r|dz  }7|	c S  t        j                  dj                  |            # t        j                  $ r Y uw xY w)z(extract host and port from an URL stringr   	   Nr   F&=   nz9option "n" expects a positive integer larger than 1: {!r}	skip_busyTzunknown option: {!r}z#no ports found matching regexp {!r})lowerr
   splitpopint
ValueErrorformatsortedr   tools
list_portsgrepr   closeSerialException)r   urlr   	test_openargsregexpargoptionr   r   deschwidss                r   r   zSerial.from_url.   su   99;!!+.ab'C	yy~! 	HCcz #		#q 1}JNq5$%`%g%ghm%noo;& 	 !7!>!>v!FGG	H" !'v||'>'>'C'CF'K L 	\D$d+A
 GGIQK	\ (()N)U)UVY)Z[[ -- s    EE,+E,N)	__name__
__module____qualname____doc__r   r   r   setterr    r   r   r   r   "   s/    Y ]]4 4'\r   r   __main__zhwgrep://ttyS0)
__future__r   r   serial.tools.list_portsr	   	NameErrorstrr   r/   r.   r   printr4   r   r   <module>r;      sh   . '  
3\V]] 3\l ztAAF	!H u  Js   A AA