summaryrefslogtreecommitdiff
path: root/sphinx/pycode
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-05-15 13:52:48 +0200
committerGeorg Brandl <georg@python.org>2011-05-15 13:52:48 +0200
commitfd2c55eaea41cfb0db941c7d0538215306f1da9a (patch)
treee930a63eeab723b56cb4a281cf219602010299df /sphinx/pycode
parent88a4dce9a45b76d990e2768de69eb465a5f216f7 (diff)
parentba9d023acf4361093666eaf1aa6e78b0ab41a891 (diff)
downloadsphinx-fd2c55eaea41cfb0db941c7d0538215306f1da9a.tar.gz
merge with 1.0
Diffstat (limited to 'sphinx/pycode')
-rw-r--r--sphinx/pycode/__init__.py16
1 files changed, 2 insertions, 14 deletions
diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py
index e15e42bf..bf51e740 100644
--- a/sphinx/pycode/__init__.py
+++ b/sphinx/pycode/__init__.py
@@ -17,7 +17,7 @@ from cStringIO import StringIO
from sphinx.errors import PycodeError
from sphinx.pycode import nodes
from sphinx.pycode.pgen2 import driver, token, tokenize, parse, literals
-from sphinx.util import get_module_source
+from sphinx.util import get_module_source, detect_encoding
from sphinx.util.pycompat import next
from sphinx.util.docstrings import prepare_docstring, prepare_commentdoc
@@ -38,10 +38,6 @@ for k, v in token.tok_name.iteritems():
number2name = pygrammar.number2symbol.copy()
number2name.update(token.tok_name)
-
-# a regex to recognize coding cookies
-_coding_re = re.compile(r'coding[:=]\s*([-\w.]+)')
-
_eq = nodes.Leaf(token.EQUAL, '=')
@@ -217,11 +213,10 @@ class ModuleAnalyzer(object):
self.srcname = srcname
# file-like object yielding source lines
self.source = source
- # will be changed when found by parse()
- self.encoding = sys.getdefaultencoding()
# cache the source code as well
pos = self.source.tell()
+ self.encoding = detect_encoding(self.source.readline)
self.code = self.source.read()
self.source.seek(pos)
@@ -251,13 +246,6 @@ class ModuleAnalyzer(object):
self.parsetree = pydriver.parse_tokens(self.tokens)
except parse.ParseError, err:
raise PycodeError('parsing failed', err)
- # find the source code encoding, if present
- comments = self.parsetree.get_prefix()
- for line in comments.splitlines()[:2]:
- match = _coding_re.search(line)
- if match is not None:
- self.encoding = match.group(1)
- break
def find_attr_docs(self, scope=''):
"""Find class and module-level attributes and their documentation."""