[pypy-svn] r16771 - in pypy/release/0.7.x/pypy/interpreter: . pyparser

arigo at codespeak.net arigo at codespeak.net
Sat Aug 27 16:36:04 CEST 2005


Author: arigo
Date: Sat Aug 27 16:35:53 2005
New Revision: 16771

Modified:
   pypy/release/0.7.x/pypy/interpreter/pycompiler.py
   pypy/release/0.7.x/pypy/interpreter/pyparser/pythonlexer.py
Log:
compile():
* look for the BOM (byte-order marker) for utf-8
* raise ValueError if invalid flags are passed


Modified: pypy/release/0.7.x/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/release/0.7.x/pypy/interpreter/pycompiler.py	(original)
+++ pypy/release/0.7.x/pypy/interpreter/pycompiler.py	Sat Aug 27 16:35:53 2005
@@ -86,11 +86,15 @@
     flag = getattr(__future__, fname).compiler_flag
     compiler_flags |= flag
     compiler_features[fname] = flag
+allowed_flags = compiler_flags | PyCF_DONT_IMPLY_DEDENT
 
-def get_flag_names( flag ):
+def get_flag_names(space, flags):
+    if flags & ~allowed_flags:
+        raise OperationError(space.w_ValueError,
+                             space.wrap("compile(): unrecognized flags"))
     flag_names = []
     for name, value in compiler_features.items():
-        if flag & value:
+        if flags & value:
             flag_names.append( name )
     return flag_names
 
@@ -221,7 +225,7 @@
             transformer = Transformer(filename)
             tree = transformer.compile_node(tuples)
             stablecompiler.misc.set_filename(filename, tree)
-            flag_names = get_flag_names( flags )
+            flag_names = get_flag_names(space, flags)
             if mode == 'exec':
                 codegenerator = ModuleCodeGenerator(tree, flag_names)
             elif mode == 'single':
@@ -317,7 +321,7 @@
             return PythonCompiler.compile_parse_result(self, parse_result,
                                                        filename, mode, flags)
         source_encoding, stack_element = parse_result
-        flag_names = get_flag_names( flags )
+        flag_names = get_flag_names(space, flags)
         w_flag_names = space.newlist( [ space.wrap(n) for n in flag_names ] )
         w_nested_tuples = stack_element.as_w_tuple(space, lineno=True)
         if source_encoding is not None:
@@ -341,7 +345,7 @@
 
     def fakecompile(self, source, filename, mode, flags):
         flags |= __future__.generators.compiler_flag   # always on (2.2 compat)
-        flag_names = get_flag_names(flags)
+        flag_names = get_flag_names(self.space, flags)
         space = self.space
 
         w_flag_names = space.newlist( [ space.wrap(n) for n in flag_names ] )
@@ -410,7 +414,7 @@
         space = self.space
         try:
             astcompiler.misc.set_filename(filename, ast_tree)
-            flag_names = get_flag_names( flags )
+            flag_names = get_flag_names(space, flags)
             if mode == 'exec':
                 codegenerator = ModuleCodeGenerator(space, ast_tree, flag_names)
             elif mode == 'single':
@@ -458,7 +462,7 @@
 
     def compile(self, source, filename, mode, flags):
         flags |= __future__.generators.compiler_flag   # always on (2.2 compat)
-        flag_names = get_flag_names(flags)
+        flag_names = get_flag_names(self.space, flags)
         space = self.space
         return None
 

Modified: pypy/release/0.7.x/pypy/interpreter/pyparser/pythonlexer.py
==============================================================================
--- pypy/release/0.7.x/pypy/interpreter/pyparser/pythonlexer.py	(original)
+++ pypy/release/0.7.x/pypy/interpreter/pyparser/pythonlexer.py	Sat Aug 27 16:35:53 2005
@@ -116,6 +116,13 @@
     # make the annotator happy
     pos = -1
     lines.append('') # XXX HACK probably not needed
+
+    # look for the bom (byte-order marker) for utf-8
+    # XXX encoding support is incomplete at the moment
+    if lines[0].startswith('\xEF\xBB\xBF'):
+        lines[0] = lines[0][3:]
+        encoding = 'utf-8'
+
     # make the annotator happy
     endDFA = automata.DFA([], [])
     # make the annotator happy



More information about the Pypy-commit mailing list