Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64051

Re: Guessing the encoding from a BOM

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '16,': 0.03; 'elif': 0.05; 'cc:addr:python-list': 0.11; 'jan': 0.12; '1:13': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'starts': 0.20; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'guess': 0.33; 'subject:the': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'two': 0.37; 'pm,': 0.38; 'checks.': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=jt0vsaK8OF/c4BJlEuu3m97Y8gqn+ac3MKpAUjbOYTU=; b=WIGa4GCUosVffuMiQ6UagfEDSXbwk8gsWh8CVSI4JlMMAzL7AvGZgM0atdVAM8uCMD zEQ6yJqnlmaTOkVsELWaBCVdAauVddbh3XDu9gyLLUfKsX57i32y2bh2Hc8QI0sEqN1C Fs19S14mf6cFA8XrMWIupVfOvXkfuOtt0V1EXtcd3840781YV/xwyQ/ptUlar30Qo7Xc PHPSXdpaCac88J/Vb+ah4p/dP4Si5OMlcFbrWIdjOLRxINfJ5ITMbR5oZuxjXfH2Ba8J HGCJ/Oohk6xHuXiqQCFuBoevYrvcdpA2qpgZQY+V+OtrwSwGbasgDsPIFLLxLLpj9WeP B6Iw==
MIME-Version 1.0
X-Received by 10.66.163.36 with SMTP id yf4mr7492413pab.67.1389848516401; Wed, 15 Jan 2014 21:01:56 -0800 (PST)
In-Reply-To <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com>
References <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com>
Date Thu, 16 Jan 2014 16:01:56 +1100
Subject Re: Guessing the encoding from a BOM
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5568.1389848524.18130.python-list@python.org> (permalink)
Lines 11
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389848524 news.xs4all.nl 2953 [2001:888:2000:d::a6]:50176
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64051

Show key headers only | View raw


On Thu, Jan 16, 2014 at 1:13 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
>     if sig.startswith((b'\xFE\xFF', b'\xFF\xFE')):
>         return 'utf_16'
>     elif sig.startswith((b'\x00\x00\xFE\xFF', b'\xFF\xFE\x00\x00')):
>         return 'utf_32'

I'd swap the order of these two checks. If the file starts FF FE 00
00, your code will guess that it's UTF-16 and begins with a U+0000.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Guessing the encoding from a BOM Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-16 02:13 +0000
  Re: Guessing the encoding from a BOM Ben Finney <ben+python@benfinney.id.au> - 2014-01-16 14:47 +1100
    Re: Guessing the encoding from a BOM Steven D'Aprano <steve@pearwood.info> - 2014-01-16 06:55 +0000
      Re: Guessing the encoding from a BOM Ethan Furman <ethan@stoneleaf.us> - 2014-01-15 23:29 -0800
  Re: Guessing the encoding from a BOM Chris Angelico <rosuav@gmail.com> - 2014-01-16 16:01 +1100
    Re: Guessing the encoding from a BOM Steven D'Aprano <steve@pearwood.info> - 2014-01-16 06:45 +0000
  Re: Guessing the encoding from a BOM Ethan Furman <ethan@stoneleaf.us> - 2014-01-15 21:40 -0800
  Re: Guessing the encoding from a BOM Björn Lindqvist <bjourne@gmail.com> - 2014-01-16 19:01 +0100
  Re: Guessing the encoding from a BOM Chris Angelico <rosuav@gmail.com> - 2014-01-17 05:06 +1100
  Re: Guessing the encoding from a BOM Tim Chase <python.list@tim.thechases.com> - 2014-01-16 12:50 -0600

csiph-web