PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/robot/parsing/txtreader.py

https://code.google.com/p/robotframework/
Python | 34 lines | 15 code | 6 blank | 13 comment | 5 complexity | 7aaced8c3629a22d978ca35600894020 MD5 | raw file
Possible License(s): Apache-2.0
  1. # Copyright 2008-2014 Nokia Solutions and Networks
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import re
  15. from .tsvreader import TsvReader
  16. class TxtReader(TsvReader):
  17. _space_splitter = re.compile(' {2,}')
  18. _pipe_splitter = re.compile(' \|(?= )')
  19. @classmethod
  20. def split_row(cls, row):
  21. if '\t' in row:
  22. row = row.replace('\t', ' ')
  23. if not row.startswith('| '):
  24. return cls._space_splitter.split(row)
  25. row = row[1:-1] if row.endswith(' |') else row[1:]
  26. return [cell.strip() for cell in cls._pipe_splitter.split(row)]
  27. def _process_cell(self, cell):
  28. return cell