Skip to content
Snippets Groups Projects
Commit 0f535a62 authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

Merge branch 'fix_py2_issue_in_htc' into 'master'

if python2...

See merge request toolbox/WindEnergyToolbox!46
parents 081c14ae fb25d7e2
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,7 @@ class HTCContents(object): ...@@ -48,6 +48,7 @@ class HTCContents(object):
lines = [] lines = []
contents = None contents = None
name_ = "" name_ = ""
parent=None
def __setitem__(self, key, value): def __setitem__(self, key, value):
if isinstance(key, str): if isinstance(key, str):
...@@ -56,6 +57,7 @@ class HTCContents(object): ...@@ -56,6 +57,7 @@ class HTCContents(object):
self.values[key] = value self.values[key] = value
else: else:
raise NotImplementedError raise NotImplementedError
value.parent=self
def __getitem__(self, key): def __getitem__(self, key):
...@@ -72,6 +74,9 @@ class HTCContents(object): ...@@ -72,6 +74,9 @@ class HTCContents(object):
return self.values[key] return self.values[key]
def __getattr__(self, *args, **kwargs): def __getattr__(self, *args, **kwargs):
if args[0] in ['__members__','__methods__']:
# fix python2 related issue. In py2, dir(self) calls __getattr__(('__members__',)), and this call must fail unhandled to work
return object.__getattribute__(self, *args, **kwargs)
try: try:
return object.__getattribute__(self, *args, **kwargs) return object.__getattribute__(self, *args, **kwargs)
except: except:
...@@ -135,7 +140,11 @@ class HTCContents(object): ...@@ -135,7 +140,11 @@ class HTCContents(object):
self._add_contents(line) self._add_contents(line)
return line return line
def location(self):
if self.parent is None:
return os.path.basename(self.filename)
else:
return self.parent.location() + "/" + self.name_
class HTCSection(HTCContents): class HTCSection(HTCContents):
...@@ -209,7 +218,10 @@ class HTCLine(HTCContents): ...@@ -209,7 +218,10 @@ class HTCLine(HTCContents):
return " ".join([str(v).lower() for v in self.values]) return " ".join([str(v).lower() for v in self.values])
def __getitem__(self, key): def __getitem__(self, key):
return self.values[key] try:
return self.values[key]
except:
raise IndexError("Parameter %s does not exists for %s"%(key+1,self.location()))
@staticmethod @staticmethod
def from_lines(lines): def from_lines(lines):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment