Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Modified copyright on all files. Also fixed a bug in the EC2 Security…
Browse files Browse the repository at this point in the history
…Group response parsing.
  • Loading branch information
Mitch.Garnaat authored and Mitch.Garnaat committed Jan 8, 2007
1 parent 8b6703c commit c626a93
Show file tree
Hide file tree
Showing 26 changed files with 152 additions and 45 deletions.
2 changes: 1 addition & 1 deletion boto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion boto/connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion boto/ec2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
5 changes: 4 additions & 1 deletion boto/ec2/image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down Expand Up @@ -33,6 +33,9 @@ def __init__(self, connection=None):
self.ownerId = None
self.isPublic = False

def __repr__(self):
return 'Image:%s' % self.id

def startElement(self, name, attrs, connection):
return None

Expand Down
8 changes: 4 additions & 4 deletions boto/ec2/instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006, 2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand All @@ -24,9 +24,6 @@
"""

from boto.resultset import ResultSet
import xml.sax
from boto.exception import SQSError, S3ResponseError, S3CreateError
from boto import handler

class Reservation:

Expand All @@ -37,6 +34,9 @@ def __init__(self, connection=None):
self.groups = []
self.instances = []

def __repr__(self):
return 'Instance:%s' % self.id

def startElement(self, name, attrs, connection):
if name == 'instancesSet':
self.instances = ResultSet('item', Instance)
Expand Down
8 changes: 7 additions & 1 deletion boto/ec2/keypair.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down Expand Up @@ -31,6 +31,9 @@ def __init__(self, connection=None):
self.fingerprint = None
self.material = None

def __repr__(self):
return 'KeyPair:%s' % self.name

def startElement(self, name, attrs, connection):
return None

Expand All @@ -44,5 +47,8 @@ def endElement(self, name, value, connection):
else:
setattr(self, name, value)

def delete(self):
return self.connection.delete_key_pair(self.name)



58 changes: 50 additions & 8 deletions boto/ec2/securitygroup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down Expand Up @@ -31,16 +31,21 @@ def __init__(self, connection=None, owner_id=None,
self.owner_id = owner_id
self.name = name
self.description = description
self.ip_permissions = []
self.rules = []

def __repr__(self):
return 'SecurityGroup:%s' % self.name

def startElement(self, name, attrs, connection):
print 'SecurityGroup.startElement: %s' % name
if name == 'item':
self.ip_permissions.append(IPPermissions(self))
return self.ip_permissions[-1]
self.rules.append(IPPermissions(self))
return self.rules[-1]
else:
return None

def endElement(self, name, value, connection):
print 'SecurityGroup.endElement: %s' % name
if name == 'ownerId':
self.owner_id = value
elif name == 'groupName':
Expand All @@ -54,28 +59,65 @@ def endElement(self, name, value, connection):
else:
setattr(self, name, value)

def delete(self):
return self.connection.delete_security_group(self.name)

class IPPermissions:

def __init__(self, parent=None):
self.parent = parent
self.ip_protocol = None
self.from_port = None
self.to_port = None
self.ip_ranges = []
self.grants = []

def __repr__(self):
return 'IPPermissions:%s(%s-%s)' % (self.ip_protocol,
self.from_port, self.to_port)

def startElement(self, name, attrs, connection):
print 'IPPermissions.startElement: %s' % name
if name == 'item':
self.grants.append(GroupOrCIDR(self))
return self.grants[-1]
return None

def endElement(self, name, value, connection):
print 'IPPermissions.endElement: %s' % name
if name == 'ipProtocol':
self.ip_protocol = value
elif name == 'fromPort':
self.from_port = value
elif name == 'toPort':
self.to_port = value
elif name == 'cidrIp':
self.ip_ranges.append(value)
else:
setattr(self, name, value)


class GroupOrCIDR:

def __init__(self, parent=None):
self.user_id = None
self.group_name = None
self.cidr_ip = None

def __repr__(self):
if self.cidr_ip:
return '%s' % self.cidr_ip
else:
return '%s-%s' % (self.group_name, self.user_id)

def startElement(self, name, attrs, connection):
print 'GroupOrCIDR.startElement: %s' % name
return None

def endElement(self, name, value, connection):
print 'GroupOrCIDR.endElement: %s' % name
if name == 'userId':
self.user_id = value
elif name == 'groupName':
self.group_name = value
if name == 'cidrIp':
self.cidr_ip = value
else:
setattr(self, name, value)

2 changes: 1 addition & 1 deletion boto/exception.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion boto/handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion boto/resultset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion boto/s3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
25 changes: 23 additions & 2 deletions boto/s3/acl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand All @@ -20,6 +20,7 @@
# IN THE SOFTWARE.

from boto.s3.user import User
import StringIO

CannedACLStrings = ['private', 'public-read',
'public-read-write', 'authenticated-read']
Expand Down Expand Up @@ -48,6 +49,13 @@ def endElement(self, name, value, connection):
else:
setattr(self, name, value)

def to_xml(self):
s = '<AccessControlPolicy>'
s += self.owner.to_xml()
s += self.acl.to_xml()
s += '</AccessControlPolicy>'
return s

class ACL:

def __init__(self, policy=None):
Expand All @@ -70,6 +78,13 @@ def endElement(self, name, value, connection):
else:
setattr(self, name, value)

def to_xml(self):
s = '<AccessControlList>'
for grant in self.grants:
s += grant.to_xml()
s += '</AccessControlList>'
return s

class Grant:

def __init__(self, acl=None, grantee=None):
Expand All @@ -95,5 +110,11 @@ def endElement(self, name, value, connection):
else:
setattr(self, name, value)


def to_xml(self):
s = '<Grant>'
s += self.grantee.to_xml('Grantee')
s += '<Permission>%s</Permission>' % self.permission
s += '</Grant>'
return s


2 changes: 1 addition & 1 deletion boto/s3/bucket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
19 changes: 12 additions & 7 deletions boto/s3/key.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down Expand Up @@ -26,7 +26,7 @@
import base64
import boto
import boto.utils
from boto.exception import S3ResponseError
from boto.exception import S3ResponseError, S3Error
from boto.s3.user import User

class Key:
Expand Down Expand Up @@ -87,12 +87,17 @@ def send_file(self, fp):
for key in final_headers:
http_conn.putheader(key,final_headers[key])
http_conn.endheaders()
l = fp.read(4096)
while len(l) > 0:
http_conn.send(l)
try:
l = fp.read(4096)
response = http_conn.getresponse()
body = response.read()
while len(l) > 0:
http_conn.send(l)
l = fp.read(4096)
response = http_conn.getresponse()
body = response.read()
except Exception, e:
self.bucket.connection.make_http_connection()
print 'Caught an unexpected exception'
raise e
if response.status != 200:
raise S3ResponseError(response.status, response.reason)
self.etag = response.getheader('etag')
Expand Down
11 changes: 10 additions & 1 deletion boto/s3/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down Expand Up @@ -40,3 +40,12 @@ def endElement(self, name, value, connection):
else:
setattr(self, name, value)

def to_xml(self, element_name='Owner'):
if self.type:
s = '<%s xsi:type="%s">' % (element_name, self.type)
else:
s = '<%s>' % element_name
s += '<ID>%s</ID>' % self.id
s += '<DisplayName>%s</DisplayName>' % self.display_name
s += '</%s>' % element_name
return s
2 changes: 1 addition & 1 deletion boto/sqs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion boto/sqs/message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion boto/sqs/queue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion boto/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2006 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down
21 changes: 21 additions & 0 deletions cq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
#!/usr/bin/env python
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
import getopt, sys
from boto.connection import SQSConnection
from boto.exception import SQSError
Expand Down
4 changes: 2 additions & 2 deletions doc/s3_tut.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ within your bucket.
The Key object is used in boto to keep track of data stored in S3. To store
new data in S3, start by creating a new Key object:

>>> from boto.key import Key
>>> from boto.s3.key import Key
>>> k = Key(bucket)
>>> k.key = 'foobar'
>>> k.set_contents_from_string('This is a test of S3')
Expand All @@ -86,7 +86,7 @@ this worked, quit out of the interpreter and start it up again. Then:
>>> import boto
>>> c = boto.connect_s3()
>>> b = c.create_bucket('mybucket') # substitute your bucket name here
>>> from boto.key import Key
>>> from boto.s3.key import Key
>>> k = Key(b)
>>> k.key = 'foobar'
>>> k.get_contents_as_string()
Expand Down
Loading

0 comments on commit c626a93

Please sign in to comment.