Package: debian-keyring
Version: 2009.01.18
Severity: minor
Tags: patch

Hello,

whilst the changelog for the Debian keyring is now properly UTF-8
encoded, there are some names that are wrongly spelled due to being
double encoded as UTF-8.

For example (and feel free to skip this paragraph if you’re not
interested in the details), my surname in UTF-8 is encoded as
‘Sim\xc3\xb3’, which interpreted as ISO-8859-1 yields ‘Simó’; which is
the spelling you can read throughout the changelog, but only because the
actual bytes written there are ‘Sim\xc3\x83\xc2\xb3’, i.e. the UTF-8
encoding of the string ‘Simó’. That’s what I mean with double UTF-8.

Anyway. Please find attached a patch that fixes hopefully all instances
of this problem in the changelog. I’ve done my best so that it’s
comprehensive, but some may have escaped.

I’m also sending the scripts I used to generate the patch. The _byname
version is the one I wrote first and ended up using; the idea of writing
a programatical one came later, and it turned out it missed some
degenerated cases.

I’d be grateful if you could apply this patch to your copy of the
changelog.

Cheers,

-- 
- Are you sure we're good?
- Always.
        -- Rory and Lorelai

Attachment: debian-keyring-changelog.diff.gz
Description: Binary data

#! /usr/bin/python3

import re
import sys

the_dict = {
    r'Adeodato Simó':                   'Adeodato Simó',
    r'Ana Beatriz Guerrero López':      'Ana Beatriz Guerrero López',
    r'Andrés Roldán':                  'Andrés Roldán',
    r'Clément Stenac':                  'Clément Stenac',
    r'Cédric Delfosse':                 'Cédric Delfosse',
    r'Damián Viano':                    'Damián Viano',
    r'David Martínez Moreno':           'David Martínez Moreno',
    r'Esteban Manchado VelÃ\x83¡zquez': 'Esteban Manchado Velázquez',
    r'Frank Küster':                    'Frank Küster',
    r'Frederik Schüler':                'Frederik Schüler',
    r'Göran Weinholt':                  'Göran Weinholt',
    r'Javier Fernández-Sanguino Peña': 'Javier Fernández-Sanguino Peña',
    r'José L. Redrejo Rodríguez':      'José L. Redrejo Rodríguez',
    r'Jérémy Bobbio':                  'Jérémy Bobbio',
    r'Jérôme Marant':                  'Jérôme Marant',
    r'Krzysztof Krzy¿aniak (eloy)':      'Krzysztof Krzyżaniak (eloy)',
    r'Krzysztof Krzy¿aniak (eloy)':     'Krzysztof Krzyżaniak (eloy)',
    r'Krzysztof Krzyżaniak (eloy)':     'Krzysztof Krzyżaniak (eloy)',
    r'Loïc Minier (lool)':              'Loïc Minier (lool)',
    r'Marc Dequènes (Duck)':            'Marc Dequènes (Duck)',
    r'Martin Sjögren':                  'Martin Sjögren',
    r'Michal Ä\x8cihaÅ\x99':             'Michal Čihař',
    r'Mohammed Adnène Trojette (adn)':  'Mohammed Adnène Trojette (adn)',
    r'Niklas Höglund':                  'Niklas Höglund',
    r'Ond\xc5\x99ej Surý':               'Ondřej Surý',
    r'Ond\xc5ej Surý':                   'Ondřej Surý',
    r'OndÅ\x99ej Surý':                 'Ondřej Surý',
    r'Piotr Ożarowski':                 'Piotr Ożarowski',
    r'Quôc Peyrot':                     'Quôc Peyrot',
    r'Recai OktaÅ\x9f':                  'Recai Oktaş',
    r'René van Bevern':                 'René van Bevern',
    r'René van Bevern (Debian)':        'René van Bevern (Debian)',
    r'Robert Jördens':                  'Robert Jördens',
    r'Rémi Perrot':                     'Rémi Perrot',
    r'Santiago Ruano Rincón':           'Santiago Ruano Rincón',
    r'Sebastian Dröge':                 'Sebastian Dröge',
    r'Steffen Möller (private)':        'Steffen Möller (private)',
    r'Søren Boll Overgaard':            'Søren Boll Overgaard',
    r'Teófilo Ruiz Suárez':            'Teófilo Ruiz Suárez',
}

regex = re.compile('|'.join(map(re.escape, the_dict.keys())))

for line in open('/org/keyring.debian.org/changelog'):
    line = regex.sub(lambda m: the_dict[m.group(0)], line)
    sys.stdout.write(line)
#! /usr/bin/python

import re
import sys

def hex_to_str(m):
    return chr(int(m.group(1), 16))

for line in open('/org/keyring.debian.org/changelog'):
    try:
        latin1 = line.decode('utf-8').encode('latin1')
    except UnicodeEncodeError:
        sys.stdout.write(line)
    else:
        try:
            utf8 = latin1.decode('utf-8').encode('utf-8')
        except UnicodeDecodeError:
            latin1 = re.sub(r'\\x([0-9A-Fa-f]{2})', hex_to_str, latin1)
            try:
                utf8 = latin1.decode('utf-8').encode('utf-8')
            except UnicodeDecodeError:
                sys.stdout.write(line)
            else:
                sys.stdout.write(utf8)
        else:
            sys.stdout.write(utf8)

Reply via email to