Skip to content

Commit 6ce8254

Browse files
AndreasHeineoroulet
authored andcommitted
fix missing arg in __init__ from localizedtext
#1171
1 parent 278a2b3 commit 6ce8254

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

opcua/ua/uatypes.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,17 +513,23 @@ class LocalizedText(FrozenClass):
513513
('Locale', 'String'),
514514
('Text', 'String'), )
515515

516-
def __init__(self, text=None):
516+
def __init__(self, text=None, locale=None):
517517
self.Encoding = 0
518518
self._text = None
519+
self._locale = None
519520
if text:
520521
self.Text = text
521-
self.Locale = None
522+
if locale:
523+
self.Locale = locale
522524
self._freeze = True
523525

524526
@property
525527
def Text(self):
526528
return self._text
529+
530+
@property
531+
def Locale(self):
532+
return self._locale
527533

528534
@Text.setter
529535
def Text(self, text):
@@ -536,12 +542,31 @@ def Text(self, text):
536542
self._text = text
537543
if self._text:
538544
self.Encoding |= (1 << 1)
545+
546+
@Locale.setter
547+
def Locale(self, locale):
548+
if not isinstance(locale, str):
549+
raise ValueError("A LocalizedText object takes a string as argument, not a {}, {}".format({type(locale)}, {locale}))
550+
self._locale = locale
551+
if self._locale:
552+
self.Encoding |= (1)
539553

540554
def to_string(self):
541-
# FIXME: use local
542555
if self.Text is None:
543556
return ""
544-
return self.Text
557+
if self.Locale is None:
558+
return self.Text
559+
return self.__str__()
560+
561+
@staticmethod
562+
def from_string(string):
563+
m = re.match(r"^LocalizedText\(Encoding:(.*), Locale:(.*), Text:(.*)\)$", string)
564+
if m:
565+
text = m.group(3) if m.group(3) != str(None) else None
566+
locale = m.group(2) if m.group(2) != str(None) else None
567+
return LocalizedText(text=text, locale=locale)
568+
else:
569+
return LocalizedText(string)
545570

546571
def __str__(self):
547572
return 'LocalizedText(' + 'Encoding:' + str(self.Encoding) + ', ' + \

0 commit comments

Comments
 (0)