Example #1
0
    def __init__(self, url, timeout=1):
        """
        used url argument to connect to server.
        if you are unsure of url, write at least hostname and port
        and call get_endpoints
        timeout is the timeout to get an answer for requests to server
        public member of this call are available to be set by API users

        """
        self.logger = logging.getLogger(__name__)
        self.server_url = urlparse(url)
        self.name = "Pure Python Client"
        self.description = self.name
        self.application_uri = "urn:freeopcua:client"
        self.product_uri = "urn:freeopcua.github.no:client"
        self.security_policy = ua.SecurityPolicy()
        self.secure_channel_id = None
        self.default_timeout = 3600000
        self.secure_channel_timeout = self.default_timeout
        self.session_timeout = self.default_timeout
        self._policy_ids = []
        self.bclient = BinaryClient(timeout)
        self.user_certificate = None
        self.user_private_key = None
        self._session_counter = 1
        self.keepalive = None
Example #2
0
 def __init__(self, timeout=1):
     self.logger = logging.getLogger(__name__)
     # _publishcallbacks should be accessed in recv thread only
     self._publishcallbacks = {}
     self._timeout = timeout
     self._uasocket = None
     self._security_policy = ua.SecurityPolicy()
Example #3
0
    def __init__(self, url, timeout=4):
        """

        :param url: url of the server.
            if you are unsure of url, write at least hostname
            and port and call get_endpoints

        :param timeout:
            Each request sent to the server expects an answer within this
            time. The timeout is specified in seconds.
        """
        self.logger = logging.getLogger(__name__)
        self.server_url = urlparse(url)
        # take initial username and password from the url
        self._username = self.server_url.username
        self._password = self.server_url.password
        self.name = "Pure Python Client"
        self.description = self.name
        self.application_uri = "urn:freeopcua:client"
        self.product_uri = "urn:freeopcua.github.io:client"
        self.security_policy = ua.SecurityPolicy()
        self.secure_channel_id = None
        self.secure_channel_timeout = 3600000  # 1 hour
        self.session_timeout = 3600000  # 1 hour
        self._policy_ids = []
        self.uaclient = UaClient(timeout)
        self.user_certificate = None
        self.user_private_key = None
        self._server_nonce = None
        self._session_counter = 1
        self.keepalive = None
        self.nodes = Shortcuts(self.uaclient)
        self.max_messagesize = 0  # No limits
        self.max_chunkcount = 0  # No limits
Example #4
0
 def __init__(self, internal_server, socket):
     self.logger = logging.getLogger(__name__)
     self.iserver = internal_server
     self.name = socket.get_extra_info('peername')
     self.sockname = socket.get_extra_info('sockname')
     self.session = None
     self.channel = None
     self.socket = socket
     self._socketlock = Lock()
     self._datalock = Lock()
     self._publishdata_queue = []
     self._connection = ua.SecureConnection(ua.SecurityPolicy())
Example #5
0
 def __init__(self, timeout=1, security_policy=ua.SecurityPolicy()):
     self.logger = logging.getLogger(__name__ + ".Socket")
     self._thread = None
     self._lock = Lock()
     self.timeout = timeout
     self._socket = None
     self._do_stop = False
     self.authentication_token = ua.NodeId()
     self._request_id = 0
     self._request_handle = 0
     self._callbackmap = {}
     self._connection = ua.SecureConnection(security_policy)
Example #6
0
 def __init__(self, internal_server, socket):
     self.logger = logging.getLogger(__name__)
     self.iserver = internal_server
     self.name = socket.get_extra_info('peername')
     self.sockname = socket.get_extra_info('sockname')
     self.session = None
     self.socket = socket
     self._socketlock = Lock()
     self._datalock = RLock()
     self._publishdata_queue = []
     self._publish_result_queue = []  # used when we need to wait for PublishRequest
     self._connection = SecureConnection(ua.SecurityPolicy())
Example #7
0
def parse_args(parser, requirenodeid=False):
    args = parser.parse_args()
    logging.basicConfig(format="%(levelname)s: %(message)s", level=getattr(logging, args.loglevel))
    if args.url and '://' not in args.url:
        logging.info("Adding default scheme %s to URL %s", ua.OPC_TCP_SCHEME, args.url)
        args.url = ua.OPC_TCP_SCHEME + '://' + args.url
    if hasattr(args, 'security'):
        if args.security:
            args.security = client_security(args.security, args.url, args.timeout)
        else:
            args.security = ua.SecurityPolicy()
    if requirenodeid:
        _require_nodeid(parser, args)
    return args
Example #8
0
 def __init__(self, internal_server, socket):
     self.logger = logging.getLogger(__name__)
     self.iserver = internal_server
     self.name = socket.get_extra_info('peername')
     self.sockname = socket.get_extra_info('sockname')
     self.session = None
     self.channel = None
     self.socket = socket
     self._socketlock = Lock()
     self._datalock = Lock()
     self._publishdata_queue = []
     self._seq_number = 0
     self._security_policy = ua.SecurityPolicy()
     self._max_chunk_size = 65536
Example #9
0
    def test_message_chunk(self):
        pol = ua.SecurityPolicy()
        chunks = ua.MessageChunk.message_to_chunks(pol, b'123', 65536)
        self.assertEqual(len(chunks), 1)
        seq = 0
        for chunk in chunks:
            seq += 1
            chunk.SequenceHeader.SequenceNumber = seq
        chunk2 = ua.MessageChunk.from_binary(pol, ua.utils.Buffer(chunks[0].to_binary()))
        self.assertEqual(chunks[0].to_binary(), chunk2.to_binary())

        # for policy None, MessageChunk overhead is 12+4+8 = 24 bytes
        # Let's pack 11 bytes into 28-byte chunks. The message must be split as 4+4+3
        chunks = ua.MessageChunk.message_to_chunks(pol, b'12345678901', 28)
        self.assertEqual(len(chunks), 3)
        self.assertEqual(chunks[0].Body, b'1234')
        self.assertEqual(chunks[1].Body, b'5678')
        self.assertEqual(chunks[2].Body, b'901')
        for chunk in chunks:
            seq += 1
            chunk.SequenceHeader.SequenceNumber = seq
            self.assertTrue(len(chunk.to_binary()) <= 28)
 def __init__(self):
     super().__init__(timeout=1, security_policy=ua.SecurityPolicy())