Permalink
Browse files

Merge pull request #2525 from danielgtaylor/s3-repr

Better S3 key repr support for unicode. Fixes #2525, #2516.
  • Loading branch information...
danielgtaylor committed Aug 26, 2014
2 parents 2b87583 + d358ee4 commit 81988845b1e41d68dcb34ed1ab5dee2784a299a9
Showing with 14 additions and 2 deletions.
  1. +8 −2 boto/s3/key.py
  2. +6 −0 tests/unit/s3/test_key.py
View
@@ -136,9 +136,15 @@ def __init__(self, bucket=None, name=None):
def __repr__(self):
if self.bucket:
return '<Key: %s,%s>' % (self.bucket.name, self.name)
name = u'<Key: %s,%s>' % (self.bucket.name, self.name)
else:
return '<Key: None,%s>' % self.name
name = u'<Key: None,%s>' % self.name
# Encode to bytes for Python 2 to prevent display decoding issues
if not isinstance(name, str):
name = name.encode('utf-8')
return name
def __iter__(self):
return self
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -39,6 +40,11 @@ def setUp(self):
def default_body(self):
return "default body"
def test_unicode_name(self):
k = Key()
k.name = u'Österreich'
print(repr(k))
def test_when_no_restore_header_present(self):
self.set_http_response(status_code=200)
b = Bucket(self.service_connection, 'mybucket')

0 comments on commit 8198884

Please sign in to comment.