kiki-0.5.6.orig/0000755000175000017500000000000010276345074012072 5ustar dokodokokiki-0.5.6.orig/__init__.py0000644000175000017500000000000010035311504014151 0ustar dokodokokiki-0.5.6.orig/docs/0000755000175000017500000000000010035311502013000 5ustar dokodokokiki-0.5.6.orig/docs/about.html0000644000175000017500000001021410035311454015004 0ustar dokodoko About Kiki
Kiki
Kiki is a free environment for regular expression testing (ferret).

Program info
Version: %(version)s
Program directory: %(kikidir)s
Data directory: %(datadir)s
Python version: %(pythonversion)s
wxPython version: %(wxpythonversion)s
Spe status: %(spe)s

Contact info
Web: %(website)s
e-mail/msn: %(mail)s
icq: %(icq)s

Credits
Kiki is built using a number of tools besides the extensive libraries of Python and wxPython:
  • the Spe Python editor
  • wxGlade for GUI design
  • the SciTE editor for Python and HTML coding
  • recon.py by Brent Burley for inspiration and correctness testing
  • part of the Python documentation is ripped and included in this distro
Of course I should also thank Pete Abrams for his Sluggy Freelance online comic which has kept me entertained for quite some time now and has also been the source of the name of this program. For those of you who don't know the comic: Kiki is a talking ferret which is very fond of bright colors and happy thoughts.

Licence
This program is © 2003, 2004 by Project 5
It is licenced under the GNU General Public Licence (GPL)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

kiki-0.5.6.orig/docs/index.html0000644000175000017500000002411107735675706015034 0ustar dokodoko Working with Kiki
Intro
Kiki is a free environment for regular expression testing (ferret). It allows you to write regexes and test them against your sample text, providing extensive output about the results. It is useful for several purposes:
  • exploring and understanding the structure of match objects generated by the re module, making Kiki a valuable tool for people new to regexes
  • testing regexes on sample text before deploying them in code
Kiki can function on its own or as plugin for the Spe Python editor.

Working with Kiki
Enter the regex in the combo box and hit Evaluate to run it against the text in the Sample text tab. The results appear in the Matches tab. You can use the list in the Help tab to view the built-in documentation about regular expressions. This documentation comes from the Python help files.

Kiki automatically stores its settings and the last used sample text/regex in between sessions. During a session, all regexes which have been evaluated and have returned matches, are also stored in the combo box where the regex is entered, so you may experiment with e.g. adapted versions without losing a more primitive regex that already kinda works.

Options
Methods
Use Find all to get all non-overlapping matches of the regex, or Find first to get only the first match (equivalent to the search method of regular expression objects).
Flags
Determines which flags the regex should be compiled with.

Understanding the output
Kiki's output is quite extensive and provides color-coded information on the results of the match. Let's assume you're trying to match the regex fer(re)*t against the sample text Kiki the ferret - as nifty as ferrets get. The results of a Find all evaluation by default looks something like this:

Kiki the 0:(fer(re)1t)0 - as nifty as 1:(fer(re)1t)0s get


Each match is prepended by a small, underlined number: this is the index of the corresponding match object in the list of match objects found in the sample text. In the example above, there are two match objects, with indexes 0 and 1.

Within each match, colored parentheses show where a match group starts and ends. Group ()0 represents the entire match. In this example we have also created an extra group because of the use of (re)*". This is made visible by the green parentheses bearing the index 1: ()1.

Pay attention to an interesting property of these groups: some of them might not contribute to the match and are then skipped in the output (in the match object, these groups start and end at position -1). An example: let's find all sentences talking about expecting the Spanish Inquisition in the text below:

Chapman: I didn't expect a kind of Spanish Inquisition.

(JARRING CHORD - the cardinals burst in)

Ximinez: NOBODY expects the Spanish Inquisition! Our chief weapon is surprise...surprise and fear...fear and surprise.... Our two weapons are fear and surprise...and ruthless efficiency.... Our *three* weapons are fear, surprise, and ruthless efficiency...and an almost fanatical devotion to the Pope.... Our *four*...no... *Amongst* our weapons.... Amongst our weaponry...are such elements as fear, surprise.... I'll come in again. (Exit and exeunt)


For this purpose, we can use e.g. the following regex:

