def check(self, value): # Only ascii chars allowed in these keys value = BaseString.check(self, value) if isinstance(value, unicode) \ and value.encode('utf-8') != value: raise ValueError, 'ASCII string required' return value
def check(self, value): # Only ascii chars allowed in these keys value = BaseString.check(self, value) if isinstance(value, str): try: x = value.encode('ascii') except UnicodeEncodeError: raise ValueError('ASCII string required') else: pass return value