~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/ec2/client.py

  • Committer: Duncan McGreggor
  • Date: 2009-09-05 00:26:12 UTC
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: duncan@canonical.com-20090905002612-cuk3ndv1tkpadgag
Replaced all occurances of ' in all the modules with " (excepting proper usage
of apostrophes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from txaws.util import iso8601time, XML
18
18
 
19
19
 
20
 
__all__ = ['EC2Client']
 
20
__all__ = ["EC2Client"]
21
21
 
22
22
 
23
23
class Reservation(object):
177
177
 
178
178
    def describe_instances(self):
179
179
        """Describe current instances."""
180
 
        q = self.query_factory('DescribeInstances', self.creds, self.endpoint)
 
180
        q = self.query_factory("DescribeInstances", self.creds, self.endpoint)
181
181
        d = q.submit()
182
182
        return d.addCallback(self._parse_instances)
183
183
 
254
254
        instanceset = {}
255
255
        for pos, instance_id in enumerate(instance_ids):
256
256
            instanceset["InstanceId.%d" % (pos+1)] = instance_id
257
 
        q = self.query_factory('TerminateInstances', self.creds, self.endpoint,
 
257
        q = self.query_factory("TerminateInstances", self.creds, self.endpoint,
258
258
                               instanceset)
259
259
        d = q.submit()
260
260
        return d.addCallback(self._parse_terminate_instances)
478
478
        keypair_set = {}
479
479
        for pos, keypair_name in enumerate(keypair_names):
480
480
            keypair_set["KeyPair.%d" % (pos + 1)] = keypair_name
481
 
        q = self.query_factory('DescribeKeyPairs', self.creds, self.endpoint,
 
481
        q = self.query_factory("DescribeKeyPairs", self.creds, self.endpoint,
482
482
                               keypair_set)
483
483
        d = q.submit()
484
484
        return d.addCallback(self._parse_describe_keypairs)
544
544
        if api_version is None:
545
545
            api_version = version.aws_api
546
546
        self.params = {
547
 
            'Version': api_version,
548
 
            'SignatureVersion': '2',
549
 
            'SignatureMethod': 'HmacSHA1',
550
 
            'Action': action,
551
 
            'AWSAccessKeyId': self.creds.access_key,
552
 
            'Timestamp': iso8601time(time_tuple),
 
547
            "Version": api_version,
 
548
            "SignatureVersion": "2",
 
549
            "SignatureMethod": "HmacSHA1",
 
550
            "Action": action,
 
551
            "AWSAccessKeyId": self.creds.access_key,
 
552
            "Timestamp": iso8601time(time_tuple),
553
553
            }
554
554
        if other_params:
555
555
            self.params.update(other_params)
558
558
        """Return the canonical query params (used in signing)."""
559
559
        result = []
560
560
        for key, value in self.sorted_params():
561
 
            result.append('%s=%s' % (self.encode(key), self.encode(value)))
562
 
        return '&'.join(result)
 
561
            result.append("%s=%s" % (self.encode(key), self.encode(value)))
 
562
        return "&".join(result)
563
563
 
564
564
    def encode(self, a_string):
565
565
        """Encode a_string as per the canonicalisation encoding rules.
567
567
        See the AWS dev reference page 90 (2008-12-01 version).
568
568
        @return: a_string encoded.
569
569
        """
570
 
        return quote(a_string, safe='~')
 
570
        return quote(a_string, safe="~")
571
571
 
572
572
    def signing_text(self):
573
573
        """Return the text to be signed when signing the query."""
582
582
        submitting the query. Signing is done automatically - this is a public
583
583
        method to facilitate testing.
584
584
        """
585
 
        self.params['Signature'] = self.creds.sign(self.signing_text())
 
585
        self.params["Signature"] = self.creds.sign(self.signing_text())
586
586
 
587
587
    def sorted_params(self):
588
588
        """Return the query params sorted appropriately for signing."""