Mini Shell
3
�2[3 � @ sr d Z dZdZdZdZdZddlZddlZdd lm Z dd
lm
Z
ddlmZ ddlmZ G d
d� d�Z
dd� ZdS )z(Provides support for a flat review find.z$Id$z
$Revision$z$Date$z-Copyright (c) 2005-2008 Sun Microsystems Inc.ZLGPL� N� )�debug)�flat_review)�messages)�
orca_statec @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
S )�SearchQueryz3Represents a search that the user wants to perform.c C s0 d| _ d| _d| _d| _d| _d| _tj| _dS )a� Creates a new SearchQuery. A searchQuery has the following
properties:
searchString - the string to find
searchBackwards - if true, search upward for matches
caseSensitive - if true, case counts
matchEntireWord - if true, only match on the entire string
startAtTop - if true, begin the search from the top of
the window, rather than at the current
location
windowWrap - if true, when the top/bottom edge of the
window is reached wrap to the bottom/top
and continue searching
� FN) �searchString�searchBackwards�
caseSensitive�matchEntireWord�
windowWrap�
startAtTopr ZLEVEL_FINEST�
debugLevel)�self� r �/usr/lib/python3.6/find.py�__init__( s zSearchQuery.__init__c C s� t j| jd� t j| jd||j|j|j|jf � t j| jdt|j� � t j| jdt|j|j j � � t j| jdt|j|j j |j j
� � t j| jd� dS )z:Prints out the context and the string to find to debug.outz<------------------------------------------------------------z-findQuery: %s line=%d zone=%d word=%d char=%dzNumber of lines: %dz#Number of zones in current line: %dz#Number of words in current zone: %dz<==========================================================
N)r �printlnr � lineIndex� zoneIndex� wordIndex� charIndex�len�lines�zones�words)r �context�stringr r r �debugContextA s
zSearchQuery.debugContextc
C s� t d� x�tdt|j��D ]�}t d| � x�tdt|j| j��D ]t}t d| � xbtdt|j| j| j��D ]B}t d||j| j| j| jt|j| j| j| j�f � qpW qBW qW dS )z+Debug utility which prints out the context.ZDUMPr z Line %dz Zone: %dz" Word %d = `%s` len(word): %dN)�print�ranger r r r r )r r �i�j�kr r r �dumpContextV s "zSearchQuery.dumpContextc
C s� |j }|j}|j}|j}tj| jd||||f � tj}| j sH|tj
B }| jr^d| j d }n| j}tj
||�} tj| jd| j|f � | jr�|jtjj� | j|d� d}
d}d}d}
�xl|�s&|jtjj�\}}}}}tj| jd|||||f � tj| |��r|
�r�x|�s|jtjj�\}}}}}tj| jd|||f � tj| jd ||f � tj| |��r�|j|j j|j }||j k�o�||jk}y|jj� W n Y n�X tj| |�}g }x|D ]}|j|jd
�� �q�W | j�r�|j � d
}x�| �r�|t!|�k �r�|j"|| �\}}|�r�|j#|j }| j�rB|d
k �sV| j �rj|d
k�rj|j#|_d
|_d}n$| �r�| �s�|�r�d}n|d7 }nP �q�W |�s| j�r�|j$tjjtjj%�}| j|d
� |j&tjj� | j|d� n |j'tjjtjj%�}| j|d� |�sd}
P �qW q�| j�r@|j$tjjtjj%�}| j|d� n |j'tjjtjj%�}| j|d� |�r�| j�r$|j&tjj�}| j|d� q�| j(�r"| �r"t)j*}d}
d}| j�r�|j+t,j-� |j$tjjtjj.�}| j|d� n,|j+t,j/� |j'tjjtjj.�}| j|d� |�s$tj| jd� P q�P q�W |�r8t0j0|�}
| j|d� |j1||||� | j|d� |
�r�tj| jd|
j |
j|
j|
jf � |
S )a9 Performs a search on the string specified in searchQuery.
Arguments:
- context: The context from active script
- justEnteredFlatReview: If true, we began the search in focus
tracking mode.
Returns:
- The context of the match, if found
z;findQuery: original context line=%d zone=%d word=%d char=%dz\bz'findQuery: startAtTop: %d regexp: `%s`zgo beginNFz9findQuery: current line=`%s` x=%d y=%d width=%d height=%dz'findQuery: current zone=`%s` x=%d y=%d zwidth=%d height=%dr Tr z[1] go previousz
[1] go endz[1] go nextz[2] go previousz[2] go nextz
[2] go endz[3] go previousz[3] go nextzfindQuery: cannot wrapzbefore setting originalzafter setting originalz4findQuery: returning line=%d zone=%d word=%d char=%d)2r r r r r r r �re�LOCALEr �
IGNORECASEr r �compiler ZgoBeginr ZContextZWINDOWr Z
getCurrentZLINE�searchZZONEr r Z
accessibleZ queryText�finditer�append�startr
�reverser ZgetWordAtOffset�indexZ
goPreviousZ WRAP_LINEZgoEndZgoNextr
r ZactiveScriptZpresentMessager ZWRAPPING_TO_BOTTOMZWRAP_ALLZWRAPPING_TO_TOP�copyZ
setCurrent)r r ZjustEnteredFlatReviewZoriginalLineIndexZoriginalZoneIndexZoriginalWordIndexZoriginalCharIndex�flagsZregexp�pattern�location�foundZ
wrappedYetZdoneWithLineZcurrentLine�x�y�widthZheightZcurrentZoneZtheZoneZstartedInThisZoneZ
allMatchesZoffsets�mr"