To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit d3e822d9 authored by Tobias Pape's avatar Tobias Pape Committed by Stefan Marr
Browse files

make the file and string stream type-compatible

parent 17795b45
import os
from rpython.rlib.streamio import open_file_as_stream
from StringIO import StringIO
from rpython.rlib.streamio import open_file_as_stream, Stream, StreamError
from som.compiler.parser import Parser
from som.compiler.class_generation_context import ClassGenerationContext
class _StringStream(Stream):
def __init__(self, string):
self._string = string
self.pos = 0
self.max = len(string) - 1
def write(self, data):
raise StreamError("StringStream is not writable")
def truncate(self, size):
raise StreamError("StringStream is immutable")
def peek(self):
if self.pos < self.max:
return self._string[self.pos:]
return ''
def tell(self):
return self.pos
def seek(self, offset, whence):
if whence == 0:
self.pos = max(0, offset)
elif whence == 1:
self.pos = max(0, self.pos + offset)
elif whence == 2:
self.pos = max(0, self.max + offset)
raise StreamError("seek(): whence must be 0, 1 or 2")
def read(self, n):
assert isinstance(n, int)
end = self.pos + n
data = self._string[self.pos:end]
self.pos += len(data)
return data
def compile_class_from_file(path, filename, system_class, universe):
return _SourcecodeCompiler().compile(path, filename, system_class, universe)
......@@ -40,7 +76,7 @@ class _SourcecodeCompiler(object):
return result
def compile_class_string(self, stream, system_class, universe):
self._parser = Parser(StringIO(stream), universe)
self._parser = Parser(_StringStream(stream), universe)
result = self._compile(system_class, universe)
return result
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment