From 417571176b0da8b242b6e46f01160161bf3c5f0a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 4 Jan 2011 12:55:37 +0100 Subject: [PATCH 1/4] #560: Change default split_owner to return something useful. --- sphinx/domains/cpp.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 64bf06ca7..c2a320ebb 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -149,9 +149,9 @@ class DefExpr(object): """Nodes returned by :meth:`get_name` can split off their owning parent. This function returns the owner and the name as a tuple of two items. If a node does not support - it, :exc:`NotImplementedError` is raised. + it, it returns None as owner and self as name. """ - raise NotImplementedError() + return None, self def prefix(self, prefix): """Prefixes a name node (a node returned by :meth:`get_name`).""" @@ -169,9 +169,6 @@ class PrimaryDefExpr(DefExpr): def get_name(self): return self - def split_owner(self): - return None, self - def prefix(self, prefix): if isinstance(prefix, PathDefExpr): prefix = prefix.clone() From 54e1ab93bacea78c482f5631a98f378340577528 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 4 Jan 2011 15:33:18 +0100 Subject: [PATCH 2/4] #570: Try decoding ``-D`` and ``-A`` command-line arguments with the locale's preferred encoding. --- CHANGES | 3 +++ sphinx/cmdline.py | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 7e4de2d2d..83b0bf5c1 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ Release 1.0.6 (in development) ============================== +* #570: Try decoding ``-D`` and ``-A`` command-line arguments with + the locale's preferred encoding. + * #528: Observe :confval:`locale_dirs` when looking for the JS translations file. diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index d2e3a4b17..af780167a 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -90,6 +90,13 @@ def main(argv): if err: return 1 + # likely encoding used for command-line arguments + try: + locale = __import__('locale') # due to submodule of the same name + likely_encoding = locale.getpreferredencoding() + except Exception: + likely_encoding = None + buildername = None force_all = freshenv = warningiserror = use_pdb = False status = sys.stdout @@ -129,7 +136,11 @@ def main(argv): try: val = int(val) except ValueError: - pass + if likely_encoding: + try: + val = val.decode(likely_encoding) + except UnicodeError: + pass confoverrides[key] = val elif opt == '-A': try: @@ -141,7 +152,11 @@ def main(argv): try: val = int(val) except ValueError: - pass + if likely_encoding: + try: + val = val.decode(likely_encoding) + except UnicodeError: + pass confoverrides['html_context.%s' % key] = val elif opt == '-n': confoverrides['nitpicky'] = True From 5c0c465db282a6c46a8b3afe6c2c78c85db9786c Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 4 Jan 2011 17:14:00 +0100 Subject: [PATCH 3/4] #383: Support sorting a limited range of accented characters in the general index. --- CHANGES | 3 +++ sphinx/environment.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 83b0bf5c1..2abc67951 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ Release 1.0.6 (in development) ============================== +* #383: Support sorting a limited range of accented characters + in the general index. + * #570: Try decoding ``-D`` and ``-A`` command-line arguments with the locale's preferred encoding. diff --git a/sphinx/environment.py b/sphinx/environment.py index 549a553db..b0d64e4a7 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -16,6 +16,7 @@ import types import codecs import imghdr import string +import unicodedata import cPickle as pickle from os import path from glob import glob @@ -1477,7 +1478,7 @@ class BuildEnvironment: # sort the index entries; put all symbols at the front, even those # following the letters in ASCII, this is where the chr(127) comes from def keyfunc(entry, lcletters=string.ascii_lowercase + '_'): - lckey = entry[0].lower() + lckey = unicodedata.normalize('NFD', entry[0].lower()) if lckey[0:1] in lcletters: return chr(127) + lckey return lckey @@ -1519,7 +1520,7 @@ class BuildEnvironment: # hack: mutating the subitems dicts to a list in the keyfunc v[1] = sorted((si, se) for (si, (se, void)) in v[1].iteritems()) # now calculate the key - letter = k[0].upper() + letter = unicodedata.normalize('NFD', k[0])[0].upper() if letter in letters: return letter else: From 9624ff5e10e2109febedb573a44567f3d20dc468 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 4 Jan 2011 19:23:47 +0100 Subject: [PATCH 4/4] #148: Support sorting a limited range of accented characters in the glossary. --- CHANGES | 4 ++-- sphinx/domains/std.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 2abc67951..96c131f59 100644 --- a/CHANGES +++ b/CHANGES @@ -1,8 +1,8 @@ Release 1.0.6 (in development) ============================== -* #383: Support sorting a limited range of accented characters - in the general index. +* #383, #148: Support sorting a limited range of accented characters + in the general index and the glossary. * #570: Try decoding ``-D`` and ``-A`` command-line arguments with the locale's preferred encoding. diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 0609388ea..0625a4516 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -10,6 +10,7 @@ """ import re +import unicodedata from docutils import nodes from docutils.parsers.rst import directives @@ -250,7 +251,7 @@ class Glossary(Directive): li.insert(0, indexnode) items.append((termtext, li)) if 'sorted' in self.options: - items.sort(key=lambda x: x[0].lower()) + items.sort(key=lambda x: unicodedata.normalize('NFD', x[0].lower())) new_dl.extend(item[1] for item in items) node.children = [new_dl] return [node]