([a-zA-Z']+\s)+?expect(.*?)(the )*Spanish Inquisition(!|.)

The result is:

Chapman: 0:(I (didn't )1expect( a kind of )2Spanish Inquisition(.)4)0

(JARRING CHORD - the cardinals burst in)

Ximinez: 1:((NOBODY )1expect(s )2(the )3Spanish Inquisition(!)4)0 Our chief weapon is surprise...surprise and fear...fear and surprise.... Our two weapons are fear and surprise...and ruthless efficiency.... Our *three* weapons are fear, surprise, and ruthless efficiency...and an almost fanatical devotion to the Pope.... Our *four*...no... *Amongst* our weapons.... Amongst our weaponry...are such elements as fear, surprise.... I'll come in again. (Exit and exeunt)


The interesting part is what's going on in the match with index 0: between the group with index 2 and the one with index 4, the group with index 3 has disappeared. This group matches an optional the which is not present in this case. In other words, the group exists, but does not contribute to the match and is therefore not displayed.

kiki-0.5.6.orig/docs/re.html0000644000175000017500000012425707735651214014333 0ustar dokodoko Regular expression docs
Syntax
A regular expression (or RE) specifies a set of strings that matches it. Kiki helps you find out if a certain regular expression matches a particular string.

Regular expressions can be concatenated to form new regular expressions: if A and B are both regular expressions, then AB is also a regular expression.
If a string p matches A and another string q matches B, the string pq will match AB (presuming the two RE's don't specify boundary conditions that are no longer satisfied by pq.
This means that complex expressions can easily be constructed from simpler primitive expressions.

Regular expressions can contain both special and ordinary characters. Most ordinary characters, like A, a, or 0, are the simplest regular expressions: they simply match themselves. You can concatenate ordinary characters, so last matches the string last.
Note the color coding used throughout these docs: this is a regex while this is a string.

Some characters, like | or (, are special. Special characters, when used in regular expressions, either stand for classes of ordinary characters, or affect how the regular expressions around them are interpreted.

Special characters
. (dot) In the default mode, this matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline.
^ (caret) Matches the start of the string, and in MULTILINE mode also matches immediately after each newline.
$ Matches the end of the string or just before the newline at the end of the string, and in MULTILINE mode also matches before a newline.
foo matches both foo and foobar, while the regular expression foo$ matches only foo. More interestingly, searching for foo.$ in foo1\nfoo2\n matches foo2 normally, but foo1 in MULTILINE mode.
* Causes the resulting RE to match 0 or more repetitions of the preceding RE, as many repetitions as are possible.ab* will match a, ab, or a followed by any number of b's.
+ Causes the resulting RE to match 1 or more repetitions of the preceding RE. ab+ will match a followed by any non-zero number of b's. It will not match just a.
? Causes the resulting RE to match 0 or 1 repetitions of the preceding RE. ab? will match either a or ab.
*?, +?, ?? The *, +, and ? qualifiers are all greedy: they match as much text as possible. Sometimes this behaviour isn't desired. If the RE <.*> is matched against <H1>title</H1>, it will match the entire string, and not just <H1>. Adding ? after the qualifier makes it perform the match in non-greedy or minimal fashion: as few characters as possible will be matched. Using .*? in the previous expression will match only <H1>.
{m} Specifies that exactly m copies of the previous RE should be matched; fewer matches cause the entire RE not to match. For example, a{6} will match exactly six a characters, but not five.
{m,n} Causes the resulting RE to match from m to n repetitions of the preceding RE, attempting to match as many repetitions as possible. For example, a{3,5} will match from 3 to 5 a characters. Omitting m specifies a lower bound of zero, and omitting n specifies an infinite upper bound. As an example, a{4,}b will match aaaab or a thousand a characters followed by a b, but not aaab. The comma may not be omitted or the modifier would be confused with the previously described form.
{m,n}? Causes the resulting RE to match from m to n repetitions of the preceding RE, attempting to match as few repetitions as possible. This is the non-greedy version of the previous qualifier. For example, on the 6-character string aaaaaa, a{3,5} will match 5 a characters, while a{3,5}? will only match 3 characters.
\ Either escapes special characters (permitting you to match characters like *, ?, and so forth), or signals a special sequence; special sequences are discussed below.

If you're not using a raw string to express the pattern, remember that Python also uses the backslash as an escape sequence in string literals; if the escape sequence isn't recognized by Python's parser, the backslash and subsequent character are included in the resulting string. However, if Python would recognize the resulting sequence, the backslash should be repeated twice. This is complicated and hard to understand, so it's highly recommended that you use raw strings for all but the simplest expressions.
[] Used to indicate a set of characters. Characters can be listed individually, or a range of characters can be indicated by giving two characters and separating them by a -. Special characters are not active inside sets. For example, [akm$] will match any of the characters a, k, m, or $. [a-z] will match any lowercase letter, and [a-zA-Z0-9] matches any letter or digit. Character classes such as \w or \S (defined below) are also acceptable inside a range. If you want to include a ] or a - inside a set, precede it with a backslash, or place it as the first character. The pattern []] will match ], for example.

You can match the characters not within a range by complementing the set. This is indicated by including a ^ as the first character of the set. ^ elsewhere will simply match the ^ character. For example, [^5] will match any character except 5, and [^^] will match any character except ^.
| A|B, where A and B can be arbitrary REs, creates a regular expression that will match either A or B. An arbitrary number of REs can be separated by the | in this way. This can be used inside groups (see below) as well. REs separated by | are tried from left to right, and the first one that allows the complete pattern to match is considered the accepted branch. This means that if A matches, B will never be tested, even if it would produce a longer overall match. In other words, the | operator is never greedy. To match a literal |, use \|, or enclose it inside a character class, as in [|].
(...) Matches whatever regular expression is inside the parentheses, and indicates the start and end of a group; the contents of a group can be retrieved after a match has been performed, and can be matched later in the string with the \number special sequence, described below. To match the literals ( or ), use \( or \), or enclose them inside a character class: [(] [)].
(?...) This is an extension notation (a ? following a ( is not meaningful otherwise). The first character after the ? determines what the meaning and further syntax of the construct is. Extensions usually do not create a new group; (?P<name>...) is the only exception to this rule. The supported extensions are listed below.

Extensions
(?iLmsux) (One or more letters from the set i, L, m, s, u, x.) The group matches the empty string and the letters set the corresponding flags (re.I, re.L, re.M, re.S, re.U, re.X) for the entire regular expression. This is useful if you wish to include the flags as part of the regular expression, instead of passing a flag argument to the compile() function.

Note that the (?x) flag changes how the expression is parsed. It should be used first in the expression string, or after one or more whitespace characters. If there are non-whitespace characters before the flag, the results are undefined.
(?:...) A non-grouping version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern.
(?P<name>...) Similar to regular parentheses, but the substring matched by the group is accessible via the symbolic group name name. Group names must be valid Python identifiers, and each group name must be defined only once within a regular expression. A symbolic group is also a numbered group, just as if the group were not named. So the group named id in the example above can also be referenced as the numbered group 1.

For example, if the pattern is (?P<id>[a-zA-Z_]\w*), the group can be referenced by its name in arguments to methods of match objects, such as m.group('id') or m.end('id'), and also by name in pattern text (for example, (?P=id)) and replacement text (such as \g<id>).
(?P=name) Matches whatever text was matched by the earlier group named name.
(?#...) A comment; the contents of the parentheses are simply ignored.
(?=...) Matches if ... matches next, but doesn't consume any of the string. This is called a lookahead assertion. For example, Isaac (?=Asimov) will match Isaac  only if it's followed by Asimov.
(?!...) Matches if ... doesn't match next. This is a negative lookahead assertion. For example, Isaac (?!Asimov) will match Isaac  only if it's not followed by Asimov.
(?<=...) Matches if the current position in the string is preceded by a match for ... that ends at the current position. This is called a positive lookbehind assertion. (?<=abc)def will find a match in abcdef, since the lookbehind will back up 3 characters and check if the contained pattern matches. The contained pattern must only match strings of some fixed length, meaning that abc or a|b are allowed, but a* and a{3,4} are not. Note that patterns which start with positive lookbehind assertions will never match at the beginning of the string being searched. You will most likely want to use the search() function rather than the match() function:
    >>> import re
    >>> m = re.search('(?<=abc)def', 'abcdef')
    >>> m.group(0)
    def
                    
This example looks for a word following a hyphen:
    >>> m = re.search('(?<=-)\w+', 'spam-egg')
    >>> m.group(0)
    egg
                    
(?<!...) Matches if the current position in the string is not preceded by a match for .... This is called a negative lookbehind assertion. Similar to positive lookbehind assertions, the contained pattern must only match strings of some fixed length. Patterns which start with negative lookbehind assertions may match at the beginning of the string being searched.

Special sequences
The special sequences consist of \ and a character from the list below. If the ordinary character is not on the list, then the resulting RE will match the second character. For example, \$ matches the character $.
\\ matches a literal backslash character
\number Matches the contents of the group of the same number. Groups are numbered starting from 1. For example, (.+) \1 matches the the or 55 55, but not the end (note the space after the group). This special sequence can only be used to match one of the first 99 groups. If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number. Inside the [ and ] of a character class, all numeric escapes are treated as characters.
\a ASCII Bell (BEL)
\A Matches only at the start of the string.
\b Matches the empty string, but only at the beginning or end of a word. A word is defined as a sequence of alphanumeric or underscore characters, so the end of a word is indicated by whitespace or a non-alphanumeric, non-underscore character. Note that \b is defined as the boundary between \w and \W, so the precise set of characters deemed to be alphanumeric depends on the values of the LOCALE and UNICODE flags.
Inside a character range, \b represents the backspace character, for compatibility with Python's string literals.
\B Matches the empty string, but only when it is not at the beginning or end of a word. This is just the opposite of \b, so is also subject to the settings of LOCALE and UNICODE.
\d Matches any decimal digit. This is equivalent to the set [0-9].
\D Matches any non-digit character; this is equivalent to the set [^0-9].
\f ASCII Formfeed (FF)
\n ASCII Linefeed (LF)
\r ASCII Carriage Return (CR)
\s Matches any whitespace character. This is equivalent to the set [ \t\n\r\f\v].
\S Matches any non-whitespace character. This is equivalent to the set [^ \t\n\r\f\v].
\t ASCII Horizontal Tab (TAB)
\v ASCII Vertical Tab (VT)
\w When the LOCALE and UNICODE flags are not specified, matches any alphanumeric character and the underscore. This is equivalent to the set [a-zA-Z0-9_].
With LOCALE, it will match the set [0-9_] plus whatever characters are defined as alphanumeric for the current locale.
If UNICODE is set, this will match the characters [0-9_] plus whatever is classified as alphanumeric in the Unicode character properties database.
\W When the LOCALE and UNICODE flags are not specified, matches any non-alphanumeric character. This is equivalent to the set [^a-zA-Z0-9_].
With LOCALE, it will match any character not in the set [0-9_], and not defined as alphanumeric for the current locale.
If UNICODE is set, this will match anything other than [0-9_] and characters marked as alphanumeric in the Unicode character properties database.
\xhh ASCII character with hex value hh
\Z Matches only at the end of the string.

Flags
The RE's behaviour can be modified by specifying a flags value. Values can be any of the following variables, combined using bitwise or (the | operator).
IGNORECASE (I) Perform case-insensitive matching. Expressions like [A-Z] will match lowercase letters, too. This is not affected by the current locale.
LOCALE (L) Make \w, \W, \b, and \B dependent on the current locale.
MULTILINE (M) When specified, the pattern character ^ matches at the beginning of the string and at the beginning of each line (immediately following each newline) and the pattern character $ matches at the end of the string and at the end of each line (immediately preceding each newline).
By default, ^ matches only at the beginning of the string, and $ only at the end of the string and immediately before the newline (if any) at the end of the string.
DOTALL (S) Make the . special character match any character at all, including a newline. Without this flag, . will match anything except a newline.
UNICODE (U) Make \w, \W, \b, and \B dependent on the Unicode character properties database (since Python 2.0).
VERBOSE (X) This flag allows you to write regular expressions that look nicer. Whitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash, and, when a line contains a # neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such # through the end of the line are ignored.
kiki-0.5.6.orig/history.txt0000644000175000017500000000235110035311504014315 0ustar dokodokoKIKI 0.5.6 - regexes made nifty Copyright (C) 2003, 2004 Project 5 (http://come.to/project5) Licence: GPL (free) Requires: Python, wxPython System: any, provided (wx)Python runs on it History ======= 0.5.6 (8-4-2004, 32.5 kB) - changed code to support wxPython 2.5.1.5 - saves settings before evaluating the regex 0.5.5 (29-9-2003, 32.5kB) - fixed bug which caused the selected regex to disappear to the history when Evalute was activated - fixed Linux bug which caused warning messages to be displayed when a different doc was selected in the Help tab - small changes in code and docs - first public release outside Spe 0.5 (28-9-2003, 32.8kB) = added really nifty colors = added docs and about screen = added ferrety Easter Egg :) = added __init__.py so that Kiki can be used as package in Spe - fixed bug that meant flags were actually not used when compiling the regex - locale used to be after multiline - restored alphabetical order 0.2 (26-9-2003, 25.7kB) - fixed a bug with caused empty regex results to lead to an infinite loop = added pretty icons :) - added support for integration in Spe - misc changes 0.1: - first version, only available in Spe 0.1.8.a kiki-0.5.6.orig/Kiki.bat0000644000175000017500000000015510035311504013432 0ustar dokodoko@ECHO OFF @ECHO Use this file to start the program under Windows. SET PATH start pythonw -OO kiki.py exitkiki-0.5.6.orig/kiki.ico0000644000175000017500000002635607735110360013523 0ustar dokodokoh6 ¨ ž00¨F( @ïïïa`b~€ttp¡ Ÿßßßïïï840\`Z‰ŽˆŠrqqdcbßßßïïï000|ur65G––ÊŠ†Ä21KÊÐÈ…a`aïïï`ba000¿¹ÀVR|œ™ñ–•ð—•ÎSSc®´¬#$!0/1ŸŸŸßßß €œžhdˆ¡œàZ`NTm&âäß120%%(666ïïï{‡‰†ÁÀÅ<8SJEe¦©²ÕÝØÃÊÊäçê999ßßßßßß,+\a]óóõ!áæâáäãíðòâãäc``VVVßßßßßß)* ÐÎ̺»¹êêé*)*“˜e\P‘w1>4445†††ßßßïïïKRS" G7mcd¼»Ãéíóg\:ĤFSH`efpppßßß|‡ˆHEHZPÄ¥AfY%ãèâ÷øûľ¶K=' ÖÛß^\\ª¨©ßßß?NNMKKaRͪFn[*áÞÛÿûû÷úús{€§ª¬öù÷ãáâpnoŸ¢¢~~IA9;) e\QòñøüûöÚÝÚX[^"&"±·¯¦¦¦jklßßßUVVíïófgeWYXøüü¬­©SQV³¯³³²µGJKfgg¶··ßßßdpoÿýþËËË GGGtttêêêïïïßßß&43»·¸ïïïFFFïïﯰ°ƒ‚‚ppp»»»øðààÀÀ€€€ÀÀààààðÿ( @€ ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ+03MSRDEA  ÀÀÀÀÀÀÀÀÀÀÀÀ }€~íõôæîíæëéïïétqiÀÀÀÀÀÀÀÀÀ svgˆ…)18 ! @@L¶²½¡œ594 ÀÀÀÀÀÀÀÀÀ ››‚ƒTWv£¥Î‘‘¿A>kMSNðôîÊÐÅkod/0'ÀÀÀÀÀÀÀÀÀcYYçâä+':*&O¿ý¢žêŸ™ê¹³ÿ~tÀ{€ôüòýÿ÷ž¢–QQK!ÀÀÀÀÀÀ200ëãã­¦µŒ†¿¬¦ø˜”ô™”÷Šå¯ªÿhe~ ÍÑÒûÿù,3&_]]kgmÀÀÀÀÀÀ  ‡‚ƒÿþþgal6­ªâ™˜è““ñ”—ò¡ò–œå³«Ú -eftûÿþš¡”SSSÀÀÀÀÀÀ&>>ÚÕÖÿýýAAA2¤¤Ô£¥ì˜žñ§õŽœÞ†•Í©œÚD, ruƒøÿþª¬¬ÀÀÀÀÀÀLeg—’”  ª3»&ɨ;±šJ61·½¬úþøÿÿøîíýÿüÿúóð‹‚x&/*3úùÿ÷ÿý®°°-$'ÀÀÀÀÀÀ¤¨©XVV%#"Ǭ4Ƥ,˨:¶M>5 ³³¥ÿþúÿÿûÿþÿýýÿóöû¬°µ!%*58=ÝÝãýüÿúÿþüþþ—’“ ÀÀÀÀÀÀ4NN ,,ÈÊÊ –{%Ô´[ЫY§ŒTÓÎÐÿûÿÿóûÿÿ÷ôøòøÿÿ¸ÄÈKW[——ýÿûÿÿ÷åìéýÿÿýøù0-/ÀÀÀÀÀÀ ‡Œ™”•!+_G^A@*?63ÛØçÿúÿÿúÿÿÿòûÿ÷ôûöÔÞÞpzzENAòøåúÿþýÿÿÔÒÒ%$&ÀÀÀÀÀÀÚÕÖù¹ 'EJ]_ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ"0-,)   , 6 ; 6 " 0@AÀÀÀÀÀÀÀÀÀÀÀÀ€žœ<@? -(Ar'F%K&L}&@q)T (,,ÀÀÀÀÀÀÀÀÀÀÀÀDST "8.I…@‡K‰ H…&E.DŠ#7i ";   ÀÀÀÀÀÀÀÀÀÀÀÀg}} +3G|%Cˆ#HŒ$G…#CŒ%C)J#I|E  ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ3GG&2Y4K‰&E'E†!A‰ABI0H„!4[% ³³³ÀÀÀÀÀÀÀÀÀÀÀÀ¬«ÀÀÀÀÀÀ !&:f+GŽ(E‹#Aˆ&F‹$FŒ"F‹%F‡,K‡,H{>ŠŠŠÀÀÀÀÀÀÀÀÀ”²²NY\9+GŒ(E+HŒ*G†+Fƒ,G„%I…FŠ#D1E#@...ÀÀÀÀÀÀÀÀÀÀÀÀ´¯ ";#E‡)K%Gˆ%F†#Dƒ'Gˆ'G‰$D‡)I‹#B‚)[ ]^]ÀÀÀÀÀÀÀÀÀ $P5L…(H‹#H‹$Hˆ&Fˆ%E‡$D†)I‹*JŒ%C})D {|{ÀÀÀÀÀÀÀÀÀÀÀÀ%% &O,G„ E‰!E‡(I‹(HŠ&Fˆ'G‰'G‰(IŠ&G€'I ÎÎÎÀÀÀ/CA .W+I%Fˆ%Fˆ&Fˆ(HŠ&Fˆ$D†"Cˆ"C‹/H}; pppÀÀÀÀÀÀÀÀÀÀÀÀE[Y%"Hb_|˜•„¢Ÿw•’_}5RN1Y,F‡&Eˆ#C…'G‰(HŠ%E‡(F‰+DŠ-IŒ!;q.###ÁÁÁÀÀÀÀÀÀv–”J\Y‚—•ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀz‘$.A A+>x,G‡#F‰"H‹%G†-I…4E†%B†,K#9k ‚ƒ…ÀÀÀÀÀÀ*77Ѝ¥ÀÀÀÀÀÀÀÀÀ‚œž 3+@v!E‹G Fƒ-I,E‡)F„+GŒ2F‰!@ SV[ÀÀÀÀÀÀ h}ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀc)H)D†!A’&GŒ'F‚#DŽ"F‰#C/GŒ%<]  "&ÀÀÀÀÀÀÀÀÀ w•’ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀFYM  0Bx*B*G"D„CEˆ$FŽ%=~,F  ¼¾¿ÀÀÀNYW x˜“ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀWg\&1Q2E€)F‡%G‹%GŽ!G„&D„#Y%' ‚ƒ„ÀÀÀÀÀÀ RfbÀÀÀÀÀÀÀÀÀ™ÏÍÀÀÀÀÀÀKij'./FHM 0V.K… Aˆ'Gˆ(_'S `abÀÀÀÀÀÀ!!ÀÀÀÀÀÀŒ»¸ÀÝÜÀÀÀ-38pno  0W%F…%C‘%F‚ #L&=# DEFÀÀÀÀÀÀ?LKÀÀÀÀÀÀ|˜—?ML /Z(C‹(EˆSQÀÀÀÀÀÀÀÀÀ‡ˆ‰62-    ÀÀÀÀÀÀ(00+?=ÀÀÀÀÀÀj„€2.. …†¢¨¦”•=96ÀÀÀÀÀÀ6BB"!ÀÀÀÀÀÀ=RO# hleRY`AFWMM^„‚‹dgc*,)ÀÀÀÀÀÀOdb ÀÀÀÀÀÀ˜”>:VUNsPLj‰Œ•ÂÊÃÄËɯ´µçêì]]bBBBÀÀÀÀÀÀÀÀÀ®« ,1/òòŠNOYâåë÷üý÷üûúþÿô÷û¸»Ã"#*mmm000ÀÀÀ_…ƒ·¹µäãå=>@ÄÈÂäæá¥¨¦º»¾ðñô•’‰B:(%$$ŠŠŠ///ÀÀÀjЉ YZVÝÜÚ·¸¶îîì---Z[_ÉËÌE6v/~l3DDE³³³666ÀÀÀЍ¨   NLB@;2RKN»¶¿€~„¿Àij¶¶gQͨ?¨;fgh­­­=<<ÀÀÀÀÀÀ²ÝÜ&250'+ R?¡‚;eM!‚€vñöúùùýÎÑËVI)~i2aR'«³µ‹Œ‹A9;ÀÀÀÍûûBVXTSU ’(¢7¯•B_]>ãèàùúùñð÷Æ¿·VK< gdjìðòŒŒŒ-%(ÀÀÀŽ®®KWXihh ”~*ʨ?¸œK\U;åãßÿûúûüûìðów~ƒQVYïïðöùøêêëa\]ÀÀÀ°ÛÚ1GE€„„B<Error:
    %s
""" t_nomatch = """No match found""" # colors used to highlight matches colors = ["0000AA" , "00AA00" , "FFAA55" , "AA0000" , "00AAAA" , "AA00AA" , "AAAAAA" , "0000FF" , "00FF00" , "00FFFF" , "FF0000" , "DDDD00" , "FF00FF" , "AAAAFF" , "FF55AA" , "AAFF55" , "FFAAAA" , "55AAFF" , "FFAAFF" , "000077" , "007700" , "770000" , "007777" , "770077" , "777700" ] class Settings(object): """Stores and retrieves settings to a file as Python data structures which are eval()-ed. This is not by definition safe, but since the user has access to source code anyway and hence the ability to screw up anything, the danger seems quite limited.""" def __init__(self, savedir=None, dirname="", filename="settings.py", debugfile=""): """Initializes the object Arguments: savedir -- directory where to store data For more info, see the docs of Settings.setSaveDir() dirname -- if savedir=None, dirname is used to determine which subdirectory of $HOME data is stored it. filename -- name of file containing stored data debugfile -- used to allow the user to manually override the default storage dir. Mor info in the docs of Settings.setSaveDir() """ self.__setSaveDir(savedir, dirname, debugfile) self.savefilename = filename self.__load() def shutdown(self): """Must be called before the program ends.""" self.save() def __setSaveDir(self, savedir=None, dirname="", debugfile=""): """Sets self.savedir Arguments: savedir -- directory where to store data if savedir==None, $HOME/dirname is used. If necessary, the directory is created. dirname -- if savedir==None, dirname determines which subdirectory of the home dir data is stored in debugfile -- this file may be a filename which is imported and may contain a variable called savedir If the debugfile is specified, imported successfully and savedir exists, it is used to override any other parameters. This allows users to override the directory, bypassing the application which needs the settings. In some Windows installations (seems to be mainly a Win2k problem), $HOME points to the root directory. In this case, this function will try to use $USERPROFILE/dirname instead. Overriding this default behaviour is possible by supplying the savedir variable in pearsdebug.py.""" if savedir==None: try: # try to override using debugfile if present and contains savedir debugmodule = __import__(debugfile, globals()) savedir = debugmodule.savedir except: # if no override, then perform default actions if savedir == None: # use $HOME/dirname savedir = os.path.expanduser('~/'+dirname) if len(savedir)<=len("c:\\/"+dirname): # sometimes $HOME points to root # if this is the case, try using $USERPROFILE (see docstring) temp = os.path.join(os.path.expandvars('$USERPROFILE'), dirname) # if this is a different location, use it! if temp > len("C:\\/"+dirname): savedir = temp # create dir if it doesn't exist if not os.path.exists(savedir): os.makedirs(savedir) self.savedir = savedir def __load(self): """Loads the settings from a file. These settings are saved in Python code format which is eval()-ed, so it's not trustworthy.""" try: settingsfile = file(os.path.join(self.savedir, self.savefilename), "r") self.settings = eval(settingsfile.read()) settingsfile.close() except: # if file doesn't exist self.settings= {} def save(self): """Saves the settings to a file.""" settingsfile = file(os.path.join(self.savedir, self.savefilename), "w") settingsfile.write(str(self.settings)) settingsfile.close() def set(self, settingname, value): """Changes the value of a setting with settingname to value.""" self.settings[settingname] = value def get(self, settingname, defaultval=None): """Returns the setting with settingname if present, otherwise returns defaultval and saves settingname with defaultval.""" if self.settings.has_key(settingname): return self.settings[settingname] else: self.set(settingname, defaultval) return defaultval class MyHtmlWindow(wx.html.HtmlWindow): """Adds OnLinkClicked""" def __init__(self, parent, id): wx.html.HtmlWindow.__init__(self, parent, id, style=wx.NO_FULL_REPAINT_ON_RESIZE) def OnLinkClicked(self, linkinfo): # there's a problem in KDE: the browser is not recognized properly # circumvent this problem import os if os.environ.has_key("BROWSER") and \ os.environ["BROWSER"]=='kfmclient openProfile webbrowsing': print "Invalid browser detected : %s\nResetting to konqueror." % os.environ["BROWSER"] os.environ["BROWSER"] = 'konqueror' # set it to konqueror import webbrowser # MUST be imported only AFTER os.environ has been modified webbrowser.open(linkinfo.GetHref(), 1) class MyFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.SplitterWindow = wx.SplitterWindow(self, -1, style=wx.SP_3D|wx.SP_LIVE_UPDATE) self.BottomPane = wx.Panel(self.SplitterWindow, -1) self.Notebook = wx.Notebook(self.BottomPane, ID_NOTEBOOK, style=0) self.HelpPane = wx.Panel(self.Notebook, -1) self.SampleTextPane = wx.Panel(self.Notebook, -1) self.MatchesPane = wx.Panel(self.Notebook, -1, style=wx.SUNKEN_BORDER|wx.TAB_TRAVERSAL) self.TopPane = wx.Panel(self.SplitterWindow, -1, style=wx.RAISED_BORDER|wx.TAB_TRAVERSAL) self.RegexBox = wx.ComboBox(self.TopPane, -1, choices=["", "", "", "", "", "", ""], style=wx.CB_DROPDOWN) self.EvaluateButton = wx.Button(self.TopPane, ID_EVALUATE, "Evaluate") self.MethodBox = wx.RadioBox(self.TopPane, -1, "Methods", choices=["Find all", "Find first"], majorDimension=1, style=wx.RA_SPECIFY_COLS) self.IgnoreCheckBox = wx.CheckBox(self.TopPane, -1, "IGNORECASE (I)") self.LocaleCheckBox = wx.CheckBox(self.TopPane, -1, "LOCALE (L)") self.MultilineCheckBox = wx.CheckBox(self.TopPane, -1, "MULTILINE (M)") self.DotAllCheckBox = wx.CheckBox(self.TopPane, -1, "DOTALL (S)") self.UnicodeCheckBox = wx.CheckBox(self.TopPane, -1, "UNICODE (U)") self.VerboseCheckBox = wx.CheckBox(self.TopPane, -1, "VERBOSE (X)") self.MatchesWindow = wx.html.HtmlWindow(self.MatchesPane, -1) self.SampleText = wx.TextCtrl(self.SampleTextPane, -1, "", style=wx.TE_PROCESS_TAB|wx.TE_MULTILINE|wx.TE_RICH) self.HelpSelection = wx.ComboBox(self.HelpPane, ID_HELPCOMBOBOX, choices=["Working with Kiki", "Re - syntax", "Re - special characters: |, (, +, etc.", "Re - extensions, groups and lookahead/lookbehind: (?...)", "Re - special sequences: \...", "Re - flags", "About Kiki"], style=wx.CB_DROPDOWN|wx.CB_READONLY) self.HelpWindow = MyHtmlWindow(self.HelpPane, -1) self.__set_properties() self.__do_layout() # end wxGlade def __set_properties(self): # begin wxGlade: MyFrame.__set_properties self.SetTitle("Kiki") self.SetSize((640, 480)) self.RegexBox.SetSelection(0) self.EvaluateButton.SetDefault() self.MethodBox.SetToolTipString("Find all returns all matches, find first only the first one") self.MethodBox.SetSelection(0) self.IgnoreCheckBox.SetToolTipString("Perform case-insensitive matching\nExpressions like [A-Z] will match lowercase letters too. This is not affected by the current locale.") self.LocaleCheckBox.SetToolTipString("Make \w, \W, \\b, and \B dependent on the current locale.") self.MultilineCheckBox.SetToolTipString("When specified, the pattern characters \"^\" and \"$\" match at the beginning respectively end of the string and at the beginning respectively end of each line (immediately following respectively preceding each newline).\nOtherwise \"^\" matches only at the beginning of the string, and \"$\" only at the end of the string and immediately before the newline (if any) at the end of the string.") self.DotAllCheckBox.SetToolTipString("Make the \".\" special character match any character at all, including a newline. Without this flag, \".\" will match anything except a newline.") self.UnicodeCheckBox.SetToolTipString("Make \w, \W, \\b, and \B dependent on the Unicode character properties database.") self.VerboseCheckBox.SetToolTipString("This flag allows you to write regular expressions that look nicer.\nWhitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash, and, when a line contains a \"#\" neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such \"#\" through the end of the line are ignored. ") self.HelpSelection.SetSelection(0) self.BottomPane.SetSize((623, 324)) self.SplitterWindow.SplitHorizontally(self.TopPane, self.BottomPane, 120) # end wxGlade def __do_layout(self): # begin wxGlade: MyFrame.__do_layout MainSizer = wx.BoxSizer(wx.HORIZONTAL) TopPaneSizer = wx.BoxSizer(wx.HORIZONTAL) HelpPaneSizer = wx.FlexGridSizer(3, 1, 7, 7) SampleTextSizer = wx.BoxSizer(wx.HORIZONTAL) MatchesPaneSizer = wx.BoxSizer(wx.HORIZONTAL) BottomPaneSizer = wx.FlexGridSizer(5, 3, 0, 0) OptionsSizer = wx.FlexGridSizer(1, 2, 0, 7) FlagsSizer = wx.StaticBoxSizer(wx.StaticBox(self.TopPane, -1, "Flags"), wx.HORIZONTAL) FlagCheckSizer = wx.FlexGridSizer(4, 3, 7, 15) RegexSizer = wx.FlexGridSizer(1, 2, 0, 7) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) RegexSizer.Add(self.RegexBox, 0, wx.EXPAND, 0) RegexSizer.Add(self.EvaluateButton, 0, 0, 0) RegexSizer.AddGrowableCol(0) BottomPaneSizer.Add(RegexSizer, 1, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) OptionsSizer.Add(self.MethodBox, 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add(self.IgnoreCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.LocaleCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.MultilineCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.DotAllCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.UnicodeCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.VerboseCheckBox, 0, 0, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagsSizer.Add(FlagCheckSizer, 1, wx.EXPAND, 0) OptionsSizer.Add(FlagsSizer, 1, 0, 0) BottomPaneSizer.Add(OptionsSizer, 1, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) self.TopPane.SetAutoLayout(1) self.TopPane.SetSizer(BottomPaneSizer) BottomPaneSizer.Fit(self.TopPane) BottomPaneSizer.SetSizeHints(self.TopPane) BottomPaneSizer.AddGrowableCol(1) MatchesPaneSizer.Add(self.MatchesWindow, 1, wx.EXPAND, 0) self.MatchesPane.SetAutoLayout(1) self.MatchesPane.SetSizer(MatchesPaneSizer) MatchesPaneSizer.Fit(self.MatchesPane) MatchesPaneSizer.SetSizeHints(self.MatchesPane) SampleTextSizer.Add(self.SampleText, 1, wx.EXPAND, 0) self.SampleTextPane.SetAutoLayout(1) self.SampleTextPane.SetSizer(SampleTextSizer) SampleTextSizer.Fit(self.SampleTextPane) SampleTextSizer.SetSizeHints(self.SampleTextPane) HelpPaneSizer.Add((1, 1), 0, wx.EXPAND, 0) HelpPaneSizer.Add(self.HelpSelection, 0, wx.EXPAND, 0) HelpPaneSizer.Add(self.HelpWindow, 1, wx.EXPAND, 0) self.HelpPane.SetAutoLayout(1) self.HelpPane.SetSizer(HelpPaneSizer) HelpPaneSizer.Fit(self.HelpPane) HelpPaneSizer.SetSizeHints(self.HelpPane) HelpPaneSizer.AddGrowableRow(2) HelpPaneSizer.AddGrowableCol(0) self.Notebook.AddPage(self.MatchesPane, "Matches") self.Notebook.AddPage(self.SampleTextPane, "Sample text") self.Notebook.AddPage(self.HelpPane, "Help") TopPaneSizer.Add(wx.NotebookSizer(self.Notebook), 1, wx.EXPAND, 0) self.BottomPane.SetAutoLayout(1) self.BottomPane.SetSizer(TopPaneSizer) MainSizer.Add(self.SplitterWindow, 1, wx.EXPAND, 0) self.SetAutoLayout(1) self.SetSizer(MainSizer) self.Layout() self.Centre() # end wxGlade # end of class MyFrame class MyFrameWithEvents(MyFrame): """Subclasses MyFrame - generated by wxGlade - and adds events.""" def __init__(self, *args, **kwargs): MyFrame.__init__(self, *args, **kwargs) # map option flags to checkboxes self.flagmapper = {FLAGIGNORE: self.IgnoreCheckBox, FLAGMULTILINE: self.MultilineCheckBox, FLAGLOCALE: self.LocaleCheckBox, FLAGDOTALL: self.DotAllCheckBox, FLAGUNICODE: self.UnicodeCheckBox, FLAGVERBOSE: self.VerboseCheckBox} self.SetTitle(" " + self.GetTitle() + " " + __version__) # set empty pages for HTML windows self.MatchesWindow.SetPage("") self.HelpWindow.SetPage("") self.HelpWindow.SetWindowStyleFlag(wx.SUNKEN_BORDER) self.Notebook.SetSelection(0) self.RegexBox.Clear() # bind events wx.EVT_BUTTON(self, ID_EVALUATE, self.evaluate) wx.EVT_CLOSE(self, self.close) wx.EVT_NOTEBOOK_PAGE_CHANGED(self, ID_NOTEBOOK, self.changePage) wx.EVT_COMBOBOX(self, ID_HELPCOMBOBOX, self.showhelp) # apply settings self.loadSettings() # move focus to regex input field self.RegexBox.SetFocus() # initialize needed attribs self.matches = [] # list of found matches self.path = os.path.split(sys.argv[0])[0] or os.getcwd() # remembers where Kiki is located def icon(self, path=None): """Load and assign the icon Arguments: path -- path where kiki.ico is located. If path==None, the current directory is used """ import sys if path==None: self.path = os.path.split(sys.argv[0])[0] or os.getcwd() # *MUST* be the directory where everything, including About data and the likes are located else: self.path = path iconfile = os.path.join(self.path, "kiki.ico") theicon = wx.Icon(iconfile, wx.BITMAP_TYPE_ICO) self.SetIcon(theicon) def changePage(self, event): """Handles notebook page changes""" if event.GetSelection()==2 and not self.HelpWindow.GetOpenedPageTitle().strip(): self.HelpWindow.SetPage(file(os.path.join(self.path, "docs", "index.html"),"r").read()) def showhelp(self, event): """Handles help combo box events""" sel = self.HelpSelection.GetStringSelection().lower() # must lower-case for comparisons id = self.HelpSelection.GetSelection() filename, anchor = "", "" simpleload = True if id==0: # show main help filename = "index.html" elif sel.find("syntax")>-1: filename, anchor = "re.html", "syntax" elif sel.find("special characters")>-1: filename, anchor = "re.html", "specialcharacters" elif sel.find("extensions")>-1: filename, anchor = "re.html", "extensions" elif sel.find("special sequences")>-1: filename, anchor = "re.html", "specialsequences" elif sel.find("flags")>-1: filename, anchor = "re.html", "flags" else: simpleload = False if simpleload: filename = os.path.join(self.path, "docs", filename) if anchor.strip(): anchor = "#" + anchor else: anchor = "" self.HelpWindow.LoadPage(filename+anchor) else: # build about-screen f = file(os.path.join(self.path, "docs", "about.html"), "r") about = f.read() f.close() # build the dictionary needed to format the string if self.GetTitle().lower().find("spe")>-1: spe = "active" else: spe = "inactive (Kiki running standalone)" d = {"version": __version__, "kikidir": self.path, "datadir": settings.savedir, "pythonversion": sys.version.split()[0], "wxpythonversion": wx.__version__, "spe": spe, "website": "http://come.to/project5", "mail": "project5@wanadoo.nl", "icq": "84243714" } about = about % d self.HelpWindow.SetPage(about) def evaluate(self, event): """Actual functionality, triggered by Evaluate button press. The regex is compiled if possible. If compilation is successful, the regex is added to the history and it's matched against the sample text. If compilation is unsuccessful, the error message is displayed. """ self.saveSettings() self.Notebook.SetSelection(0) # display output pane # STEP 1: try to compile the regex # get flags to use in the compilation flags = 0 for flag in self.flagmapper.keys(): if self.flagmapper[flag].IsChecked(): flags = flags|eval(flag) # compile the regex and stop with error message if invalid try: self.MatchesWindow.SetPage("") regex = re.compile(self.RegexBox.GetValue(), flags) except re.error, e: self.MatchesWindow.SetPage(t_error % e) return False # stop execution if error if self.RegexBox.GetValue().strip(): # append to history if non-empty # get current history items currentitems = [self.RegexBox.GetValue()] for i in range(self.RegexBox.GetCount()): t = self.RegexBox.GetString(0) if not t in currentitems: # no duplicates currentitems.append(t) self.RegexBox.Delete(0) for item in currentitems: self.RegexBox.Append(item) self.RegexBox.SetSelection(0) # set selection again rawtext = self.SampleText.GetValue() # insider joke for the Sluggy fans if rawtext.strip()=="INSTANT FERRET-SHOCK!": import random shock = [""] #blinkychars = """+*-/\:;][{}|tyqfghjkl?>ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%""" rc = random.choice c = colors sa = shock.append t = """KIKI""" [ sa(t % (rc(c))) for i in xrange(10000) ] shock.append("") self.MatchesWindow.SetPage("".join(shock)) return None self.matches = [] # empty the list of match objects output = [] while 1: if len(self.matches)==0: start = 0 else: start = self.matches[-1].end() if len(self.matches[-1].group(0))==0: # in case of expressions which return empty matches # Without this condition, an endless loop would occur. start += 1 match = regex.search(rawtext, start) if (not match) or \ (len(self.matches)>=1 and self.MethodBox.GetSelection()==1) or \ start>=len(rawtext): # this last condition is also to prevent an endless loop break # stop execution else: self.matches.append(match) if not self.matches: # if no matches found output.append(t_nomatch) else: # matches found # show matches with parentheses if settings.get(RESULTS_SHOWMATCHES, True): output.append(self.showmatches()) output.append("""

""") # show tabular overview of named groups if settings.get(RESULTS_SHOWNAMEDGROUPS, True): # TODO: self.shownamedgroups() pass if settings.get(RESULTS_SHOWSAMPLE, True): output.append("""
Sample text matched against:
""") output.append(self.htmlize(rawtext) or " ") # something must be in there, so if no raw text, at least force a space output.append("""
""") self.MatchesWindow.SetPage("".join(output)) def htmlize(self, text): """Converts the text to html (escapes HTML entities and tags, converts spaces to  's and enters to
's.""" result = cgi.escape(text) result = result.replace("\t", "    ") result = result.replace(" ", "  ") result = result.replace("\r\n", "
") result = result.replace("\r", "
") result = result.replace("\n", "
") return result def formatmatch(self, match, index, matchtemplate, starttemplate, endtemplate): """Pretty-prints a match as HTML, with colors for groups, etc.""" # first, make a dictionary of start and end positions # (each char number in the match may be mapped to zero, one or more # group numbers which start/end there) # Groups function according to first-to-open, last-to-close. starts, ends = {}, {} # populate the dictionaries with empty lists # A -1 key is necessary for groups which do not participate in the match. for pos in range(-1, len(match.string)+1): starts[pos], ends[pos] = [], [] # now populate them with real values: each position key will contain # none or more group numbers #print match.groups() for groupnr in range(1+len(match.groups())): #print groupnr #print starts, ends starts[match.start(groupnr)].append(groupnr) ends[match.end(groupnr)].append(groupnr) # prepare result result = [] # now, loop through the string matched and build the layout string = match.string opengroups = [] # keeps track of open groups for pos in range(match.start(), match.end()+1): while 1: # first, try to shut down any open groups if opengroups and opengroups[-1] in ends[pos]: # if opengroups available and the last one must be closed now # shut down open group and remove it from the opengroups list result.append(endtemplate % {GROUPCOLOR: colors[opengroups[-1] % len(colors)], GROUPNUMBER: opengroups.pop(-1)}) # secondly, try to open any new groups elif starts[pos]: # if any new groups must be opened now result.append(starttemplate % {GROUPCOLOR: colors[starts[pos][0] % len(colors)], GROUPNUMBER: starts[pos][0]}) opengroups.append(starts[pos].pop(0)) else: # if no groups must be opened or closed, nothing special going on if pos""") # load match layout templates starttemplate = settings.get(STARTTEMPLATE, """(""" % GROUPCOLOR) endtemplate = settings.get(ENDTEMPLATE, """)%%(%s)s""" % (GROUPCOLOR, GROUPNUMBER)) matchtemplate = settings.get(MATCHTEMPLATE, """%%(%s)s:%%(%s)s""" % (MATCHINDEX, FORMATTEDMATCH)) # loop through matches and create output for match in self.matches: index += 1 # determine what part of the string we're looking at if index>0: prevmatchend = self.matches[index-1].end() else: prevmatchend = 0 if index+1 < len(self.matches): nextmatchstart = self.matches[index+1].start() else: nextmatchstart = -1 # append piece in between matches html.append(self.htmlize(match.string[prevmatchend:match.start()])) # append current match #html.append(self.htmlize(match.string[match.start():match.end()])) html.append(self.formatmatch(match, index, matchtemplate, starttemplate, endtemplate)) # append end piece if necessary if index+1 >= len(self.matches): # if last match, print rest of string html.append(self.htmlize(match.string[match.end():])) html.append("""""") res = "".join(html) return res def loadSettings(self): """Loads GUI settings from the settings system.""" # load some size settings # set window size and position; make sure it's on screen # and has a reasonable size system = wx.SystemSettings_GetMetric pos = list(settings.get(WINDOWPOSITION, (-1,-1))) if pos[0]<-1: pos[0] = 0 if pos[1]<-1: pos[1] = 0 if pos[0]>system(wx.SYS_SCREEN_X)-50: pos[0] = 0 if pos[1]>system(wx.SYS_SCREEN_Y)-50: pos[1] = 0 self.SetPosition(pos) size = list(settings.get(WINDOWSIZE, (-1, -1))) if size[0]>system(wx.SYS_SCREEN_X): size[0] = 640 if size[1]>system(wx.SYS_SCREEN_Y): size[1] = 480 size[0] = max(size[0], 640) size[1] = max(size[1], 480) self.SetSize(size) # load the sample text and regex last used self.SampleText.SetValue(settings.get(SAMPLETEXT, "")) self.RegexBox.SetValue(settings.get(REGEX, "")) # load the flags and desired type of re functionality for flag in self.flagmapper.keys(): self.flagmapper[flag].SetValue(settings.get(flag, False)) self.MethodBox.SetSelection(settings.get(SEARCHTYPE, 0)) # other settings self.SplitterWindow.SetSashPosition(settings.get(SASHPOSITION, 100)) def saveSettings(self, dosave=True): """Puts all GUI settings in the settings system. Arguments: dosave -- if True, the save() method of Settings is called when done """ # put all stuff that needs saving in the settings settings.set(WINDOWSIZE, self.GetSize()) settings.set(WINDOWPOSITION, self.GetPosition()) settings.set(SASHPOSITION, self.SplitterWindow.GetSashPosition()) settings.set(SAMPLETEXT, self.SampleText.GetValue()) settings.set(REGEX, self.RegexBox.GetValue()) # save the selected flags for flag in self.flagmapper.keys(): settings.set(flag, self.flagmapper[flag].GetValue()) settings.set(SEARCHTYPE, self.MethodBox.GetSelection()) if dosave: settings.save() def close(self, event): """Prepares for shutdown and then closes the app.""" self.saveSettings() # shut down the settings system settings.shutdown() # shut down the app self.Destroy() def speCreate(parent, info=None): """Integration of Kiki into spe (http://spe.pycs.net)""" global settings settings = Settings(dirname=".spe", filename="kikicfg.py", debugfile="kikidebug") Kiki = MyFrameWithEvents(parent, -1, "") Kiki.SetTitle(Kiki.GetTitle() + " - the ferret in your Spe") if info and info.has_key('kikiPath'): kikipath = info['kikiPath'] else: kikipath = os.path.join(os.path.dirname(sys.argv[0]), "framework/contributions") Kiki.icon(kikipath) Kiki.Show(1) return Kiki def main(): global settings settings = Settings(dirname=".kiki", filename="kikicfg.py", debugfile="kikidebug") Kiki = wx.PySimpleApp() wx.InitAllImageHandlers() mw = MyFrameWithEvents(None, -1, "") mw.icon() Kiki.SetTopWindow(mw) mw.Show(1) Kiki.MainLoop() if __name__ == "__main__": main() kiki-0.5.6.orig/kiki.wxg0000644000175000017500000007342510035311504013543 0ustar dokodoko Kiki 1 640, 480 wxHORIZONTAL wxEXPAND 0 wxSPLIT_HORIZONTAL 120 BottomPane TopPane 0 5 1 3 0 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 1 0 2 0 wxEXPAND 0 0 0 1 ID_EVALUATE wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 1 2 0 wxEXPAND 0 0 1 Find all returns all matches, find first only the first one Find all Find first 0 wxHORIZONTAL wxEXPAND 0 15 4 3 7 wxEXPAND 0 2 7 wxEXPAND 0 2 7 wxEXPAND 0 2 7 0 Perform case-insensitive matching\nExpressions like [A-Z] will match lowercase letters too. This is not affected by the current locale. 0 Make \w, \W, \\b, and \B dependent on the current locale. 0 When specified, the pattern characters "^" and "$" match at the beginning respectively end of the string and at the beginning respectively end of each line (immediately following respectively preceding each newline).\nOtherwise "^" matches only at the beginning of the string, and "$" only at the end of the string and immediately before the newline (if any) at the end of the string. 0 Make the "." special character match any character at all, including a newline. Without this flag, "." will match anything except a newline. 0 Make \w, \W, \\b, and \B dependent on the Unicode character properties database. 0 This flag allows you to write regular expressions that look nicer.\nWhitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash, and, when a line contains a "#" neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such "#" through the end of the line are ignored. wxEXPAND 0 2 7 wxEXPAND 0 2 7 wxEXPAND 0 2 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 623, 324 wxHORIZONTAL wxEXPAND 0 Matches Sample text Help ID_NOTEBOOK wxHORIZONTAL wxEXPAND 0 $parent $id wxHORIZONTAL wxEXPAND 0 7 2 3 0 1 7 wxEXPAND 0 1 1 wxEXPAND 0 0 Working with Kiki Re - syntax Re - special characters: |, (, +, etc. Re - extensions, groups and lookahead/lookbehind: (?...) Re - special sequences: \... Re - flags About Kiki ID_HELPCOMBOBOX wxEXPAND 0 $parent $id kiki-0.5.6.orig/readme.txt0000644000175000017500000000541210035311504014052 0ustar dokodokoKIKI 0.5.6 - regexes made nifty Copyright (C) 2003, 2004 Project 5 (http://come.to/project5) Licence: GPL (free) Requires: Python, wxPython System: any, provided (wx)Python runs on it Installation ============ Make sure you install first (if not already present on your system): - Python (2.3.x or newer) from: http://python.org - wxPython (2.4.2.4 or later - preferably 2.5.1.5 or later) from: http://wxpython.org Then unpack this archive to some directory and run "kiki.py" either by double-clicking on it or by entering at the command line prompt "python kiki.py". Windows users might want to use "Kiki.bat" to run it instead. You might want to add it to your start menu too. Windows users should open the Kiki directory in the explorer. Right-click on "Kiki.bat" and, keeping the right mouse button pressed, drag and drop the file on the Start button. If you want the icon in there too, proceed as follows: - go to the Start menu and right-click on "Kiki", then choose "Properties" - go to the "Shortcut" tab and click on "Other icon" (not sure what it is on English systems). You will get a warning message, ignore it. - click on the Browse button and go to the Kiki directory. Select the "kiki.ico" file and then click on the "Open" button. Linux users should use whatever facilities their distro provides to manipulate the menu. Integration with Spe ==================== Spe is a very good Python editor, also written in Python/wxPython. It is available at http://spe.pycs.net. The distribution includes an unmodified version of Kiki. You can access it from the Tools menu. Uninstalling ============ - remove the folder where you unpacked kiki.py You can also remove the folder in your $HOME directory called ".kiki". This is where Pears stores its stuff. Under WinXP, the $HOME folder can be located at: C:\Documents and Settings\ Help ==== For help, see the Help tab in the program. Credits ======= Once upon a time, there was a Tkinter-based application called "Recon - Regular expression test console", written by Brent Burley, which I found quite useful for writing regexes. I decided that I needed something with more features and better looks. Kiki and Recon share no code at all, but they share the design philosophy. I decided to call my program "Ferret" (short for "Free Environment for Regular Expression Testing"). On second thought, I thought it would be better to name it after the most famous (in fact after the *only* famous) ferret I know: Kiki from the very funny Sluggy online comic (http://sluggy.com). Plans for future versions ========================= - overview of named groups History ======= The project history is present in "history.txt".kiki-0.5.6.orig/kiki-0.5.6/0000755000175000017500000000000010276345004013456 5ustar dokodokokiki-0.5.6.orig/kiki-0.5.6/__init__.py0000644000175000017500000000000010035311504015544 0ustar dokodokokiki-0.5.6.orig/kiki-0.5.6/docs/0000755000175000017500000000000010035311502014373 5ustar dokodokokiki-0.5.6.orig/kiki-0.5.6/docs/about.html0000644000175000017500000001021410035311454016377 0ustar dokodoko About Kiki
Kiki
Kiki is a free environment for regular expression testing (ferret).

Program info
Version: %(version)s
Program directory: %(kikidir)s
Data directory: %(datadir)s
Python version: %(pythonversion)s
wxPython version: %(wxpythonversion)s
Spe status: %(spe)s

Contact info
Web: %(website)s
e-mail/msn: %(mail)s
icq: %(icq)s

Credits
Kiki is built using a number of tools besides the extensive libraries of Python and wxPython:
  • the Spe Python editor
  • wxGlade for GUI design
  • the SciTE editor for Python and HTML coding
  • recon.py by Brent Burley for inspiration and correctness testing
  • part of the Python documentation is ripped and included in this distro
Of course I should also thank Pete Abrams for his Sluggy Freelance online comic which has kept me entertained for quite some time now and has also been the source of the name of this program. For those of you who don't know the comic: Kiki is a talking ferret which is very fond of bright colors and happy thoughts.

Licence
This program is © 2003, 2004 by Project 5
It is licenced under the GNU General Public Licence (GPL)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

kiki-0.5.6.orig/kiki-0.5.6/docs/index.html0000644000175000017500000002411107735675706016427 0ustar dokodoko Working with Kiki
Intro
Kiki is a free environment for regular expression testing (ferret). It allows you to write regexes and test them against your sample text, providing extensive output about the results. It is useful for several purposes:
  • exploring and understanding the structure of match objects generated by the re module, making Kiki a valuable tool for people new to regexes
  • testing regexes on sample text before deploying them in code
Kiki can function on its own or as plugin for the Spe Python editor.

Working with Kiki
Enter the regex in the combo box and hit Evaluate to run it against the text in the Sample text tab. The results appear in the Matches tab. You can use the list in the Help tab to view the built-in documentation about regular expressions. This documentation comes from the Python help files.

Kiki automatically stores its settings and the last used sample text/regex in between sessions. During a session, all regexes which have been evaluated and have returned matches, are also stored in the combo box where the regex is entered, so you may experiment with e.g. adapted versions without losing a more primitive regex that already kinda works.

Options
Methods
Use Find all to get all non-overlapping matches of the regex, or Find first to get only the first match (equivalent to the search method of regular expression objects).
Flags
Determines which flags the regex should be compiled with.

Understanding the output
Kiki's output is quite extensive and provides color-coded information on the results of the match. Let's assume you're trying to match the regex fer(re)*t against the sample text Kiki the ferret - as nifty as ferrets get. The results of a Find all evaluation by default looks something like this:

Kiki the 0:(fer(re)1t)0 - as nifty as 1:(fer(re)1t)0s get


Each match is prepended by a small, underlined number: this is the index of the corresponding match object in the list of match objects found in the sample text. In the example above, there are two match objects, with indexes 0 and 1.

Within each match, colored parentheses show where a match group starts and ends. Group ()0 represents the entire match. In this example we have also created an extra group because of the use of (re)*". This is made visible by the green parentheses bearing the index 1: ()1.

Pay attention to an interesting property of these groups: some of them might not contribute to the match and are then skipped in the output (in the match object, these groups start and end at position -1). An example: let's find all sentences talking about expecting the Spanish Inquisition in the text below:

Chapman: I didn't expect a kind of Spanish Inquisition.

(JARRING CHORD - the cardinals burst in)

Ximinez: NOBODY expects the Spanish Inquisition! Our chief weapon is surprise...surprise and fear...fear and surprise.... Our two weapons are fear and surprise...and ruthless efficiency.... Our *three* weapons are fear, surprise, and ruthless efficiency...and an almost fanatical devotion to the Pope.... Our *four*...no... *Amongst* our weapons.... Amongst our weaponry...are such elements as fear, surprise.... I'll come in again. (Exit and exeunt)


For this purpose, we can use e.g. the following regex:

([a-zA-Z']+\s)+?expect(.*?)(the )*Spanish Inquisition(!|.)

The result is:

Chapman: 0:(I (didn't )1expect( a kind of )2Spanish Inquisition(.)4)0

(JARRING CHORD - the cardinals burst in)

Ximinez: 1:((NOBODY )1expect(s )2(the )3Spanish Inquisition(!)4)0 Our chief weapon is surprise...surprise and fear...fear and surprise.... Our two weapons are fear and surprise...and ruthless efficiency.... Our *three* weapons are fear, surprise, and ruthless efficiency...and an almost fanatical devotion to the Pope.... Our *four*...no... *Amongst* our weapons.... Amongst our weaponry...are such elements as fear, surprise.... I'll come in again. (Exit and exeunt)


The interesting part is what's going on in the match with index 0: between the group with index 2 and the one with index 4, the group with index 3 has disappeared. This group matches an optional the which is not present in this case. In other words, the group exists, but does not contribute to the match and is therefore not displayed.

kiki-0.5.6.orig/kiki-0.5.6/docs/re.html0000644000175000017500000012425707735651214015726 0ustar dokodoko Regular expression docs
Syntax
A regular expression (or RE) specifies a set of strings that matches it. Kiki helps you find out if a certain regular expression matches a particular string.

Regular expressions can be concatenated to form new regular expressions: if A and B are both regular expressions, then AB is also a regular expression.
If a string p matches A and another string q matches B, the string pq will match AB (presuming the two RE's don't specify boundary conditions that are no longer satisfied by pq.
This means that complex expressions can easily be constructed from simpler primitive expressions.

Regular expressions can contain both special and ordinary characters. Most ordinary characters, like A, a, or 0, are the simplest regular expressions: they simply match themselves. You can concatenate ordinary characters, so last matches the string last.
Note the color coding used throughout these docs: this is a regex while this is a string.

Some characters, like | or (, are special. Special characters, when used in regular expressions, either stand for classes of ordinary characters, or affect how the regular expressions around them are interpreted.

Special characters
. (dot) In the default mode, this matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline.
^ (caret) Matches the start of the string, and in MULTILINE mode also matches immediately after each newline.
$ Matches the end of the string or just before the newline at the end of the string, and in MULTILINE mode also matches before a newline.
foo matches both foo and foobar, while the regular expression foo$ matches only foo. More interestingly, searching for foo.$ in foo1\nfoo2\n matches foo2 normally, but foo1 in MULTILINE mode.
* Causes the resulting RE to match 0 or more repetitions of the preceding RE, as many repetitions as are possible.ab* will match a, ab, or a followed by any number of b's.
+ Causes the resulting RE to match 1 or more repetitions of the preceding RE. ab+ will match a followed by any non-zero number of b's. It will not match just a.
? Causes the resulting RE to match 0 or 1 repetitions of the preceding RE. ab? will match either a or ab.
*?, +?, ?? The *, +, and ? qualifiers are all greedy: they match as much text as possible. Sometimes this behaviour isn't desired. If the RE <.*> is matched against <H1>title</H1>, it will match the entire string, and not just <H1>. Adding ? after the qualifier makes it perform the match in non-greedy or minimal fashion: as few characters as possible will be matched. Using .*? in the previous expression will match only <H1>.
{m} Specifies that exactly m copies of the previous RE should be matched; fewer matches cause the entire RE not to match. For example, a{6} will match exactly six a characters, but not five.
{m,n} Causes the resulting RE to match from m to n repetitions of the preceding RE, attempting to match as many repetitions as possible. For example, a{3,5} will match from 3 to 5 a characters. Omitting m specifies a lower bound of zero, and omitting n specifies an infinite upper bound. As an example, a{4,}b will match aaaab or a thousand a characters followed by a b, but not aaab. The comma may not be omitted or the modifier would be confused with the previously described form.
{m,n}? Causes the resulting RE to match from m to n repetitions of the preceding RE, attempting to match as few repetitions as possible. This is the non-greedy version of the previous qualifier. For example, on the 6-character string aaaaaa, a{3,5} will match 5 a characters, while a{3,5}? will only match 3 characters.
\ Either escapes special characters (permitting you to match characters like *, ?, and so forth), or signals a special sequence; special sequences are discussed below.

If you're not using a raw string to express the pattern, remember that Python also uses the backslash as an escape sequence in string literals; if the escape sequence isn't recognized by Python's parser, the backslash and subsequent character are included in the resulting string. However, if Python would recognize the resulting sequence, the backslash should be repeated twice. This is complicated and hard to understand, so it's highly recommended that you use raw strings for all but the simplest expressions.
[] Used to indicate a set of characters. Characters can be listed individually, or a range of characters can be indicated by giving two characters and separating them by a -. Special characters are not active inside sets. For example, [akm$] will match any of the characters a, k, m, or $. [a-z] will match any lowercase letter, and [a-zA-Z0-9] matches any letter or digit. Character classes such as \w or \S (defined below) are also acceptable inside a range. If you want to include a ] or a - inside a set, precede it with a backslash, or place it as the first character. The pattern []] will match ], for example.

You can match the characters not within a range by complementing the set. This is indicated by including a ^ as the first character of the set. ^ elsewhere will simply match the ^ character. For example, [^5] will match any character except 5, and [^^] will match any character except ^.
| A|B, where A and B can be arbitrary REs, creates a regular expression that will match either A or B. An arbitrary number of REs can be separated by the | in this way. This can be used inside groups (see below) as well. REs separated by | are tried from left to right, and the first one that allows the complete pattern to match is considered the accepted branch. This means that if A matches, B will never be tested, even if it would produce a longer overall match. In other words, the | operator is never greedy. To match a literal |, use \|, or enclose it inside a character class, as in [|].
(...) Matches whatever regular expression is inside the parentheses, and indicates the start and end of a group; the contents of a group can be retrieved after a match has been performed, and can be matched later in the string with the \number special sequence, described below. To match the literals ( or ), use \( or \), or enclose them inside a character class: [(] [)].
(?...) This is an extension notation (a ? following a ( is not meaningful otherwise). The first character after the ? determines what the meaning and further syntax of the construct is. Extensions usually do not create a new group; (?P<name>...) is the only exception to this rule. The supported extensions are listed below.

Extensions
(?iLmsux) (One or more letters from the set i, L, m, s, u, x.) The group matches the empty string and the letters set the corresponding flags (re.I, re.L, re.M, re.S, re.U, re.X) for the entire regular expression. This is useful if you wish to include the flags as part of the regular expression, instead of passing a flag argument to the compile() function.

Note that the (?x) flag changes how the expression is parsed. It should be used first in the expression string, or after one or more whitespace characters. If there are non-whitespace characters before the flag, the results are undefined.
(?:...) A non-grouping version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern.
(?P<name>...) Similar to regular parentheses, but the substring matched by the group is accessible via the symbolic group name name. Group names must be valid Python identifiers, and each group name must be defined only once within a regular expression. A symbolic group is also a numbered group, just as if the group were not named. So the group named id in the example above can also be referenced as the numbered group 1.

For example, if the pattern is (?P<id>[a-zA-Z_]\w*), the group can be referenced by its name in arguments to methods of match objects, such as m.group('id') or m.end('id'), and also by name in pattern text (for example, (?P=id)) and replacement text (such as \g<id>).
(?P=name) Matches whatever text was matched by the earlier group named name.
(?#...) A comment; the contents of the parentheses are simply ignored.
(?=...) Matches if ... matches next, but doesn't consume any of the string. This is called a lookahead assertion. For example, Isaac (?=Asimov) will match Isaac  only if it's followed by Asimov.
(?!...) Matches if ... doesn't match next. This is a negative lookahead assertion. For example, Isaac (?!Asimov) will match Isaac  only if it's not followed by Asimov.
(?<=...) Matches if the current position in the string is preceded by a match for ... that ends at the current position. This is called a positive lookbehind assertion. (?<=abc)def will find a match in abcdef, since the lookbehind will back up 3 characters and check if the contained pattern matches. The contained pattern must only match strings of some fixed length, meaning that abc or a|b are allowed, but a* and a{3,4} are not. Note that patterns which start with positive lookbehind assertions will never match at the beginning of the string being searched. You will most likely want to use the search() function rather than the match() function:
    >>> import re
    >>> m = re.search('(?<=abc)def', 'abcdef')
    >>> m.group(0)
    def
                    
This example looks for a word following a hyphen:
    >>> m = re.search('(?<=-)\w+', 'spam-egg')
    >>> m.group(0)
    egg
                    
(?<!...) Matches if the current position in the string is not preceded by a match for .... This is called a negative lookbehind assertion. Similar to positive lookbehind assertions, the contained pattern must only match strings of some fixed length. Patterns which start with negative lookbehind assertions may match at the beginning of the string being searched.

Special sequences
The special sequences consist of \ and a character from the list below. If the ordinary character is not on the list, then the resulting RE will match the second character. For example, \$ matches the character $.
\\ matches a literal backslash character
\number Matches the contents of the group of the same number. Groups are numbered starting from 1. For example, (.+) \1 matches the the or 55 55, but not the end (note the space after the group). This special sequence can only be used to match one of the first 99 groups. If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number. Inside the [ and ] of a character class, all numeric escapes are treated as characters.
\a ASCII Bell (BEL)
\A Matches only at the start of the string.
\b Matches the empty string, but only at the beginning or end of a word. A word is defined as a sequence of alphanumeric or underscore characters, so the end of a word is indicated by whitespace or a non-alphanumeric, non-underscore character. Note that \b is defined as the boundary between \w and \W, so the precise set of characters deemed to be alphanumeric depends on the values of the LOCALE and UNICODE flags.
Inside a character range, \b represents the backspace character, for compatibility with Python's string literals.
\B Matches the empty string, but only when it is not at the beginning or end of a word. This is just the opposite of \b, so is also subject to the settings of LOCALE and UNICODE.
\d Matches any decimal digit. This is equivalent to the set [0-9].
\D Matches any non-digit character; this is equivalent to the set [^0-9].
\f ASCII Formfeed (FF)
\n ASCII Linefeed (LF)
\r ASCII Carriage Return (CR)
\s Matches any whitespace character. This is equivalent to the set [ \t\n\r\f\v].
\S Matches any non-whitespace character. This is equivalent to the set [^ \t\n\r\f\v].
\t ASCII Horizontal Tab (TAB)
\v ASCII Vertical Tab (VT)
\w When the LOCALE and UNICODE flags are not specified, matches any alphanumeric character and the underscore. This is equivalent to the set [a-zA-Z0-9_].
With LOCALE, it will match the set [0-9_] plus whatever characters are defined as alphanumeric for the current locale.
If UNICODE is set, this will match the characters [0-9_] plus whatever is classified as alphanumeric in the Unicode character properties database.
\W When the LOCALE and UNICODE flags are not specified, matches any non-alphanumeric character. This is equivalent to the set [^a-zA-Z0-9_].
With LOCALE, it will match any character not in the set [0-9_], and not defined as alphanumeric for the current locale.
If UNICODE is set, this will match anything other than [0-9_] and characters marked as alphanumeric in the Unicode character properties database.
\xhh ASCII character with hex value hh
\Z Matches only at the end of the string.

Flags
The RE's behaviour can be modified by specifying a flags value. Values can be any of the following variables, combined using bitwise or (the | operator).
IGNORECASE (I) Perform case-insensitive matching. Expressions like [A-Z] will match lowercase letters, too. This is not affected by the current locale.
LOCALE (L) Make \w, \W, \b, and \B dependent on the current locale.
MULTILINE (M) When specified, the pattern character ^ matches at the beginning of the string and at the beginning of each line (immediately following each newline) and the pattern character $ matches at the end of the string and at the end of each line (immediately preceding each newline).
By default, ^ matches only at the beginning of the string, and $ only at the end of the string and immediately before the newline (if any) at the end of the string.
DOTALL (S) Make the . special character match any character at all, including a newline. Without this flag, . will match anything except a newline.
UNICODE (U) Make \w, \W, \b, and \B dependent on the Unicode character properties database (since Python 2.0).
VERBOSE (X) This flag allows you to write regular expressions that look nicer. Whitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash, and, when a line contains a # neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such # through the end of the line are ignored.
kiki-0.5.6.orig/kiki-0.5.6/history.txt0000644000175000017500000000235110035311504015710 0ustar dokodokoKIKI 0.5.6 - regexes made nifty Copyright (C) 2003, 2004 Project 5 (http://come.to/project5) Licence: GPL (free) Requires: Python, wxPython System: any, provided (wx)Python runs on it History ======= 0.5.6 (8-4-2004, 32.5 kB) - changed code to support wxPython 2.5.1.5 - saves settings before evaluating the regex 0.5.5 (29-9-2003, 32.5kB) - fixed bug which caused the selected regex to disappear to the history when Evalute was activated - fixed Linux bug which caused warning messages to be displayed when a different doc was selected in the Help tab - small changes in code and docs - first public release outside Spe 0.5 (28-9-2003, 32.8kB) = added really nifty colors = added docs and about screen = added ferrety Easter Egg :) = added __init__.py so that Kiki can be used as package in Spe - fixed bug that meant flags were actually not used when compiling the regex - locale used to be after multiline - restored alphabetical order 0.2 (26-9-2003, 25.7kB) - fixed a bug with caused empty regex results to lead to an infinite loop = added pretty icons :) - added support for integration in Spe - misc changes 0.1: - first version, only available in Spe 0.1.8.a kiki-0.5.6.orig/kiki-0.5.6/Kiki.bat0000644000175000017500000000015510035311504015025 0ustar dokodoko@ECHO OFF @ECHO Use this file to start the program under Windows. SET PATH start pythonw -OO kiki.py exitkiki-0.5.6.orig/kiki-0.5.6/kiki.ico0000644000175000017500000002635607735110360015116 0ustar dokodokoh6 ¨ ž00¨F( @ïïïa`b~€ttp¡ Ÿßßßïïï840\`Z‰ŽˆŠrqqdcbßßßïïï000|ur65G––ÊŠ†Ä21KÊÐÈ…a`aïïï`ba000¿¹ÀVR|œ™ñ–•ð—•ÎSSc®´¬#$!0/1ŸŸŸßßß €œžhdˆ¡œàZ`NTm&âäß120%%(666ïïï{‡‰†ÁÀÅ<8SJEe¦©²ÕÝØÃÊÊäçê999ßßßßßß,+\a]óóõ!áæâáäãíðòâãäc``VVVßßßßßß)* ÐÎ̺»¹êêé*)*“˜e\P‘w1>4445†††ßßßïïïKRS" G7mcd¼»Ãéíóg\:ĤFSH`efpppßßß|‡ˆHEHZPÄ¥AfY%ãèâ÷øûľ¶K=' ÖÛß^\\ª¨©ßßß?NNMKKaRͪFn[*áÞÛÿûû÷úús{€§ª¬öù÷ãáâpnoŸ¢¢~~IA9;) e\QòñøüûöÚÝÚX[^"&"±·¯¦¦¦jklßßßUVVíïófgeWYXøüü¬­©SQV³¯³³²µGJKfgg¶··ßßßdpoÿýþËËË GGGtttêêêïïïßßß&43»·¸ïïïFFFïïﯰ°ƒ‚‚ppp»»»øðààÀÀ€€€ÀÀààààðÿ( @€ ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ+03MSRDEA  ÀÀÀÀÀÀÀÀÀÀÀÀ }€~íõôæîíæëéïïétqiÀÀÀÀÀÀÀÀÀ svgˆ…)18 ! @@L¶²½¡œ594 ÀÀÀÀÀÀÀÀÀ ››‚ƒTWv£¥Î‘‘¿A>kMSNðôîÊÐÅkod/0'ÀÀÀÀÀÀÀÀÀcYYçâä+':*&O¿ý¢žêŸ™ê¹³ÿ~tÀ{€ôüòýÿ÷ž¢–QQK!ÀÀÀÀÀÀ200ëãã­¦µŒ†¿¬¦ø˜”ô™”÷Šå¯ªÿhe~ ÍÑÒûÿù,3&_]]kgmÀÀÀÀÀÀ  ‡‚ƒÿþþgal6­ªâ™˜è““ñ”—ò¡ò–œå³«Ú -eftûÿþš¡”SSSÀÀÀÀÀÀ&>>ÚÕÖÿýýAAA2¤¤Ô£¥ì˜žñ§õŽœÞ†•Í©œÚD, ruƒøÿþª¬¬ÀÀÀÀÀÀLeg—’”  ª3»&ɨ;±šJ61·½¬úþøÿÿøîíýÿüÿúóð‹‚x&/*3úùÿ÷ÿý®°°-$'ÀÀÀÀÀÀ¤¨©XVV%#"Ǭ4Ƥ,˨:¶M>5 ³³¥ÿþúÿÿûÿþÿýýÿóöû¬°µ!%*58=ÝÝãýüÿúÿþüþþ—’“ ÀÀÀÀÀÀ4NN ,,ÈÊÊ –{%Ô´[ЫY§ŒTÓÎÐÿûÿÿóûÿÿ÷ôøòøÿÿ¸ÄÈKW[——ýÿûÿÿ÷åìéýÿÿýøù0-/ÀÀÀÀÀÀ ‡Œ™”•!+_G^A@*?63ÛØçÿúÿÿúÿÿÿòûÿ÷ôûöÔÞÞpzzENAòøåúÿþýÿÿÔÒÒ%$&ÀÀÀÀÀÀÚÕÖù¹ 'EJ]_ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ"0-,)   , 6 ; 6 " 0@AÀÀÀÀÀÀÀÀÀÀÀÀ€žœ<@? -(Ar'F%K&L}&@q)T (,,ÀÀÀÀÀÀÀÀÀÀÀÀDST "8.I…@‡K‰ H…&E.DŠ#7i ";   ÀÀÀÀÀÀÀÀÀÀÀÀg}} +3G|%Cˆ#HŒ$G…#CŒ%C)J#I|E  ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ3GG&2Y4K‰&E'E†!A‰ABI0H„!4[% ³³³ÀÀÀÀÀÀÀÀÀÀÀÀ¬«ÀÀÀÀÀÀ !&:f+GŽ(E‹#Aˆ&F‹$FŒ"F‹%F‡,K‡,H{>ŠŠŠÀÀÀÀÀÀÀÀÀ”²²NY\9+GŒ(E+HŒ*G†+Fƒ,G„%I…FŠ#D1E#@...ÀÀÀÀÀÀÀÀÀÀÀÀ´¯ ";#E‡)K%Gˆ%F†#Dƒ'Gˆ'G‰$D‡)I‹#B‚)[ ]^]ÀÀÀÀÀÀÀÀÀ $P5L…(H‹#H‹$Hˆ&Fˆ%E‡$D†)I‹*JŒ%C})D {|{ÀÀÀÀÀÀÀÀÀÀÀÀ%% &O,G„ E‰!E‡(I‹(HŠ&Fˆ'G‰'G‰(IŠ&G€'I ÎÎÎÀÀÀ/CA .W+I%Fˆ%Fˆ&Fˆ(HŠ&Fˆ$D†"Cˆ"C‹/H}; pppÀÀÀÀÀÀÀÀÀÀÀÀE[Y%"Hb_|˜•„¢Ÿw•’_}5RN1Y,F‡&Eˆ#C…'G‰(HŠ%E‡(F‰+DŠ-IŒ!;q.###ÁÁÁÀÀÀÀÀÀv–”J\Y‚—•ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀz‘$.A A+>x,G‡#F‰"H‹%G†-I…4E†%B†,K#9k ‚ƒ…ÀÀÀÀÀÀ*77Ѝ¥ÀÀÀÀÀÀÀÀÀ‚œž 3+@v!E‹G Fƒ-I,E‡)F„+GŒ2F‰!@ SV[ÀÀÀÀÀÀ h}ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀc)H)D†!A’&GŒ'F‚#DŽ"F‰#C/GŒ%<]  "&ÀÀÀÀÀÀÀÀÀ w•’ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀFYM  0Bx*B*G"D„CEˆ$FŽ%=~,F  ¼¾¿ÀÀÀNYW x˜“ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀWg\&1Q2E€)F‡%G‹%GŽ!G„&D„#Y%' ‚ƒ„ÀÀÀÀÀÀ RfbÀÀÀÀÀÀÀÀÀ™ÏÍÀÀÀÀÀÀKij'./FHM 0V.K… Aˆ'Gˆ(_'S `abÀÀÀÀÀÀ!!ÀÀÀÀÀÀŒ»¸ÀÝÜÀÀÀ-38pno  0W%F…%C‘%F‚ #L&=# DEFÀÀÀÀÀÀ?LKÀÀÀÀÀÀ|˜—?ML /Z(C‹(EˆSQÀÀÀÀÀÀÀÀÀ‡ˆ‰62-    ÀÀÀÀÀÀ(00+?=ÀÀÀÀÀÀj„€2.. …†¢¨¦”•=96ÀÀÀÀÀÀ6BB"!ÀÀÀÀÀÀ=RO# hleRY`AFWMM^„‚‹dgc*,)ÀÀÀÀÀÀOdb ÀÀÀÀÀÀ˜”>:VUNsPLj‰Œ•ÂÊÃÄËɯ´µçêì]]bBBBÀÀÀÀÀÀÀÀÀ®« ,1/òòŠNOYâåë÷üý÷üûúþÿô÷û¸»Ã"#*mmm000ÀÀÀ_…ƒ·¹µäãå=>@ÄÈÂäæá¥¨¦º»¾ðñô•’‰B:(%$$ŠŠŠ///ÀÀÀjЉ YZVÝÜÚ·¸¶îîì---Z[_ÉËÌE6v/~l3DDE³³³666ÀÀÀЍ¨   NLB@;2RKN»¶¿€~„¿Àij¶¶gQͨ?¨;fgh­­­=<<ÀÀÀÀÀÀ²ÝÜ&250'+ R?¡‚;eM!‚€vñöúùùýÎÑËVI)~i2aR'«³µ‹Œ‹A9;ÀÀÀÍûûBVXTSU ’(¢7¯•B_]>ãèàùúùñð÷Æ¿·VK< gdjìðòŒŒŒ-%(ÀÀÀŽ®®KWXihh ”~*ʨ?¸œK\U;åãßÿûúûüûìðów~ƒQVYïïðöùøêêëa\]ÀÀÀ°ÛÚ1GE€„„B<Error:
    %s
""" t_nomatch = """No match found""" # colors used to highlight matches colors = ["0000AA" , "00AA00" , "FFAA55" , "AA0000" , "00AAAA" , "AA00AA" , "AAAAAA" , "0000FF" , "00FF00" , "00FFFF" , "FF0000" , "DDDD00" , "FF00FF" , "AAAAFF" , "FF55AA" , "AAFF55" , "FFAAAA" , "55AAFF" , "FFAAFF" , "000077" , "007700" , "770000" , "007777" , "770077" , "777700" ] class Settings(object): """Stores and retrieves settings to a file as Python data structures which are eval()-ed. This is not by definition safe, but since the user has access to source code anyway and hence the ability to screw up anything, the danger seems quite limited.""" def __init__(self, savedir=None, dirname="", filename="settings.py", debugfile=""): """Initializes the object Arguments: savedir -- directory where to store data For more info, see the docs of Settings.setSaveDir() dirname -- if savedir=None, dirname is used to determine which subdirectory of $HOME data is stored it. filename -- name of file containing stored data debugfile -- used to allow the user to manually override the default storage dir. Mor info in the docs of Settings.setSaveDir() """ self.__setSaveDir(savedir, dirname, debugfile) self.savefilename = filename self.__load() def shutdown(self): """Must be called before the program ends.""" self.save() def __setSaveDir(self, savedir=None, dirname="", debugfile=""): """Sets self.savedir Arguments: savedir -- directory where to store data if savedir==None, $HOME/dirname is used. If necessary, the directory is created. dirname -- if savedir==None, dirname determines which subdirectory of the home dir data is stored in debugfile -- this file may be a filename which is imported and may contain a variable called savedir If the debugfile is specified, imported successfully and savedir exists, it is used to override any other parameters. This allows users to override the directory, bypassing the application which needs the settings. In some Windows installations (seems to be mainly a Win2k problem), $HOME points to the root directory. In this case, this function will try to use $USERPROFILE/dirname instead. Overriding this default behaviour is possible by supplying the savedir variable in pearsdebug.py.""" if savedir==None: try: # try to override using debugfile if present and contains savedir debugmodule = __import__(debugfile, globals()) savedir = debugmodule.savedir except: # if no override, then perform default actions if savedir == None: # use $HOME/dirname savedir = os.path.expanduser('~/'+dirname) if len(savedir)<=len("c:\\/"+dirname): # sometimes $HOME points to root # if this is the case, try using $USERPROFILE (see docstring) temp = os.path.join(os.path.expandvars('$USERPROFILE'), dirname) # if this is a different location, use it! if temp > len("C:\\/"+dirname): savedir = temp # create dir if it doesn't exist if not os.path.exists(savedir): os.makedirs(savedir) self.savedir = savedir def __load(self): """Loads the settings from a file. These settings are saved in Python code format which is eval()-ed, so it's not trustworthy.""" try: settingsfile = file(os.path.join(self.savedir, self.savefilename), "r") self.settings = eval(settingsfile.read()) settingsfile.close() except: # if file doesn't exist self.settings= {} def save(self): """Saves the settings to a file.""" settingsfile = file(os.path.join(self.savedir, self.savefilename), "w") settingsfile.write(str(self.settings)) settingsfile.close() def set(self, settingname, value): """Changes the value of a setting with settingname to value.""" self.settings[settingname] = value def get(self, settingname, defaultval=None): """Returns the setting with settingname if present, otherwise returns defaultval and saves settingname with defaultval.""" if self.settings.has_key(settingname): return self.settings[settingname] else: self.set(settingname, defaultval) return defaultval class MyHtmlWindow(wx.html.HtmlWindow): """Adds OnLinkClicked""" def __init__(self, parent, id): wx.html.HtmlWindow.__init__(self, parent, id, style=wx.NO_FULL_REPAINT_ON_RESIZE) def OnLinkClicked(self, linkinfo): # there's a problem in KDE: the browser is not recognized properly # circumvent this problem import os if os.environ.has_key("BROWSER") and \ os.environ["BROWSER"]=='kfmclient openProfile webbrowsing': print "Invalid browser detected : %s\nResetting to konqueror." % os.environ["BROWSER"] os.environ["BROWSER"] = 'konqueror' # set it to konqueror import webbrowser # MUST be imported only AFTER os.environ has been modified webbrowser.open(linkinfo.GetHref(), 1) class MyFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.SplitterWindow = wx.SplitterWindow(self, -1, style=wx.SP_3D|wx.SP_LIVE_UPDATE) self.BottomPane = wx.Panel(self.SplitterWindow, -1) self.Notebook = wx.Notebook(self.BottomPane, ID_NOTEBOOK, style=0) self.HelpPane = wx.Panel(self.Notebook, -1) self.SampleTextPane = wx.Panel(self.Notebook, -1) self.MatchesPane = wx.Panel(self.Notebook, -1, style=wx.SUNKEN_BORDER|wx.TAB_TRAVERSAL) self.TopPane = wx.Panel(self.SplitterWindow, -1, style=wx.RAISED_BORDER|wx.TAB_TRAVERSAL) self.RegexBox = wx.ComboBox(self.TopPane, -1, choices=["", "", "", "", "", "", ""], style=wx.CB_DROPDOWN) self.EvaluateButton = wx.Button(self.TopPane, ID_EVALUATE, "Evaluate") self.MethodBox = wx.RadioBox(self.TopPane, -1, "Methods", choices=["Find all", "Find first"], majorDimension=1, style=wx.RA_SPECIFY_COLS) self.IgnoreCheckBox = wx.CheckBox(self.TopPane, -1, "IGNORECASE (I)") self.LocaleCheckBox = wx.CheckBox(self.TopPane, -1, "LOCALE (L)") self.MultilineCheckBox = wx.CheckBox(self.TopPane, -1, "MULTILINE (M)") self.DotAllCheckBox = wx.CheckBox(self.TopPane, -1, "DOTALL (S)") self.UnicodeCheckBox = wx.CheckBox(self.TopPane, -1, "UNICODE (U)") self.VerboseCheckBox = wx.CheckBox(self.TopPane, -1, "VERBOSE (X)") self.MatchesWindow = wx.html.HtmlWindow(self.MatchesPane, -1) self.SampleText = wx.TextCtrl(self.SampleTextPane, -1, "", style=wx.TE_PROCESS_TAB|wx.TE_MULTILINE|wx.TE_RICH) self.HelpSelection = wx.ComboBox(self.HelpPane, ID_HELPCOMBOBOX, choices=["Working with Kiki", "Re - syntax", "Re - special characters: |, (, +, etc.", "Re - extensions, groups and lookahead/lookbehind: (?...)", "Re - special sequences: \...", "Re - flags", "About Kiki"], style=wx.CB_DROPDOWN|wx.CB_READONLY) self.HelpWindow = MyHtmlWindow(self.HelpPane, -1) self.__set_properties() self.__do_layout() # end wxGlade def __set_properties(self): # begin wxGlade: MyFrame.__set_properties self.SetTitle("Kiki") self.SetSize((640, 480)) self.RegexBox.SetSelection(0) self.EvaluateButton.SetDefault() self.MethodBox.SetToolTipString("Find all returns all matches, find first only the first one") self.MethodBox.SetSelection(0) self.IgnoreCheckBox.SetToolTipString("Perform case-insensitive matching\nExpressions like [A-Z] will match lowercase letters too. This is not affected by the current locale.") self.LocaleCheckBox.SetToolTipString("Make \w, \W, \\b, and \B dependent on the current locale.") self.MultilineCheckBox.SetToolTipString("When specified, the pattern characters \"^\" and \"$\" match at the beginning respectively end of the string and at the beginning respectively end of each line (immediately following respectively preceding each newline).\nOtherwise \"^\" matches only at the beginning of the string, and \"$\" only at the end of the string and immediately before the newline (if any) at the end of the string.") self.DotAllCheckBox.SetToolTipString("Make the \".\" special character match any character at all, including a newline. Without this flag, \".\" will match anything except a newline.") self.UnicodeCheckBox.SetToolTipString("Make \w, \W, \\b, and \B dependent on the Unicode character properties database.") self.VerboseCheckBox.SetToolTipString("This flag allows you to write regular expressions that look nicer.\nWhitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash, and, when a line contains a \"#\" neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such \"#\" through the end of the line are ignored. ") self.HelpSelection.SetSelection(0) self.BottomPane.SetSize((623, 324)) self.SplitterWindow.SplitHorizontally(self.TopPane, self.BottomPane, 120) # end wxGlade def __do_layout(self): # begin wxGlade: MyFrame.__do_layout MainSizer = wx.BoxSizer(wx.HORIZONTAL) TopPaneSizer = wx.BoxSizer(wx.HORIZONTAL) HelpPaneSizer = wx.FlexGridSizer(3, 1, 7, 7) SampleTextSizer = wx.BoxSizer(wx.HORIZONTAL) MatchesPaneSizer = wx.BoxSizer(wx.HORIZONTAL) BottomPaneSizer = wx.FlexGridSizer(5, 3, 0, 0) OptionsSizer = wx.FlexGridSizer(1, 2, 0, 7) FlagsSizer = wx.StaticBoxSizer(wx.StaticBox(self.TopPane, -1, "Flags"), wx.HORIZONTAL) FlagCheckSizer = wx.FlexGridSizer(4, 3, 7, 15) RegexSizer = wx.FlexGridSizer(1, 2, 0, 7) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) RegexSizer.Add(self.RegexBox, 0, wx.EXPAND, 0) RegexSizer.Add(self.EvaluateButton, 0, 0, 0) RegexSizer.AddGrowableCol(0) BottomPaneSizer.Add(RegexSizer, 1, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) OptionsSizer.Add(self.MethodBox, 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add(self.IgnoreCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.LocaleCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.MultilineCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.DotAllCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.UnicodeCheckBox, 0, 0, 0) FlagCheckSizer.Add(self.VerboseCheckBox, 0, 0, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagCheckSizer.Add((7, 2), 0, wx.EXPAND, 0) FlagsSizer.Add(FlagCheckSizer, 1, wx.EXPAND, 0) OptionsSizer.Add(FlagsSizer, 1, 0, 0) BottomPaneSizer.Add(OptionsSizer, 1, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) BottomPaneSizer.Add((7, 7), 0, wx.EXPAND, 0) self.TopPane.SetAutoLayout(1) self.TopPane.SetSizer(BottomPaneSizer) BottomPaneSizer.Fit(self.TopPane) BottomPaneSizer.SetSizeHints(self.TopPane) BottomPaneSizer.AddGrowableCol(1) MatchesPaneSizer.Add(self.MatchesWindow, 1, wx.EXPAND, 0) self.MatchesPane.SetAutoLayout(1) self.MatchesPane.SetSizer(MatchesPaneSizer) MatchesPaneSizer.Fit(self.MatchesPane) MatchesPaneSizer.SetSizeHints(self.MatchesPane) SampleTextSizer.Add(self.SampleText, 1, wx.EXPAND, 0) self.SampleTextPane.SetAutoLayout(1) self.SampleTextPane.SetSizer(SampleTextSizer) SampleTextSizer.Fit(self.SampleTextPane) SampleTextSizer.SetSizeHints(self.SampleTextPane) HelpPaneSizer.Add((1, 1), 0, wx.EXPAND, 0) HelpPaneSizer.Add(self.HelpSelection, 0, wx.EXPAND, 0) HelpPaneSizer.Add(self.HelpWindow, 1, wx.EXPAND, 0) self.HelpPane.SetAutoLayout(1) self.HelpPane.SetSizer(HelpPaneSizer) HelpPaneSizer.Fit(self.HelpPane) HelpPaneSizer.SetSizeHints(self.HelpPane) HelpPaneSizer.AddGrowableRow(2) HelpPaneSizer.AddGrowableCol(0) self.Notebook.AddPage(self.MatchesPane, "Matches") self.Notebook.AddPage(self.SampleTextPane, "Sample text") self.Notebook.AddPage(self.HelpPane, "Help") TopPaneSizer.Add(wx.NotebookSizer(self.Notebook), 1, wx.EXPAND, 0) self.BottomPane.SetAutoLayout(1) self.BottomPane.SetSizer(TopPaneSizer) MainSizer.Add(self.SplitterWindow, 1, wx.EXPAND, 0) self.SetAutoLayout(1) self.SetSizer(MainSizer) self.Layout() self.Centre() # end wxGlade # end of class MyFrame class MyFrameWithEvents(MyFrame): """Subclasses MyFrame - generated by wxGlade - and adds events.""" def __init__(self, *args, **kwargs): MyFrame.__init__(self, *args, **kwargs) # map option flags to checkboxes self.flagmapper = {FLAGIGNORE: self.IgnoreCheckBox, FLAGMULTILINE: self.MultilineCheckBox, FLAGLOCALE: self.LocaleCheckBox, FLAGDOTALL: self.DotAllCheckBox, FLAGUNICODE: self.UnicodeCheckBox, FLAGVERBOSE: self.VerboseCheckBox} self.SetTitle(" " + self.GetTitle() + " " + __version__) # set empty pages for HTML windows self.MatchesWindow.SetPage("") self.HelpWindow.SetPage("") self.HelpWindow.SetWindowStyleFlag(wx.SUNKEN_BORDER) self.Notebook.SetSelection(0) self.RegexBox.Clear() # bind events wx.EVT_BUTTON(self, ID_EVALUATE, self.evaluate) wx.EVT_CLOSE(self, self.close) wx.EVT_NOTEBOOK_PAGE_CHANGED(self, ID_NOTEBOOK, self.changePage) wx.EVT_COMBOBOX(self, ID_HELPCOMBOBOX, self.showhelp) # apply settings self.loadSettings() # move focus to regex input field self.RegexBox.SetFocus() # initialize needed attribs self.matches = [] # list of found matches self.path = os.path.split(sys.argv[0])[0] or os.getcwd() # remembers where Kiki is located def icon(self, path=None): """Load and assign the icon Arguments: path -- path where kiki.ico is located. If path==None, the current directory is used """ import sys if path==None: self.path = os.path.split(sys.argv[0])[0] or os.getcwd() # *MUST* be the directory where everything, including About data and the likes are located else: self.path = path iconfile = os.path.join(self.path, "kiki.ico") theicon = wx.Icon(iconfile, wx.BITMAP_TYPE_ICO) self.SetIcon(theicon) def changePage(self, event): """Handles notebook page changes""" if event.GetSelection()==2 and not self.HelpWindow.GetOpenedPageTitle().strip(): self.HelpWindow.SetPage(file(os.path.join(self.path, "docs", "index.html"),"r").read()) def showhelp(self, event): """Handles help combo box events""" sel = self.HelpSelection.GetStringSelection().lower() # must lower-case for comparisons id = self.HelpSelection.GetSelection() filename, anchor = "", "" simpleload = True if id==0: # show main help filename = "index.html" elif sel.find("syntax")>-1: filename, anchor = "re.html", "syntax" elif sel.find("special characters")>-1: filename, anchor = "re.html", "specialcharacters" elif sel.find("extensions")>-1: filename, anchor = "re.html", "extensions" elif sel.find("special sequences")>-1: filename, anchor = "re.html", "specialsequences" elif sel.find("flags")>-1: filename, anchor = "re.html", "flags" else: simpleload = False if simpleload: filename = os.path.join(self.path, "docs", filename) if anchor.strip(): anchor = "#" + anchor else: anchor = "" self.HelpWindow.LoadPage(filename+anchor) else: # build about-screen f = file(os.path.join(self.path, "docs", "about.html"), "r") about = f.read() f.close() # build the dictionary needed to format the string if self.GetTitle().lower().find("spe")>-1: spe = "active" else: spe = "inactive (Kiki running standalone)" d = {"version": __version__, "kikidir": self.path, "datadir": settings.savedir, "pythonversion": sys.version.split()[0], "wxpythonversion": wx.__version__, "spe": spe, "website": "http://come.to/project5", "mail": "project5@wanadoo.nl", "icq": "84243714" } about = about % d self.HelpWindow.SetPage(about) def evaluate(self, event): """Actual functionality, triggered by Evaluate button press. The regex is compiled if possible. If compilation is successful, the regex is added to the history and it's matched against the sample text. If compilation is unsuccessful, the error message is displayed. """ self.saveSettings() self.Notebook.SetSelection(0) # display output pane # STEP 1: try to compile the regex # get flags to use in the compilation flags = 0 for flag in self.flagmapper.keys(): if self.flagmapper[flag].IsChecked(): flags = flags|eval(flag) # compile the regex and stop with error message if invalid try: self.MatchesWindow.SetPage("") regex = re.compile(self.RegexBox.GetValue(), flags) except re.error, e: self.MatchesWindow.SetPage(t_error % e) return False # stop execution if error if self.RegexBox.GetValue().strip(): # append to history if non-empty # get current history items currentitems = [self.RegexBox.GetValue()] for i in range(self.RegexBox.GetCount()): t = self.RegexBox.GetString(0) if not t in currentitems: # no duplicates currentitems.append(t) self.RegexBox.Delete(0) for item in currentitems: self.RegexBox.Append(item) self.RegexBox.SetSelection(0) # set selection again rawtext = self.SampleText.GetValue() # insider joke for the Sluggy fans if rawtext.strip()=="INSTANT FERRET-SHOCK!": import random shock = [""] #blinkychars = """+*-/\:;][{}|tyqfghjkl?>ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%""" rc = random.choice c = colors sa = shock.append t = """KIKI""" [ sa(t % (rc(c))) for i in xrange(10000) ] shock.append("") self.MatchesWindow.SetPage("".join(shock)) return None self.matches = [] # empty the list of match objects output = [] while 1: if len(self.matches)==0: start = 0 else: start = self.matches[-1].end() if len(self.matches[-1].group(0))==0: # in case of expressions which return empty matches # Without this condition, an endless loop would occur. start += 1 match = regex.search(rawtext, start) if (not match) or \ (len(self.matches)>=1 and self.MethodBox.GetSelection()==1) or \ start>=len(rawtext): # this last condition is also to prevent an endless loop break # stop execution else: self.matches.append(match) if not self.matches: # if no matches found output.append(t_nomatch) else: # matches found # show matches with parentheses if settings.get(RESULTS_SHOWMATCHES, True): output.append(self.showmatches()) output.append("""

""") # show tabular overview of named groups if settings.get(RESULTS_SHOWNAMEDGROUPS, True): # TODO: self.shownamedgroups() pass if settings.get(RESULTS_SHOWSAMPLE, True): output.append("""
Sample text matched against:
""") output.append(self.htmlize(rawtext) or " ") # something must be in there, so if no raw text, at least force a space output.append("""
""") self.MatchesWindow.SetPage("".join(output)) def htmlize(self, text): """Converts the text to html (escapes HTML entities and tags, converts spaces to  's and enters to
's.""" result = cgi.escape(text) result = result.replace("\t", "    ") result = result.replace(" ", "  ") result = result.replace("\r\n", "
") result = result.replace("\r", "
") result = result.replace("\n", "
") return result def formatmatch(self, match, index, matchtemplate, starttemplate, endtemplate): """Pretty-prints a match as HTML, with colors for groups, etc.""" # first, make a dictionary of start and end positions # (each char number in the match may be mapped to zero, one or more # group numbers which start/end there) # Groups function according to first-to-open, last-to-close. starts, ends = {}, {} # populate the dictionaries with empty lists # A -1 key is necessary for groups which do not participate in the match. for pos in range(-1, len(match.string)+1): starts[pos], ends[pos] = [], [] # now populate them with real values: each position key will contain # none or more group numbers #print match.groups() for groupnr in range(1+len(match.groups())): #print groupnr #print starts, ends starts[match.start(groupnr)].append(groupnr) ends[match.end(groupnr)].append(groupnr) # prepare result result = [] # now, loop through the string matched and build the layout string = match.string opengroups = [] # keeps track of open groups for pos in range(match.start(), match.end()+1): while 1: # first, try to shut down any open groups if opengroups and opengroups[-1] in ends[pos]: # if opengroups available and the last one must be closed now # shut down open group and remove it from the opengroups list result.append(endtemplate % {GROUPCOLOR: colors[opengroups[-1] % len(colors)], GROUPNUMBER: opengroups.pop(-1)}) # secondly, try to open any new groups elif starts[pos]: # if any new groups must be opened now result.append(starttemplate % {GROUPCOLOR: colors[starts[pos][0] % len(colors)], GROUPNUMBER: starts[pos][0]}) opengroups.append(starts[pos].pop(0)) else: # if no groups must be opened or closed, nothing special going on if pos""") # load match layout templates starttemplate = settings.get(STARTTEMPLATE, """(""" % GROUPCOLOR) endtemplate = settings.get(ENDTEMPLATE, """)%%(%s)s""" % (GROUPCOLOR, GROUPNUMBER)) matchtemplate = settings.get(MATCHTEMPLATE, """%%(%s)s:%%(%s)s""" % (MATCHINDEX, FORMATTEDMATCH)) # loop through matches and create output for match in self.matches: index += 1 # determine what part of the string we're looking at if index>0: prevmatchend = self.matches[index-1].end() else: prevmatchend = 0 if index+1 < len(self.matches): nextmatchstart = self.matches[index+1].start() else: nextmatchstart = -1 # append piece in between matches html.append(self.htmlize(match.string[prevmatchend:match.start()])) # append current match #html.append(self.htmlize(match.string[match.start():match.end()])) html.append(self.formatmatch(match, index, matchtemplate, starttemplate, endtemplate)) # append end piece if necessary if index+1 >= len(self.matches): # if last match, print rest of string html.append(self.htmlize(match.string[match.end():])) html.append("""""") res = "".join(html) return res def loadSettings(self): """Loads GUI settings from the settings system.""" # load some size settings # set window size and position; make sure it's on screen # and has a reasonable size system = wx.SystemSettings_GetMetric pos = list(settings.get(WINDOWPOSITION, (-1,-1))) if pos[0]<-1: pos[0] = 0 if pos[1]<-1: pos[1] = 0 if pos[0]>system(wx.SYS_SCREEN_X)-50: pos[0] = 0 if pos[1]>system(wx.SYS_SCREEN_Y)-50: pos[1] = 0 self.SetPosition(pos) size = list(settings.get(WINDOWSIZE, (-1, -1))) if size[0]>system(wx.SYS_SCREEN_X): size[0] = 640 if size[1]>system(wx.SYS_SCREEN_Y): size[1] = 480 size[0] = max(size[0], 640) size[1] = max(size[1], 480) self.SetSize(size) # load the sample text and regex last used self.SampleText.SetValue(settings.get(SAMPLETEXT, "")) self.RegexBox.SetValue(settings.get(REGEX, "")) # load the flags and desired type of re functionality for flag in self.flagmapper.keys(): self.flagmapper[flag].SetValue(settings.get(flag, False)) self.MethodBox.SetSelection(settings.get(SEARCHTYPE, 0)) # other settings self.SplitterWindow.SetSashPosition(settings.get(SASHPOSITION, 100)) def saveSettings(self, dosave=True): """Puts all GUI settings in the settings system. Arguments: dosave -- if True, the save() method of Settings is called when done """ # put all stuff that needs saving in the settings settings.set(WINDOWSIZE, self.GetSize()) settings.set(WINDOWPOSITION, self.GetPosition()) settings.set(SASHPOSITION, self.SplitterWindow.GetSashPosition()) settings.set(SAMPLETEXT, self.SampleText.GetValue()) settings.set(REGEX, self.RegexBox.GetValue()) # save the selected flags for flag in self.flagmapper.keys(): settings.set(flag, self.flagmapper[flag].GetValue()) settings.set(SEARCHTYPE, self.MethodBox.GetSelection()) if dosave: settings.save() def close(self, event): """Prepares for shutdown and then closes the app.""" self.saveSettings() # shut down the settings system settings.shutdown() # shut down the app self.Destroy() def speCreate(parent, info=None): """Integration of Kiki into spe (http://spe.pycs.net)""" global settings settings = Settings(dirname=".spe", filename="kikicfg.py", debugfile="kikidebug") Kiki = MyFrameWithEvents(parent, -1, "") Kiki.SetTitle(Kiki.GetTitle() + " - the ferret in your Spe") if info and info.has_key('kikiPath'): kikipath = info['kikiPath'] else: kikipath = os.path.join(os.path.dirname(sys.argv[0]), "framework/contributions") Kiki.icon(kikipath) Kiki.Show(1) return Kiki def main(): global settings settings = Settings(dirname=".kiki", filename="kikicfg.py", debugfile="kikidebug") Kiki = wx.PySimpleApp() wx.InitAllImageHandlers() mw = MyFrameWithEvents(None, -1, "") mw.icon() Kiki.SetTopWindow(mw) mw.Show(1) Kiki.MainLoop() if __name__ == "__main__": main() kiki-0.5.6.orig/kiki-0.5.6/kiki.wxg0000644000175000017500000007342510035311504015136 0ustar dokodoko Kiki 1 640, 480 wxHORIZONTAL wxEXPAND 0 wxSPLIT_HORIZONTAL 120 BottomPane TopPane 0 5 1 3 0 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 1 0 2 0 wxEXPAND 0 0 0 1 ID_EVALUATE wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 1 2 0 wxEXPAND 0 0 1 Find all returns all matches, find first only the first one Find all Find first 0 wxHORIZONTAL wxEXPAND 0 15 4 3 7 wxEXPAND 0 2 7 wxEXPAND 0 2 7 wxEXPAND 0 2 7 0 Perform case-insensitive matching\nExpressions like [A-Z] will match lowercase letters too. This is not affected by the current locale. 0 Make \w, \W, \\b, and \B dependent on the current locale. 0 When specified, the pattern characters "^" and "$" match at the beginning respectively end of the string and at the beginning respectively end of each line (immediately following respectively preceding each newline).\nOtherwise "^" matches only at the beginning of the string, and "$" only at the end of the string and immediately before the newline (if any) at the end of the string. 0 Make the "." special character match any character at all, including a newline. Without this flag, "." will match anything except a newline. 0 Make \w, \W, \\b, and \B dependent on the Unicode character properties database. 0 This flag allows you to write regular expressions that look nicer.\nWhitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash, and, when a line contains a "#" neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such "#" through the end of the line are ignored. wxEXPAND 0 2 7 wxEXPAND 0 2 7 wxEXPAND 0 2 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 wxEXPAND 0 7 7 623, 324 wxHORIZONTAL wxEXPAND 0 Matches Sample text Help ID_NOTEBOOK wxHORIZONTAL wxEXPAND 0 $parent $id wxHORIZONTAL wxEXPAND 0 7 2 3 0 1 7 wxEXPAND 0 1 1 wxEXPAND 0 0 Working with Kiki Re - syntax Re - special characters: |, (, +, etc. Re - extensions, groups and lookahead/lookbehind: (?...) Re - special sequences: \... Re - flags About Kiki ID_HELPCOMBOBOX wxEXPAND 0 $parent $id kiki-0.5.6.orig/kiki-0.5.6/readme.txt0000644000175000017500000000541210035311504015445 0ustar dokodokoKIKI 0.5.6 - regexes made nifty Copyright (C) 2003, 2004 Project 5 (http://come.to/project5) Licence: GPL (free) Requires: Python, wxPython System: any, provided (wx)Python runs on it Installation ============ Make sure you install first (if not already present on your system): - Python (2.3.x or newer) from: http://python.org - wxPython (2.4.2.4 or later - preferably 2.5.1.5 or later) from: http://wxpython.org Then unpack this archive to some directory and run "kiki.py" either by double-clicking on it or by entering at the command line prompt "python kiki.py". Windows users might want to use "Kiki.bat" to run it instead. You might want to add it to your start menu too. Windows users should open the Kiki directory in the explorer. Right-click on "Kiki.bat" and, keeping the right mouse button pressed, drag and drop the file on the Start button. If you want the icon in there too, proceed as follows: - go to the Start menu and right-click on "Kiki", then choose "Properties" - go to the "Shortcut" tab and click on "Other icon" (not sure what it is on English systems). You will get a warning message, ignore it. - click on the Browse button and go to the Kiki directory. Select the "kiki.ico" file and then click on the "Open" button. Linux users should use whatever facilities their distro provides to manipulate the menu. Integration with Spe ==================== Spe is a very good Python editor, also written in Python/wxPython. It is available at http://spe.pycs.net. The distribution includes an unmodified version of Kiki. You can access it from the Tools menu. Uninstalling ============ - remove the folder where you unpacked kiki.py You can also remove the folder in your $HOME directory called ".kiki". This is where Pears stores its stuff. Under WinXP, the $HOME folder can be located at: C:\Documents and Settings\ Help ==== For help, see the Help tab in the program. Credits ======= Once upon a time, there was a Tkinter-based application called "Recon - Regular expression test console", written by Brent Burley, which I found quite useful for writing regexes. I decided that I needed something with more features and better looks. Kiki and Recon share no code at all, but they share the design philosophy. I decided to call my program "Ferret" (short for "Free Environment for Regular Expression Testing"). On second thought, I thought it would be better to name it after the most famous (in fact after the *only* famous) ferret I know: Kiki from the very funny Sluggy online comic (http://sluggy.com). Plans for future versions ========================= - overview of named groups History ======= The project history is present in "history.txt".