Commit 028500a2 authored by pm22d12's avatar pm22d12
Browse files

https protocol modified to access the server "n5eil01u.ecs.nsidc.org"

parent dd2674a6
......@@ -387,6 +387,9 @@ class DCheck(object):
obj = ftps.Protocol_ftps(option)
elif protocolname == "https_directorylist":
classFileExtractor = https_directorylist.FileExtractor
redirector = None
if "Redirector" in option:
redirector = option["Redirector"]
if "FileExtractor" in option:
fileExtractor = "FileExtractor_" + option["FileExtractor"]
if hasattr(file_extractor, fileExtractor):
......@@ -398,7 +401,10 @@ class DCheck(object):
module = __import__("https_FileExtractor")
log.warning("The HTTP protocol uses the FileExtractor module of the plugin directory")
classFileExtractor=getattr(module, fileExtractor)
obj = https_directorylist.Protocol_https_directorylist(classFileExtractor)
obj = https_directorylist.Protocol_https_directorylist(
fileExtractor=classFileExtractor,
redirector=redirector)
return obj
def getOptions(self, argsList=None):
......
......@@ -12,6 +12,7 @@ import time
import urllib.request
import urllib.error
import urllib.parse
import http.cookiejar
import re
import html.parser
import os
......@@ -143,7 +144,7 @@ class FileExtractor(html.parser.HTMLParser):
class Protocol_https_directorylist(AbstractProtocol):
def __init__(self, fileExtractor=FileExtractor):
def __init__(self, fileExtractor=FileExtractor, redirector=None):
AbstractProtocol.__init__(self)
self.path = None
......@@ -164,6 +165,7 @@ class Protocol_https_directorylist(AbstractProtocol):
self.__fileExtractor = fileExtractor
self.date_format = self.__fileExtractor.DATE_FORMAT
#print(f"init =====> extractor : {self.__fileExtractor} (date format={self.date_format}), factor={self.__fileExtractor.FACTOR}")
self.__redirector = redirector
def setConfig(self, config):
AbstractProtocol.setConfig(self, config)
......@@ -207,7 +209,8 @@ class Protocol_https_directorylist(AbstractProtocol):
def getFileInfoList(self):
# gestion de l'authentification http
if self.username is not None and self.password is not None or 1==1:
if self.username is not None and self.password is not None:
"""
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(
'Input your password.',
......@@ -217,6 +220,26 @@ class Protocol_https_directorylist(AbstractProtocol):
# les urllib2.urlopen utiliseront le gestionnaire de mot de passe
opener = urllib.request.build_opener(auth_handler)
urllib.request.install_opener(opener)
"""
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(
realm=None, uri=self.server, user=self.username, passwd=self.password)
if self.__redirector is not None:
password_mgr.add_password(
realm=None, uri=self.__redirector, user=self.username, passwd=self.password)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
cookie_jar = http.cookiejar.CookieJar()
handler_cookie = urllib.request.HTTPCookieProcessor(cookie_jar)
opener = urllib.request.build_opener(handler, handler_cookie)
else:
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(handler)
urllib.request.install_opener(opener)
self._baseurl = self._protocol_str + self.server
self.url = self._baseurl + "/" + self.path
......
......@@ -63,9 +63,11 @@ class HttpsSession(object):
downloadfile = open(localpath, 'wb')
self.filesize = int(flow.info()['Content-Length'])
# check real filename
if 'Content-Disposition' in flow.info():
if 'Content-Disposition' in flow.info() \
and len(flow.info()['Content-Disposition'].split('filename=')) == 2:
print("'Content-Disposition' = %s", str(flow.info()['Content-Disposition']))
filename = flow.info()[
'Content-Disposition'].split('=')[1].strip('"')
'Content-Disposition'].split('filename=')[1].strip('"')
else:
filename = filename[:-len(TMP_EXT)]
......
......@@ -366,17 +366,21 @@ class SynchronisationLocalRemote(object):
elif self.__remote_storage_type.startswith('Https'):
if self.__remote_storage_type == 'Https_OpenSearch' or self.__remote_storage_type == 'Https_opensearch':
protocol = "https_opensearch"
self.__remote_url = "https_opensearch://"
else:
protocol = "https"
assert 0, "Dead code: unknown var 'provider'"
# self.__base_url = '%s://%s:%s@%s/%s' % (
# protocol,
# provider.username,
# provider.password,
# provider.server,
# self.__download.remote_storage_repository.lstrip('/')
# )
self.__remote_url = "https://"
if self.__remote_storage_username is not None:
self.__remote_url += self.__remote_storage_username
if self.__remote_storage_passwd is not None:
self.__remote_url += ':' + self.__remote_storage_passwd
if self.__remote_storage_username is not None or self.__remote_storage_passwd is not None:
self.__remote_url += '@'
self.__remote_url += '%s' % self.__remote_storage_server
if self.__remote_storage_port is not None:
self.__remote_url += ':%s' % (str(self.__remote_storage_port))
self.__remote_url += '/' + self.__remote_storage_repository.lstrip('/')
elif self.__remote_storage_type in ['Localpath', 'Localmove', 'Localpointer', 'Onlynotify']:
self.__remote_url = self.__remote_storage_repository
......
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