Пример #1
0
 def parse(self, input):
     """Parses the given file or file source string."""
     if hasattr(input, 'name'):
         self.filename = input.name
     elif not getattr(self, 'filename', ''):
         self.filename = ''
     if isinstance(input, bytes):
         input = BytesIO(input)
     # clear units to get rid of automatically generated headers before parsing
     self.units = []
     poparser.parse_units(poparser.ParseState(input, pounit), self)
Пример #2
0
 def parse(self, input):
     """Parses the given file or file source string."""
     if hasattr(input, 'name'):
         self.filename = input.name
     elif not getattr(self, 'filename', ''):
         self.filename = ''
     if isinstance(input, bytes):
         input = BytesIO(input)
     # clear units to get rid of automatically generated headers before parsing
     self.units = []
     poparser.parse_units(poparser.ParseState(input, pounit), self)
Пример #3
0
 def parse(self, input):
     """Parses the given file or file source string."""
     if hasattr(input, "name"):
         self.filename = input.name
     elif not getattr(self, "filename", ""):
         self.filename = ""
     if not isinstance(input, bytes):
         input = input.read()
     lines, self.newline = splitlines(input)
     # clear units to get rid of automatically generated headers before parsing
     self.units = []
     poparser.parse_units(
         poparser.ParseState(iter(lines), self.create_unit), self)
Пример #4
0
 def parse(self, input):
     """Parses the given file or file source string."""
     try:
         if hasattr(input, 'name'):
             self.filename = input.name
         elif not getattr(self, 'filename', ''):
             self.filename = ''
         if isinstance(input, str):
             input = cStringIO.StringIO(input)
         # clear units to get rid of automatically generated headers before parsing
         self.units = []
         poparser.parse_units(poparser.ParseState(input, pounit), self)
     except Exception, e:
         raise base.ParseError(e)
Пример #5
0
 def parse(self, input):
     """Parses the given file or file source string."""
     try:
         if hasattr(input, 'name'):
             self.filename = input.name
         elif not getattr(self, 'filename', ''):
             self.filename = ''
         if isinstance(input, str):
             input = cStringIO.StringIO(input)
         # clear units to get rid of automatically generated headers before parsing
         self.units = []
         poparser.parse_units(poparser.ParseState(input, pounit), self)
     except Exception, e:
         raise base.ParseError(e)
Пример #6
0
    def parse(self, input, duplicatestyle="merge"):
        """Parses the given file or file source string."""
        if hasattr(input, 'name'):
            self.filename = input.name
        elif not getattr(self, 'filename', ''):
            self.filename = ''
        if isinstance(input, bytes):
            input = BytesIO(input)
        # clear units to get rid of automatically generated headers before parsing
        self.units = []
        poparser.parse_units(poparser.ParseState(input, pounit), self)

        # duplicates are now removed by default unless duplicatestyle=allow
        if duplicatestyle != "allow":
            self.removeduplicates(duplicatestyle=duplicatestyle)
Пример #7
0
    def parse(self, inputfile):
        """Parses the given file or file source string."""
        if True:
#        try:
            if hasattr(inputfile, 'name'):
                self.filename = inputfile.name
            elif hasattr(inputfile, 'filename'):
                self.filename = inputfile.filename
            else:
                self.filename = ''
            # TODO: only a turnaround fix
            if isinstance(inputfile, bytes):
                inputfile=inputfile.decode('utf-8')
            if isinstance(inputfile, str):
                inputfile = io.StringIO(inputfile)
            # clear units to get rid of automatically generated headers before parsing
            self.units = []
            poparser.parse_units(poparser.ParseState(inputfile, pounit), self)