Browse Source

Catch ClassNotFound error in parser __init__.py

tags/v1.0^2
Benjamin Attal 10 years ago
parent
commit
4cc0626a71
1 changed files with 13 additions and 3 deletions
  1. +13
    -3
      bitshift/parser/__init__.py

+ 13
- 3
bitshift/parser/__init__.py View File

@@ -4,6 +4,9 @@ from .python import parse_py


_all__ = ["parse"] _all__ = ["parse"]


class UnsupportedFileError(Exception):
pass

def _lang(codelet): def _lang(codelet):
""" """
Private function to identify the language of a codelet. Private function to identify the language of a codelet.
@@ -16,10 +19,13 @@ def _lang(codelet):
Modify function to incorporate tags from stackoverflow. Modify function to incorporate tags from stackoverflow.
""" """


if codelet.filename is not None:
return pgl.guess_lexer_for_filename(codelet.filename).name
try:
if codelet.filename is not None:
return pgl.guess_lexer_for_filename(codelet.filename, '').name


return LANGS.index(pgl.guess_lexer(codelet.code))
return LANGS.index(pgl.guess_lexer(codelet.code))
except:
raise UnsupportedFileError('Could not find a lexer for the codelet\'s filename')


def _recv_data(server_socket): def _recv_data(server_socket):
""" """
@@ -61,6 +67,9 @@ def _recv_data(server_socket):
def parse(codelet): def parse(codelet):
""" """
Dispatches the codelet to the correct parser based on its language. Dispatches the codelet to the correct parser based on its language.
It is the job of the respective parsers to accumulate data about the
code and to convert it into a string representing a python dict.
The codelet is then given dict as its 'symbols' field.


:param codelet: The codelet object to parsed. :param codelet: The codelet object to parsed.


@@ -68,6 +77,7 @@ def parse(codelet):
""" """


lang = _lang(codelet); source = codelet.code lang = _lang(codelet); source = codelet.code
codelet.language = lang
server_socket_number = 5000 + lang server_socket_number = 5000 + lang


if lang == LANGS.index('Python'): if lang == LANGS.index('Python'):


Loading…
Cancel
Save