Skip to content

Commit

Permalink
Merge pull request #5 from efef/master
Browse files Browse the repository at this point in the history
Fixed the mypy issues
  • Loading branch information
wjhpeters authored Sep 18, 2019
2 parents dc6863d + d07c276 commit 7aa3edc
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ deploy:
on:
tags: true
distributions: sdist bdist_wheel
repo: wjhpeters/issue-185-EduVPN
repo: wjhpeters/tmp
notifications:
email:
on_fail: always
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ You can find the documentation on [http://python-eduvpn-client.readthedocs.io](h
Development
===========

[![Build Status](https://travis-ci.org/wjhpeters/issue-185-EduVPN.svg?branch=master)](https://travis-ci.org/wjhpeters/issue-185-EduVPN)
[![Build Status](https://travis-ci.org/wjhpeters/tmp.svg?branch=master)](https://travis-ci.org/wjhpeters/tmp)
49 changes: 24 additions & 25 deletions eduvpn/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
logger = logging.getLogger(__name__)


def insert_config(settings): # type: (dict) -> NetworkManager.connection
def insert_config(settings): # type: (dict) -> Any
"""
Add a configuration to the networkmanager
Expand All @@ -38,7 +38,7 @@ def insert_config(settings): # type: (dict) -> NetworkManager.connection
name = settings['connection']['id']
logger.info("generating or updating OpenVPN"
"configuration with name {}".format(name))
connection = NetworkManager.Settings.AddConnection(settings)
connection = NetworkManager.Settings.AddConnection(settings) # type: ignore
return connection


Expand All @@ -62,7 +62,7 @@ def list_providers(): # type: () -> Iterable[Metadata]
except IOError as e:
logger.error("cant open {}: {}".format(p, e))
else:
all_ = NetworkManager.Settings.ListConnections()
all_ = NetworkManager.Settings.ListConnections() # type: ignore
vpn_connections = ([c.GetSettings()['connection'] for c in all_
if c.GetSettings()['connection']['type'] == 'vpn'])
logger.info("There are {} VPN connections in"
Expand All @@ -87,7 +87,7 @@ def store_provider(meta, config_dict): # type: (Metadata, dict) -> str
nm_config['vpn']['data'].update({'cert': cert_path, 'key': key_path})

if new:
insert_config(nm_config)
insert_config(nm_config) # type: ignore
else:
update_config_provider(meta, config_dict)

Expand All @@ -114,7 +114,7 @@ def delete_provider(uuid): # type: (str) -> None

logger.info("deleting profile with uuid {}"
"using NetworkManager".format(uuid))
all_connections = NetworkManager.Settings.ListConnections()
all_connections = NetworkManager.Settings.ListConnections() # type: ignore
conns = [c for c in all_connections
if c.GetSettings()['connection']['uuid'] == uuid]
if len(conns) != 1:
Expand Down Expand Up @@ -142,7 +142,7 @@ def delete_provider(uuid): # type: (str) -> None
raise


def connect_provider(uuid): # type: (str) -> None
def connect_provider(uuid): # type: (str) -> Any
"""
Enable the network manager configuration by its UUID
Expand All @@ -155,10 +155,9 @@ def connect_provider(uuid): # type: (str) -> None
raise EduvpnException("No DBus daemon running")

try:
connection = NetworkManager.Settings.GetConnectionByUuid(uuid)
return NetworkManager.NetworkManager.ActivateConnection(connection,
"/", "/")
except DBusException as e:
connection = NetworkManager.Settings.GetConnectionByUuid(uuid) # type: ignore
return NetworkManager.ActivateConnection(connection, "/", "/") # type: ignore
except DBusException as e: # type: ignore
raise EduvpnException(e)


Expand All @@ -174,10 +173,10 @@ def list_active(): # type: () -> list
return []

try:
active = NetworkManager.NetworkManager.ActiveConnections
return [a for a in active if NetworkManager.Settings.
GetConnectionByUuid(a.Uuid).GetSettings()
['connection']['type'] == 'vpn']
active = NetworkManager.ActiveConnections # type: ignore
return [a for a in active if NetworkManager.Settings. # type: ignore
GetConnectionByUuid(a.Uuid).GetSettings() # type: ignore
['connection']['type'] == 'vpn'] # type: ignore
except DBusException:
return []

Expand All @@ -189,10 +188,10 @@ def disconnect_all(): # type: () -> Any
if not have_dbus():
return []

for active in NetworkManager.NetworkManager.ActiveConnections:
conn = NetworkManager.Settings.GetConnectionByUuid(active.Uuid)
if conn.GetSettings()['connection']['type'] == 'vpn':
disconnect_provider(active.Uuid)
for active in NetworkManager.ActiveConnections: # type: ignore
conn = NetworkManager.Settings.GetConnectionByUuid(active.Uuid) # type: ignore
if conn.GetSettings()['connection']['type'] == 'vpn': # type: ignore
disconnect_provider(active.Uuid) # type: ignore


def disconnect_provider(uuid): # type: (str) -> None
Expand All @@ -207,13 +206,13 @@ def disconnect_provider(uuid): # type: (str) -> None
if not have_dbus():
raise EduvpnException("No DBus daemon running")

conns = [i for i in NetworkManager.NetworkManager.ActiveConnections
conns = [i for i in NetworkManager.ActiveConnections # type: ignore
if i.Uuid == uuid]
if len(conns) == 0:
if len(conns) == 0: # type: ignore
raise EduvpnException("no active connection found"
"with uuid {}".format(uuid))
for conn in conns:
NetworkManager.NetworkManager.DeactivateConnection(conn)
NetworkManager.NetworkManager.DeactivateConnection(conn) # type: ignore


def is_provider_connected(uuid): # type: (str) -> Any
Expand Down Expand Up @@ -248,10 +247,10 @@ def update_config_provider(meta, config_dict): # type: (Metadata, dict) -> None
username=meta.username)

if have_dbus():
connection = NetworkManager.Settings.GetConnectionByUuid(meta.uuid)
connection = NetworkManager.Settings.GetConnectionByUuid(meta.uuid) # type: ignore
old_settings = connection.GetSettings()
nm_config['vpn']['data'].update({'cert': (old_settings['vpn']['data']['cert']),
'key': (old_settings['vpn']['data']['key'])})
'key': (old_settings['vpn']['data']['key'])}) # type: ignore
connection.Update(nm_config)


Expand Down Expand Up @@ -298,5 +297,5 @@ def monitor_vpn(uuid, callback): # type: (str, Any) -> None
if not have_dbus():
return

connection = NetworkManager.Settings.GetConnectionByUuid(uuid)
connection.connect_to_signal('Updated', callback)
connection = NetworkManager.Settings.GetConnectionByUuid(uuid) # type: ignore
connection.connect_to_signal('Updated', callback) # type: ignore
4 changes: 2 additions & 2 deletions eduvpn/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def do_GET(self):
if not hasattr(httpd, "path"):
raise Exception("Invalid response received")

parsed = urlparse(httpd.path)
logger.info("received a request {}".format(httpd.path))
parsed = urlparse(httpd.path) # type: ignore
logger.info("received a request {}".format(httpd.path)) # type: ignore
return parse_qs(parsed.query)


Expand Down
2 changes: 2 additions & 0 deletions eduvpn/other_nm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# This code has been taken from https://github.com/seveas/python-networkmanager and modified slightly.
# This way we have the same version on all platforms and we can solve some small issues.

# type: ignore

import copy
import dbus
import dbus.service
Expand Down
2 changes: 1 addition & 1 deletion eduvpn/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_instance_info(instance_uri, verifier=None): # type: (str, VerifyKey) ->
if info_sig.status_code == 404:
logger.warning("can't verify signature for {} since there is no signature.".format(info_uri))
else:
_ = verifier.verify(smessage=info.content, signature=info_sig.content.decode('base64'))
_ = verifier.verify(smessage=info.content, signature=info_sig.content.decode('base64')) # type: ignore
urls = info.json()['api']['http://eduvpn.org/api#2']
return urls["api_base_uri"], urls["authorization_endpoint"], urls["token_endpoint"]

Expand Down
6 changes: 3 additions & 3 deletions eduvpn/steps/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _phase1_background(meta, dialog, verifier, builder, force_token_refresh, let
try:
logger.info("starting token obtaining in background")
r = get_instance_info(instance_uri=meta.instance_base_uri, verifier=verifier)
meta.api_base_uri, meta.authorization_endpoint, meta.token_endpoint = r
meta.api_base_uri, meta.authorization_endpoint, meta.token_endpoint = r # type: ignore
except Exception as e:
error = e
GLib.idle_add(lambda: error_helper(dialog, "Can't fetch instance info", "{}".format(str(error))))
Expand All @@ -58,7 +58,7 @@ def _phase1_background(meta, dialog, verifier, builder, force_token_refresh, let
port = get_open_port()
try:
oauth = create_oauth_session(port, lets_connect=lets_connect, auto_refresh_url=meta.token_endpoint)
auth_url, state = get_auth_url(oauth, code_verifier, meta.authorization_endpoint)
auth_url, state = get_auth_url(oauth, code_verifier, meta.authorization_endpoint) # type: ignore
except Exception as e:
error = e
GLib.idle_add(lambda: error_helper(dialog, "Can't create oauth session", "{}".format(str(error))))
Expand Down Expand Up @@ -129,7 +129,7 @@ def _phase2_background(meta, port, oauth, code_verifier, auth_url, dialog, build
GLib.idle_add(lambda: error_helper(dialog, "Can't obtain token", "{}".format(error)))
GLib.idle_add(lambda: dialog.hide())
else:
logging.error(error)
logging.error(error) # type: ignore
raise
else:
GLib.idle_add(lambda: _phase2_callback(meta=meta, oauth=oauth, dialog=dialog, builder=builder,
Expand Down
6 changes: 3 additions & 3 deletions eduvpn/steps/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def select_instance_step(meta,
instances,
builder,
verifier,
lets_connect): # type: (Metadata, str, Gtk.builder, str, bool) -> None
lets_connect): # type: (Metadata, List[Tuple[str, str, Optional[bytes]]], Gtk.builder, str, bool) -> None
"""prompt user with instance dialog"""
logger.info("presenting instances to user")
dialog = builder.get_object('instances-dialog')
Expand All @@ -64,8 +64,8 @@ def select_instance_step(meta,
dialog.show_all()

for display_name, url, icon_data in instances:
icon = bytes2pixbuf(icon_data)
model.append((display_name, url, icon, base64.b64encode(icon_data).decode('ascii')))
icon = bytes2pixbuf(icon_data) # type: ignore
model.append((display_name, url, icon, base64.b64encode(icon_data).decode('ascii'))) # type: ignore

response = dialog.run()
dialog.hide()
Expand Down
2 changes: 1 addition & 1 deletion eduvpn/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def thread_helper(func): # type: (Any) -> threading.Thread
return thread


def pil2pixbuf(img): # type: (pil.Image) -> GdkPixbuf.Pixbuf
def pil2pixbuf(img): # type: (Any) -> GdkPixbuf.Pixbuf
"""
Convert a pillow (pil) object to a pixbuf
Expand Down

0 comments on commit 7aa3edc

Please sign in to comment.