Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'skip:u 30': 0.07; 'output,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'separating': 0.09; 'subject:into': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; '2.7': 0.14; '*args):': 0.16; 'dict': 0.16; 'ignoring': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'skip:f 60': 0.16; 'skip:q 30': 0.16; 'skip:u 60': 0.16; 'subject:selection': 0.16; 'subject:unicode': 0.16; 'unicode.': 0.16; 'vowel': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; '>>>': 0.22; 'import': 0.22; 'issue.': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'unicode': 0.24; 'this:': 0.26; 'tracker': 0.26; 'pass': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'asked': 0.31; 'code': 0.31; 'class': 0.32; 'another': 0.32; 'text': 0.33; 'checking': 0.33; 'framework': 0.33; 'skip:_ 10': 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'there': 0.35; 'marks': 0.36; 'step': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'does': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'new': 0.61; 'received:173': 0.61; 'email addr:gmail.com': 0.63; '8bit%:95': 0.64; '8bit%:100': 0.72; 'received:fios.verizon.net': 0.84; 'skip:\xe0 10': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: re.finditer() skips unicode into selection Date: Wed, 26 Jun 2013 16:14:48 -0400 References: <1d412b4a-b043-4723-909a-54c6c06cebd4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: <1d412b4a-b043-4723-909a-54c6c06cebd4@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 77 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372277713 news.xs4all.nl 15954 [2001:888:2000:d::a6]:58929 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49274 On 6/26/2013 3:18 PM, akshay.ksth@gmail.com wrote: > I am using the following Highlighter class for Spell Checking to work o= n my QTextEdit. > > class Highlighter(QSyntaxHighlighter): > pattern =3D ur'\w+' > def __init__(self, *args): > QSyntaxHighlighter.__init__(self, *args) > self.dict =3D None > > def setDict(self, dict): > self.dict =3D dict > > def highlightBlock(self, text): > if not self.dict: > return > text =3D unicode(text) > format =3D QTextCharFormat() > format.setUnderlineColor(Qt.red) > format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline) > unicode_pattern=3Dre.compile(self.pattern,re.UNICODE|re.LOCALE= ) > > for word_object in unicode_pattern.finditer(text): > if not self.dict.spell(word_object.group()): > print word_object.group() > self.setFormat(word_object.start(), word_object.end() = - word_object.start(), format) > > But whenever I pass unicode values into my QTextEdit the re.finditer() = does not seem to collect it. > > When I pass "I am a =E0=A4=A8=E0=A5=87=E0=A4=AA=E0=A4=BE=E0=A4=B2=E0=A5= =80" into the QTextEdit. The output is like this: > > I I I a I am I am I am a I am a I am a I am a I am a I am a I am a= I am a > > It is completely ignoring the unicode. The whole text is unicode. It is ignoring the non-ascii, as you asked it = to with re.LOCALE. With 3.3.2: import re pattern =3D re.compile(r'\w+', re.LOCALE) text =3D "I am a =E0=A4=A8=E0=A5=87=E0=A4=AA=E0=A4=BE=E0=A4=B2=E0=A5=80" for word in pattern.finditer(text): print(word.group()) >>> I am a Delete ', re.LOCALE' and the following are also printed: =E0=A4=A8 =E0=A4=AA =E0=A4=B2 There is an issue on the tracker about the vowel marks in =E0=A4=A8=E0=A5= =87=E0=A4=AA=E0=A4=BE=E0=A4=B2=E0=A5=80 being=20 mis-seen as word separators, but that is another issue. Lesson: when you do not understand output, simplify code to see what=20 changes. Separating re issues from framework issues is a big step in=20 that direction. ? What might be the issue. I am new to PyQt and regex. Im using Python=20 2.7 and PyQt4. --=20 Terry Jan Reedy