From: Robert Bradshaw Date: Wed, 11 Jun 2008 02:21:56 +0000 (-0700) Subject: Module name sanity checking X-Git-Tag: 0.9.8rc1~12 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=490109aeafb20e82d0ad95244c017d0d3d783126;p=cython.git Module name sanity checking --- diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 8d8832ba..aa47543c 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -23,6 +23,8 @@ from Errors import PyrexError, CompileError, error from Symtab import BuiltinScope, ModuleScope from Cython import Utils +module_name_pattern = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$") + # Note: PHASES and TransformSet should be removed soon; but that's for # another day and another commit. PHASES = [ @@ -74,6 +76,9 @@ class Context: module_name, relative_to, pos, need_pxd)) scope = None pxd_pathname = None + if not module_name_pattern.match(module_name): + raise CompileError((path, 0, 0), + "'%s' is not a valid module name" % module_name) if "." not in module_name and relative_to: if debug_find_module: print("...trying relative import")