Commit c7ba7c06 authored by oroulet's avatar oroulet

pylint over client code

parent 62679938
......@@ -3,16 +3,14 @@ http://freeopcua.github.io/, https://github.com/FreeOpcUa/opcua-asyncio
[![Build Status](https://travis-ci.org/FreeOpcUa/opcua-asyncio.svg?branch=master)](https://travis-ci.org/FreeOpcUa/opcua-asyncio)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/FreeOpcUa/opcua-asyncio/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/FreeOpcUa/opcua-asyncio/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/FreeOpcUa/opcua-asyncio/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/FreeOpcUa/opcua-asyncio/?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/grade/f7f9a138ee7c4541b3b794b86e61e929)](https://www.codacy.com/app/olivier-roulet/opcua-asyncio)
[![Code Climate](https://codeclimate.com/github/FreeOpcUa/opcua-asyncio/badges/gpa.svg)](https://codeclimate.com/github/FreeOpcUa/opcua-asyncio)
[![PyPI Oackage](https://badge.fury.io/py/freeopcua.svg)](https://badge.fury.io/py/freeopcua)
[![PyPI Package](https://badge.fury.io/py/freeopcua.svg)](https://badge.fury.io/py/freeopcua)
# opcua-asyncio
This repository is a fork of [python-opcua](https://github.com/FreeOpcUa/python-opcua) to rebase it completely on asyncio and drop support for Python < 3.6.
Please note that opcua-asyncio is still in development and should be treated as an alpha release.
There is also a draft of sync wrapper over async API which may replace python-opcua in the future in asyncua/sync.py
## Motivation
......
from .client import *
__all__ = client.__all__
......@@ -14,7 +14,7 @@ _logger = logging.getLogger(__name__)
asyncio.get_event_loop().set_debug(True)
class Client(object):
class Client:
"""
High level client to connect to an OPC-UA server.
......@@ -93,8 +93,8 @@ class Client(object):
Set user password for the connection.
initial password from the URL will be overwritten
"""
if type(pwd) is not str:
raise TypeError("Password must be a string, got %s", type(pwd))
if not isinstance(pwd, str):
raise TypeError(f"Password must be a string, got {pwd} of type {type(pwd)}")
self._password = pwd
async def set_security_string(self, string: str):
......@@ -280,8 +280,7 @@ class Client(object):
params.Server = serv
params.DiscoveryConfiguration = discovery_configuration
return await self.uaclient.register_server2(params)
else:
return await self.uaclient.register_server(serv)
return await self.uaclient.register_server(serv)
async def find_servers(self, uris=None):
"""
......@@ -379,11 +378,11 @@ class Client(object):
if policy.TokenType == token_type:
if policy.SecurityPolicyUri:
return policy.SecurityPolicyUri
else: # empty URI means "use this endpoint's policy URI"
return self.security_policy.URI
# empty URI means "use this endpoint's policy URI"
return self.security_policy.URI
return self.security_policy.URI
async def activate_session(self, username: str=None, password: str=None, certificate=None):
async def activate_session(self, username: str = None, password: str = None, certificate=None):
"""
Activate session using either username and password or private_key
"""
......
......@@ -85,7 +85,7 @@ class UASocketProtocol(asyncio.Protocol):
self.logger.fatal("Received an error: %r", msg)
self._call_callback(0, ua.UaStatusCodeError(msg.Error.value))
else:
raise ua.UaError("Unsupported message type: %s", msg)
raise ua.UaError(f"Unsupported message type: {msg}")
def _send_request(self, request, callback=None, timeout=1000, message_type=ua.MessageType.SecureMessage):
"""
......@@ -183,7 +183,6 @@ class UASocketProtocol(asyncio.Protocol):
self._connection.set_channel(response.Parameters)
return response.Parameters
async def close_secure_channel(self):
"""
Close secure channel.
......@@ -231,14 +230,12 @@ class UaClient:
async def connect_socket(self, host: str, port: int):
"""Connect to server socket."""
self.logger.info("opening connection")
# nodelay ncessary to avoid packing in one frame, some servers do not like it
# ToDo: TCP_NODELAY is set by default, but only since 3.6
await self.loop.create_connection(self._make_protocol, host, port)
def disconnect_socket(self):
if self.protocol and self.protocol.state == UASocketProtocol.CLOSED:
self.logger.warning("disconnect_socket was called but connection is closed")
return
return None
return self.protocol.disconnect_socket()
async def send_hello(self, url, max_messagesize=0, max_chunkcount=0):
......@@ -448,7 +445,9 @@ class UaClient:
def _sub_data_received(self, future):
data = future.result()
self.loop.create_task(self._call_publish_callback(data))
"""
# to avoid fire and forget of task we could use a loop:
def _sub_data_received(self, future):
data = future.result()
self.loop.create_task(self._enqueue_sub_data(data))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment