Browse Source

Remove Python 2 support.

We now only support Python 3.
master
Damien Goutte-Gattat 3 months ago
parent
commit
6f9b45345a
5 changed files with 22 additions and 53 deletions
  1. +8
    -7
      incenp/davpoint/__main__.py
  2. +0
    -36
      incenp/davpoint/compat.py
  3. +4
    -4
      incenp/davpoint/davfs2.py
  4. +7
    -5
      incenp/davpoint/sharepoint.py
  5. +3
    -1
      setup.py

+ 8
- 7
incenp/davpoint/__main__.py View File

@ -15,28 +15,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from configparser import ConfigParser
import os
import sys
import click
from incenp.davpoint import __version__
from incenp.davpoint.compat import ConfigParser
from incenp.davpoint.davfs2 import get_credentials, mount
from incenp.davpoint.sharepoint import authenticate
prog_name = "davpoint"
prog_notice = """\
{} {}
prog_notice = f"""\
{prog_name} {__version__}
Copyright © 2019 Damien Goutte-Gattat
This program is released under the GNU General Public License.
See the COPYING file or <http://www.gnu.org/licenses/gpl.html>.
""".format(prog_name, __version__)
"""
def die(msg):
sys.stderr.write("{}: {}\n".format(prog_name, msg))
print("{prog_name}: {msg}", file=sys.stderr)
sys.exit(1)
@ -56,7 +56,7 @@ def main(config_file, share):
config.read(config_file)
if not config.has_section(share):
die("No section '{}' in configuration file".format(share))
die(f"No section {share!r} in configuration file")
endpoint = config.get(share, 'endpoint')
mountpoint = config.get(share, 'mountpoint')
@ -68,7 +68,8 @@ def main(config_file, share):
username, password = get_credentials(endpoint, mountpoint)
cookies = authenticate(endpoint, username, password)
davfs2_options['add_header'] = 'Cookie rtFa={rtFa};FedAuth={FedAuth};'.format(**cookies)
davfs2_options['add_header'] = (f'Cookie rtFa={cookies["rtFa"]};'
f'FedAuth={cookies["FedAuth"]};')
mount(mountpoint, davfs2_options)


+ 0
- 36
incenp/davpoint/compat.py View File

@ -1,36 +0,0 @@
# -*- coding: utf-8 -*-
# davpoint - Davfs2 wrapper to mount SharePoint filesystems
# Copyright © 2019 Damien Goutte-Gattat
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Python 2 compatibility module."""
try:
from http.cookiejar import CookieJar
except ImportError:
from cookielib import CookieJar
try:
from urllib.error import URLError
from urllib.parse import urlparse
from urllib.request import urlopen, build_opener, HTTPCookieProcessor, Request
except ImportError:
from urllib2 import URLError, urlopen, build_opener, HTTPCookieProcessor, Request
from urlparse import urlparse
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import SafeConfigParser as ConfigParser

+ 4
- 4
incenp/davpoint/davfs2.py View File

@ -90,7 +90,7 @@ def get_credentials(endpoint, mountpoint):
continue
if secret[0] in (endpoint, mountpoint):
return (secret[1], secret[2])
raise Error("Credentials not found for {}:{}".format(endpoint, mountpoint))
raise Error(f"Credentials not found for {endpoint}:{mountpoint}")
def mount(mountpoint, config):
@ -108,18 +108,18 @@ def mount(mountpoint, config):
fd, fn = mkstemp(text=True)
fh = fdopen(fd, 'w')
command.insert(1, '-o')
command.insert(2, 'conf={}'.format(fn))
command.insert(2, f'conf={fn}')
else:
# Write configuration to ~/.davfs2/davfs2.conf
# (Backup it first if it exists)
fn = '{}/.davfs2/davfs2.conf'.format(getenv('HOME', '.'))
if exists(fn):
backup = '{}.bak'.format(fn)
backup = f'{fn}.bak'
rename(fn, backup)
fh = open(fn, 'w')
for key, value in config.items():
fh.write('{} {}\n'.format(key, value))
fh.write(f'{key} {value}\n')
fh.close()
ret = call(command)


+ 7
- 5
incenp/davpoint/sharepoint.py View File

@ -20,11 +20,13 @@
This module provides functions to interact with SharePoint services.
"""
from http.cookiejar import CookieJar
from urllib.error import URLError
from urllib.parse import urlparse
from urllib.request import Request, build_opener, urlopen, HTTPCookieProcessor
from xml.etree.ElementTree import parse as xmlparse
from incenp.davpoint import Error
from incenp.davpoint.compat import CookieJar, HTTPCookieProcessor, Request, \
URLError, build_opener, urlopen, urlparse
_request_template = '''<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing"
@ -75,14 +77,14 @@ def authenticate(endpoint, username, password):
"""
scheme, host, _, _, _, _ = urlparse(endpoint)
if scheme not in ['http', 'https'] or not host:
raise Error("Invalid endpoint: {}".format(endpoint))
raise Error(f"Invalid endpoint: {endpoint}")
try:
data = _request_template.format(username, password, endpoint)
request = urlopen('https://login.microsoftonline.com/extSTS.srf',
data.encode('utf-8'))
except URLError as e:
raise Error("Authentication request failed: {}".format(e.reason))
raise Error(f"Authentication request failed: {e.reason}")
reply = xmlparse(request)
token = reply.find('.//wssec:BinarySecurityToken', _namespaces)
@ -95,7 +97,7 @@ def authenticate(endpoint, username, password):
request = Request(_site_url_template.format(scheme, host))
reply = opener.open(request, data=token.text.encode('utf-8'))
except URLError as e:
raise Error("Login request failed: {}".format(e.reason))
raise Error(f"Login request failed: {e.reason}")
cookies = {}
for cookie in cookie_jar:


+ 3
- 1
setup.py View File

@ -35,8 +35,10 @@ setup(
'Environment :: Console',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8'
],
install_requires=[


Loading…
Cancel
Save