From 00f5157f750d5bedb110c20b0d3640aeb9996c3e Mon Sep 17 00:00:00 2001 From: Sagiv Malihi Date: Mon, 12 Aug 2019 11:45:29 +0300 Subject: [PATCH] use built-in tokenize.open to properly read source files with encoding declaration --- pycscope/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pycscope/__init__.py b/pycscope/__init__.py index e0adc90..eac8252 100755 --- a/pycscope/__init__.py +++ b/pycscope/__init__.py @@ -22,7 +22,7 @@ import getopt, sys, os, string, re import keyword, parser, symbol, token - +import tokenize class Mark(object): """ Marks, as defined by Cscope, that are implemented. @@ -222,7 +222,7 @@ def parseFile(basepath, relpath, indexbuff, indexbuff_len, fnamesbuff, dump=Fals # Open the file and get the contents fullpath = os.path.join(basepath, relpath) try: - f = open(fullpath, 'rU') + f = tokenize.open(fullpath) except IOError as e: # Can't open a file, emit message and ignore print("pycscope.py: %s" % e)