~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/client/base.py

Merged 921421-completemultipart [r=oubiwann][f=921421]

This branch adds Complete Multipart method to s3 client.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import os
2
 
import urlparse
3
 
 
4
1
try:
5
2
    from xml.etree.ElementTree import ParseError
6
3
except ImportError:
9
6
import warnings
10
7
from StringIO import StringIO
11
8
 
12
 
from twisted.internet.endpoints import TCP4ClientEndpoint
13
9
from twisted.internet.ssl import ClientContextFactory
14
10
from twisted.internet.protocol import Protocol
15
11
from twisted.internet.defer import Deferred, succeed, fail
16
12
from twisted.python import failure
17
13
from twisted.web import http
18
14
from twisted.web.iweb import UNKNOWN_LENGTH
19
 
from twisted.web.client import Agent, ProxyAgent
 
15
from twisted.web.client import HTTPClientFactory
 
16
from twisted.web.client import Agent
20
17
from twisted.web.client import ResponseDone
21
 
from twisted.web.http import NO_CONTENT, PotentialDataLoss
 
18
from twisted.web.http import NO_CONTENT
22
19
from twisted.web.http_headers import Headers
23
20
from twisted.web.error import Error as TwistedWebError
24
21
try:
133
130
        self._received += len(bytes)
134
131
 
135
132
    def connectionLost(self, reason):
136
 
        reason.trap(ResponseDone, PotentialDataLoss)
 
133
        reason.trap(ResponseDone)
137
134
        d = self.finished
138
135
        self.finished = None
139
136
        streaming = self.content_length is UNKNOWN_LENGTH
223
220
        if (self.body_producer is None) and (data is not None):
224
221
            self.body_producer = FileBodyProducer(StringIO(data))
225
222
        if scheme == "https":
226
 
            proxy_endpoint = os.environ.get("https_proxy")
227
 
            if proxy_endpoint:
228
 
                proxy_url = urlparse.urlparse(proxy_endpoint)
229
 
                endpoint = TCP4ClientEndpoint(self.reactor, proxy_url.hostname, proxy_url.port)
230
 
                agent = ProxyAgent(endpoint)
 
223
            if self.endpoint.ssl_hostname_verification:
 
224
                contextFactory = WebVerifyingContextFactory(host)
231
225
            else:
232
 
                if self.endpoint.ssl_hostname_verification:
233
 
                    contextFactory = WebVerifyingContextFactory(host)
234
 
                else:
235
 
                    contextFactory = WebClientContextFactory()
236
 
                agent = Agent(self.reactor, contextFactory)
 
226
                contextFactory = WebClientContextFactory()
 
227
            agent = Agent(self.reactor, contextFactory)
237
228
            self.client.url = url
238
229
            d = agent.request(method, url, self.request_headers,
239
230
                self.body_producer)
240
231
        else:
241
 
            proxy_endpoint = os.environ.get("http_proxy")
242
 
            if proxy_endpoint:
243
 
                proxy_url = urlparse.urlparse(proxy_endpoint)
244
 
                endpoint = TCP4ClientEndpoint(self.reactor, proxy_url.hostname, proxy_url.port)
245
 
                agent = ProxyAgent(endpoint)
246
 
            else:
247
 
                agent = Agent(self.reactor)
 
232
            agent = Agent(self.reactor)
248
233
            d = agent.request(method, url, self.request_headers,
249
234
                self.body_producer)
250
235
        d.addCallback(self._handle_response)