Пример #1
0
    def test_getitem(self):
        s = oldstr(b'abc')

        self.assertNotEqual(s[0], 97)
        self.assertEqual(s[0], b'a')
        self.assertEqual(s[0], oldstr(b'a'))

        self.assertEqual(s[1:], b'bc')
        self.assertEqual(s[1:], oldstr(b'bc'))
Пример #2
0
    def test_getitem(self):
        s = oldstr(b'abc')

        self.assertNotEqual(s[0], 97)
        self.assertEqual(s[0], b'a')
        self.assertEqual(s[0], oldstr(b'a'))

        self.assertEqual(s[1:], b'bc')
        self.assertEqual(s[1:], oldstr(b'bc'))
Пример #3
0
    def test_getitem(self):
        s = oldstr(b"abc")

        self.assertNotEqual(s[0], 97)
        self.assertEqual(s[0], b"a")
        self.assertEqual(s[0], oldstr(b"a"))

        self.assertEqual(s[1:], b"bc")
        self.assertEqual(s[1:], oldstr(b"bc"))
Пример #4
0
def copyKeyMultipart(srcBucketName, srcKeyName, srcKeyVersion, dstBucketName, dstKeyName, sseAlgorithm=None, sseKey=None,
                     copySourceSseAlgorithm=None, copySourceSseKey=None):
    """
    Copies a key from a source key to a destination key in multiple parts. Note that if the
    destination key exists it will be overwritten implicitly, and if it does not exist a new
    key will be created. If the destination bucket does not exist an error will be raised.

    :param str srcBucketName: The name of the bucket to be copied from.
    :param str srcKeyName: The name of the key to be copied from.
    :param str srcKeyVersion: The version of the key to be copied from.
    :param str dstBucketName: The name of the destination bucket for the copy.
    :param str dstKeyName: The name of the destination key that will be created or overwritten.
    :param str sseAlgorithm: Server-side encryption algorithm for the destination.
    :param str sseKey: Server-side encryption key for the destination.
    :param str copySourceSseAlgorithm: Server-side encryption algorithm for the source.
    :param str copySourceSseKey: Server-side encryption key for the source.

    :rtype: str
    :return: The version of the copied file (or None if versioning is not enabled for dstBucket).
    """
    s3 = boto3.resource('s3')
    dstBucket = s3.Bucket(oldstr(dstBucketName))
    dstObject = dstBucket.Object(oldstr(dstKeyName))
    copySource = {'Bucket': oldstr(srcBucketName), 'Key': oldstr(srcKeyName)}
    if srcKeyVersion is not None:
        copySource['VersionId'] = oldstr(srcKeyVersion)

    # The boto3 functions don't allow passing parameters as None to
    # indicate they weren't provided. So we have to do a bit of work
    # to ensure we only provide the parameters when they are actually
    # required.
    destEncryptionArgs = {}
    if sseKey is not None:
        destEncryptionArgs.update({'SSECustomerAlgorithm': sseAlgorithm,
                                   'SSECustomerKey': sseKey})
    copyEncryptionArgs = {}
    if copySourceSseKey is not None:
        copyEncryptionArgs.update({'CopySourceSSECustomerAlgorithm': copySourceSseAlgorithm,
                                   'CopySourceSSECustomerKey': copySourceSseKey})
    copyEncryptionArgs.update(destEncryptionArgs)

    dstObject.copy(copySource, ExtraArgs=copyEncryptionArgs)

    # Unfortunately, boto3's managed copy doesn't return the version
    # that it actually copied to. So we have to check immediately
    # after, leaving open the possibility that it may have been
    # modified again in the few seconds since the copy finished. There
    # isn't much we can do about it.
    info = boto3.client('s3').head_object(Bucket=dstObject.bucket_name, Key=dstObject.key,
                                          **destEncryptionArgs)
    return info.get('VersionId', None)
Пример #5
0
 def chr(i):
     """
     Return a byte-string of one character with ordinal i; 0 <= i <= 256
     """
     return oldstr(bytes((i,)))
Пример #6
0
 def test_str(self):
     s1 = oldstr(b'abc')
     self.assertEqual(str(s1), 'abc')
     s2 = oldstr(b'abc\ndef')
     self.assertEqual(str(s2), 'abc\ndef')
Пример #7
0
 def test_repr(self):
     s1 = oldstr(b'abc')
     self.assertEqual(repr(s1), "'abc'")
     s2 = oldstr(b'abc\ndef')
     self.assertEqual(repr(s2), "'abc\\ndef'")
Пример #8
0
 def test_isinstance(self):
     s = b'abc'
     self.assertTrue(isinstance(s, basestring))
     s2 = oldstr(b'abc')
     self.assertTrue(isinstance(s2, basestring))
Пример #9
0
def compat_oldstr(s):
    if USING_PYTHON2:
        return oldstr(s)
    else:
        return s.decode('utf-8') if isinstance(s, bytes) else s
Пример #10
0
 def test_str(self):
     s1 = oldstr(b"abc")
     self.assertEqual(str(s1), "abc")
     s2 = oldstr(b"abc\ndef")
     self.assertEqual(str(s2), "abc\ndef")
Пример #11
0
 def test_str(self):
     s1 = oldstr(b'abc')
     self.assertEqual(str(s1), 'abc')
     s2 = oldstr(b'abc\ndef')
     self.assertEqual(str(s2), 'abc\ndef')
Пример #12
0
 def test_repr(self):
     s1 = oldstr(b'abc')
     self.assertEqual(repr(s1), "'abc'")
     s2 = oldstr(b'abc\ndef')
     self.assertEqual(repr(s2), "'abc\\ndef'")
Пример #13
0
 def test_isinstance(self):
     s = b'abc'
     self.assertTrue(isinstance(s, basestring))
     s2 = oldstr(b'abc')
     self.assertTrue(isinstance(s2, basestring))