lib: Move decode function to lib.py
decode() is needed by FindCompatibleDts but importing query.py result in an instantiation of the database (query.py line 29). Moving it to lib.py allows to import it for FindCompatibleDts without opening the database. Signed-off-by: Maxime Chretien <maxime.chretien@bootlin.com>
This commit is contained in:
parent
e2adc03d1e
commit
c1abf3d134
3 changed files with 11 additions and 11 deletions
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
import re
|
||||
from urllib import parse
|
||||
from query import decode
|
||||
from lib import decode
|
||||
|
||||
class FindCompatibleDTS:
|
||||
def __init__(self):
|
||||
|
|
@ -50,7 +50,7 @@ class FindCompatibleDTS:
|
|||
|
||||
# Iterate though lines and search for idents
|
||||
for num, line in enumerate(file_lines, 1):
|
||||
line = query.decode(line)
|
||||
line = decode(line)
|
||||
if family == 'C':
|
||||
ret = self.parse_c(line)
|
||||
elif family == 'D':
|
||||
|
|
|
|||
8
lib.py
8
lib.py
|
|
@ -52,6 +52,14 @@ def unescape(bstr):
|
|||
bstr = bstr.replace(a, b)
|
||||
return bstr
|
||||
|
||||
def decode(byte_object):
|
||||
# decode('ascii') fails on special chars
|
||||
# FIXME: major hack until we handle everything as bytestrings
|
||||
try:
|
||||
return byte_object.decode('utf-8')
|
||||
except UnicodeDecodeError:
|
||||
return byte_object.decode('iso-8859-1')
|
||||
|
||||
# List of tokens which we don't want to consider as identifiers
|
||||
# Typically for very frequent variable names and things redefined by #define
|
||||
# TODO: allow to have per project blacklists
|
||||
|
|
|
|||
10
query.py
10
query.py
|
|
@ -18,7 +18,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Elixir. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from lib import script, scriptLines
|
||||
from lib import script, scriptLines, decode
|
||||
import lib
|
||||
import data
|
||||
import os
|
||||
|
|
@ -46,14 +46,6 @@ class SymbolInstance(object):
|
|||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
def decode(byte_object):
|
||||
# decode('ascii') fails on special chars
|
||||
# FIXME: major hack until we handle everything as bytestrings
|
||||
try:
|
||||
return byte_object.decode('utf-8')
|
||||
except UnicodeDecodeError:
|
||||
return byte_object.decode('iso-8859-1')
|
||||
|
||||
def query(cmd, *args):
|
||||
if cmd == 'versions':
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue