mirror of
https://github.com/FreeOpcUa/opcua-asyncio
synced 2025-10-29 17:07:18 +08:00
The method 'to_string' was changed and 'from_string' was created. The function 'string_to_val' was changed to use 'from_string' for LocalizedText.
This commit is contained in:
parent
5b744ed3ed
commit
ffc7d40fb0
|
|
@ -115,7 +115,7 @@ def string_to_val(string, vtype):
|
|||
elif vtype == ua.VariantType.DateTime:
|
||||
val = parser.parse(string)
|
||||
elif vtype == ua.VariantType.LocalizedText:
|
||||
val = ua.LocalizedText(string)
|
||||
val = ua.LocalizedText.from_string(string)
|
||||
elif vtype == ua.VariantType.StatusCode:
|
||||
val = ua.StatusCode(string)
|
||||
elif vtype == ua.VariantType.Guid:
|
||||
|
|
|
|||
|
|
@ -553,10 +553,21 @@ class LocalizedText(FrozenClass):
|
|||
self.Encoding |= (1)
|
||||
|
||||
def to_string(self):
|
||||
# FIXME: use local
|
||||
if self.Text is None:
|
||||
return ""
|
||||
return self.Text
|
||||
if self.Locale is None:
|
||||
return self.Text
|
||||
return self.__str__()
|
||||
|
||||
@staticmethod
|
||||
def from_string(string):
|
||||
m = re.match("^LocalizedText\(Encoding:(.*), Locale:(.*), Text:(.*)\)$", string)
|
||||
if m:
|
||||
text = m.group(3) if m.group(3)!=str(None) else None
|
||||
locale = m.group(2) if m.group(2)!=str(None) else None
|
||||
return LocalizedText(text=text,locale=locale)
|
||||
else:
|
||||
return LocalizedText(string)
|
||||
|
||||
def __str__(self):
|
||||
return f'LocalizedText(Encoding:{self.Encoding}, Locale:{self.Locale}, Text:{self.Text})'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user