MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / LocalizedText

Class LocalizedText

opcua/ua/uatypes.py:501–584  ·  view source on GitHub ↗

A string qualified with a namespace index.

Source from the content-addressed store, hash-verified

499
500
501class LocalizedText(FrozenClass):
502 """
503 A string qualified with a namespace index.
504 """
505
506 ua_switches = {
507 'Locale': ('Encoding', 0),
508 'Text': ('Encoding', 1),
509 }
510
511 ua_types = (
512 ('Encoding', 'Byte'),
513 ('Locale', 'String'),
514 ('Text', 'String'), )
515
516 def __init__(self, text=None, locale=None):
517 self.Encoding = 0
518 self._text = None
519 self._locale = None
520 if text:
521 self.Text = text
522 if locale:
523 self.Locale = locale
524 self._freeze = True
525
526 @property
527 def Text(self):
528 return self._text
529
530 @property
531 def Locale(self):
532 return self._locale
533
534 @Text.setter
535 def Text(self, text):
536 if isinstance(text, str):
537 pass
538 elif isinstance(text, bytes):
539 text = text.decode()
540 else:
541 raise ValueError("A LocalizedText object takes a string as argument, not a {}, {}".format(type(text), text))
542 self._text = text
543 if self._text:
544 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)
553
554 def to_string(self):
555 if self.Text is None:
556 return ""
557 if self.Locale is None:
558 return self.Text

Calls

no outgoing calls

Tested by

no test coverage detected