Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:code': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:characters': 0.09; 'exception': 0.12; 'def': 0.15; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'posted,': 0.16; 'soup': 0.16; 'subject: \n ': 0.16; 'subject:non': 0.16; 'part,': 0.18; 'trying': 0.21; 'stuff': 0.22; 'header:In-Reply-To:1': 0.22; 'code': 0.25; 'guess': 0.26; 'skip:b 20': 0.26; "i'm": 0.27; 'code,': 0.28; 'problem': 0.28; 'import': 0.28; 'stefan': 0.29; 'character.': 0.30; 'subject:?': 0.31; "didn't": 0.31; 'hi,': 0.32; 'source': 0.33; 'to:addr:python-list': 0.33; 'header:User- Agent:1': 0.34; 'header:X-Complaints-To:1': 0.35; 'subject:How': 0.35; 'file': 0.36; 'but': 0.37; 'received:org': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'subject:from': 0.40; "it's": 0.40; 'you.': 0.62; 'tag': 0.64; 'received:188': 0.68; 'subject:removal': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Stefan Behnel Subject: Re: How do I automate the removal of all non-ascii characters from my code? Date: Mon, 12 Sep 2011 10:43:51 +0200 References: <4E6DC028.1020101@islandtraining.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: ppp-188-174-36-144.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315817058 news.xs4all.nl 2492 [2001:888:2000:d::a6]:39632 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13162 Alec Taylor, 12.09.2011 10:33: > from creole import html2creole > > from BeautifulSoup import BeautifulSoup > > VALID_TAGS = ['strong', 'em', 'p', 'ul', 'li', 'br', 'b', 'i', 'a', 'h1', 'h2'] > > def sanitize_html(value): > > soup = BeautifulSoup(value) > > for tag in soup.findAll(True): > if tag.name not in VALID_TAGS: > tag.hidden = True > > return soup.renderContents() > html2creole(u(sanitize_html('''

style="margin-left:76.8px;margin-right:0;text-indent:0;">Abstract

>

style="margin-left:76.8px;margin-right:0;text-indent:0;"> > [more stuff here] > """)) Hi, I'm not sure what you are trying to say with the above code, but if it's the code that fails for you with the exception you posted, I would guess that the problem is in the "[more stuff here]" part, which likely contains a non-ASCII character. Note that you didn't declare the source file encoding above. Do as Gary told you. Stefan