MCPcopy Create free account
hub / github.com/s3tools/s3cmd / _https_connection

Method _https_connection

S3/ConnMan.py:164–198  ·  view source on GitHub ↗
(hostname, port=None)

Source from the content-addressed store, hash-verified

162
163 @staticmethod
164 def _https_connection(hostname, port=None):
165 try:
166 context = http_connection._ssl_context()
167 # Wildcard certificates do not work with DNS-style named buckets.
168 bucket_name, success = getBucketFromHostname(hostname)
169 if success and '.' in bucket_name:
170 # this merely delays running the hostname check until
171 # after the connection is made and we get control
172 # back. We then run the same check, relaxed for S3's
173 # wildcard certificates.
174 debug(u'Bucket name contains "." character, disabling initial SSL hostname check')
175 check_hostname = False
176 if context:
177 context.check_hostname = False
178 else:
179 if context:
180 check_hostname = context.check_hostname
181 else:
182 # Earliest version of python that don't have context,
183 # don't check hostnames anyway
184 check_hostname = True
185 # Note, we are probably needed to try to set check_hostname because of that bug:
186 # http://bugs.python.org/issue22959
187 conn = httplib.HTTPSConnection(hostname, port, context=context, check_hostname=check_hostname)
188 debug(u'httplib.HTTPSConnection() has both context and check_hostname')
189 except TypeError:
190 try:
191 # in case check_hostname parameter is not present try again
192 conn = httplib.HTTPSConnection(hostname, port, context=context)
193 debug(u'httplib.HTTPSConnection() has only context')
194 except TypeError:
195 # in case even context parameter is not present try one last time
196 conn = httplib.HTTPSConnection(hostname, port)
197 debug(u'httplib.HTTPSConnection() has neither context nor check_hostname')
198 return conn
199
200 def __init__(self, id, hostname, ssl, cfg):
201 self.ssl = ssl

Callers 1

__init__Method · 0.80

Calls 2

getBucketFromHostnameFunction · 0.85
_ssl_contextMethod · 0.80

Tested by

no test coverage detected