From f5fc5d9dacdf7d49d0385bcfd9c0fa91036bf695 Mon Sep 17 00:00:00 2001 From: Johannes King Date: Thu, 18 May 2017 08:19:24 +0200 Subject: [PATCH] fix #134 --- regions/io/ds9/read.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/regions/io/ds9/read.py b/regions/io/ds9/read.py index 9e2fdcc9..0c37fbbf 100644 --- a/regions/io/ds9/read.py +++ b/regions/io/ds9/read.py @@ -228,8 +228,9 @@ def parse_line(self, line): "the known region types.".format(region_type)) return else: - # Found region specification - self.parse_region(include, region_type, line) + # Found region specification, + region_end = region_type_search.span()[1] + self.parse_region(region_type, region_end, line) def _raise_error(self, msg): if self.errors == 'warn': @@ -264,13 +265,13 @@ def parse_meta(meta_str): return result - def parse_region(self, include, region_type, line): + def parse_region(self, region_type, region_end, line): """Extract a Shape from a region string""" if self.coordsys is None: raise DS9RegionParserError("No coordinate system specified and a" " region has been found.") else: - helper = DS9RegionParser(self.coordsys, region_type, + helper = DS9RegionParser(self.coordsys, region_type, region_end, self.global_meta, line) helper.parse() self.shapes.append(helper.shape) @@ -293,10 +294,11 @@ class DS9RegionParser(object): ---------- coordsys : str Coordinate system - include : str {'', '-'} - Flag at the beginning of the line region_type : str Region type + region_end : int + Coordinate of the end of the regions name, this is passed in order to + handle whitespaces correctly global_meta : dict Global meta data line : str @@ -328,10 +330,11 @@ class DS9RegionParser(object): } """DS9 language specification. This defines how a certain region is read""" - def __init__(self, coordsys, region_type, global_meta, line): + def __init__(self, coordsys, region_type, region_end, global_meta, line): self.coordsys = coordsys self.region_type = region_type + self.region_end = region_end self.global_meta = global_meta self.line = line @@ -346,6 +349,7 @@ def __init__(self, coordsys, region_type, global_meta, line): def __str__(self): ss = self.__class__.__name__ ss += '\nLine : {}'.format(self.line) + ss += '\nRegion end : {}'.format(self.region_end) ss += '\nMeta string : {}'.format(self.meta_str) ss += '\nCoord string: {}'.format(self.coord_str) ss += '\nShape: {}'.format(self.shape) @@ -377,12 +381,9 @@ def parse_include(self): def split_line(self): """Split line into coordinates and meta string""" - end_of_region_name = len(self.region_type) - if not self.include: - end_of_region_name += 1 # coordinate of the # symbol or end of the line (-1) if not found hash_or_end = self.line.find("#") - temp = self.line[end_of_region_name:hash_or_end].strip(" |") + temp = self.line[self.region_end:hash_or_end].strip(" |") self.coord_str = regex_paren.sub("", temp) self.meta_str = self.line[hash_or_end:]