~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to swift/common/constraints.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-28 09:40:30 UTC
  • mfrom: (1.2.16)
  • Revision ID: package-import@ubuntu.com-20130128094030-aetz57x2qz9ye2d4
Tags: 1.7.6-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
182
182
 
183
183
def check_utf8(string):
184
184
    """
185
 
    Validate if a string is valid UTF-8 str or unicode
 
185
    Validate if a string is valid UTF-8 str or unicode and that it
 
186
    does not contain any null character.
186
187
 
187
188
    :param string: string to be validated
188
 
    :returns: True if the string is valid utf-8 str or unicode, False otherwise
 
189
    :returns: True if the string is valid utf-8 str or unicode and
 
190
              contains no null characters, False otherwise
189
191
    """
190
192
    if not string:
191
193
        return False
194
196
            string.encode('utf-8')
195
197
        else:
196
198
            string.decode('UTF-8')
197
 
        return True
 
199
        return '\x00' not in string
198
200
    # If string is unicode, decode() will raise UnicodeEncodeError
199
201
    # So, we should catch both UnicodeDecodeError & UnicodeEncodeError
200
202
    except UnicodeError: