示例#1
0
 def test_unicode_nfc_and_nfd_decomposition_equality(self):
     import unicodedata
     text = 'Hyv\xe4'
     assert_equal(safe_str(unicodedata.normalize('NFC', text)), text)
     # In Mac filesystem umlaut characters are presented in NFD-format.
     # This is to check that unic normalizes all strings to NFC
     assert_equal(safe_str(unicodedata.normalize('NFD', text)), text)
示例#2
0
 def __init__(self, result):
     if not (is_dict_like(result) and 'status' in result):
         raise RuntimeError('Invalid remote result dictionary: %s' % result)
     self.status = result['status']
     self.output = safe_str(self._get(result, 'output'))
     self.return_ = self._get(result, 'return')
     self.error = safe_str(self._get(result, 'error'))
     self.traceback = safe_str(self._get(result, 'traceback'))
     self.fatal = bool(self._get(result, 'fatal', False))
     self.continuable = bool(self._get(result, 'continuable', False))
示例#3
0
 def _get_message(self, record):
     try:
         return self.format(record), None
     except:
         message = 'Failed to log following message properly: %s' \
                     % safe_str(record.msg)
         error = '\n'.join(get_error_details())
         return message, error
示例#4
0
 def _normalize_message(self, msg):
     if callable(msg):
         return msg
     if not is_string(msg):
         msg = safe_str(msg)
     if '\r\n' in msg:
         msg = msg.replace('\r\n', '\n')
     return msg
示例#5
0
 def _handle_error(self, name, value, error=None, strict=True):
     if not strict:
         return value
     value_type = '' if isinstance(value,
                                   str) else ' (%s)' % type_name(value)
     ending = ': %s' % error if (error and error.args) else '.'
     raise ValueError(
         "Argument '%s' got value '%s'%s that cannot be converted to %s%s" %
         (name, safe_str(value), value_type, self.type_name, ending))
示例#6
0
    def replace_string(self, item, custom_unescaper=None, ignore_errors=False):
        """Replaces variables from a string. Result is always a string.

        Input can also be an already found VariableMatch.
        """
        unescaper = custom_unescaper or unescape
        match = self._search_variable(item, ignore_errors=ignore_errors)
        if not match:
            return safe_str(unescaper(match.string))
        return self._replace_string(match, unescaper, ignore_errors)
示例#7
0
 def _replace_string(self, match, unescaper, ignore_errors):
     parts = []
     while match:
         parts.extend([
             unescaper(match.before),
             safe_str(self._get_variable_value(match, ignore_errors))
         ])
         match = search_variable(match.after, ignore_errors=ignore_errors)
     parts.append(unescaper(match.string))
     return ''.join(parts)
示例#8
0
 def start_keyword(self, kw):
     attrs = {'name': kw.kwname, 'library': kw.libname}
     if kw.type != 'KEYWORD':
         attrs['type'] = kw.type
     if kw.sourcename:
         attrs['sourcename'] = kw.sourcename
     self._writer.start('kw', attrs)
     self._write_list('var', kw.assign)
     self._write_list('arg', [safe_str(a) for a in kw.args])
     self._write_list('tag', kw.tags)
     # Must be after tags to allow adding message when using --flattenkeywords.
     self._writer.element('doc', kw.doc)
示例#9
0
 def _list_dir(self, dir_path, incl_suites):
     try:
         names = os.listdir(dir_path)
     except:
         raise DataError("Reading directory '%s' failed: %s"
                         % (dir_path, get_error_message()))
     for name in sorted(names, key=lambda item: item.lower()):
         name = safe_str(name)  # Handles NFC normalization on OSX
         path = os.path.join(dir_path, name)
         base, ext = os.path.splitext(name)
         ext = ext[1:].lower()
         if self._is_init_file(path, base, ext):
             yield path, True
         elif self._is_included(path, base, ext, incl_suites):
             yield path, False
         else:
             LOGGER.info("Ignoring file or directory '%s'." % path)
示例#10
0
 def string(self, string, escape=True, attr=False):
     if escape and string:
         if not is_string(string):
             string = safe_str(string)
         string = (html_escape if not attr else attribute_escape)(string)
     return self._strings.add(string)
示例#11
0
 def _get_extra_attributes(self, kw):
     args = [a if is_string(a) else safe_str(a) for a in kw.args]
     return {'kwname': kw.kwname or '', 'libname': kw.libname or '', 'args': args}
示例#12
0
 def default_repr(self):
     if self.default is self.NOTSET:
         return None
     if isinstance(self.default, Enum):
         return self.default.name
     return safe_str(self.default)
示例#13
0
 def _fail(self, message, default_template, *items):
     if not message:
         message = default_template % tuple(
             safe_str(item) for item in items)
     raise AssertionError(message)
示例#14
0
 def test_list_with_objects_containing_unicode_repr(self):
     objects = [UnicodeRepr(), UnicodeRepr()]
     result = safe_str(objects)
     assert_equal(result, '[Hyv\xe4, Hyv\xe4]')
示例#15
0
 def test_object_containing_unicode_repr(self):
     assert_equal(safe_str(UnicodeRepr()), 'Hyv\xe4')
示例#16
0
 def test_bytes_below_128(self):
     assert_equal(safe_str('\x00-\x01-\x02-\x7f'), '\x00-\x01-\x02-\x7f')
示例#17
0
 def _to_string(self, item):
     item = safe_str(item) if item is not None else ''
     return self._handle_string(item)
 def _trace_log_args(self, positional, named):
     args = [prepr(arg) for arg in positional]
     args += ['%s=%s' % (safe_str(n), prepr(v)) for n, v in named]
     return 'Arguments: [ %s ]' % ' | '.join(args)
示例#19
0
 def test_bytes_above_128(self):
     assert_equal(safe_str(b'hyv\xe4'), 'hyv\\xe4')
     assert_equal(safe_str(b'\x00-\x01-\x02-\xe4'), '\x00-\x01-\x02-\\xe4')
示例#20
0
 def test_bytes_with_newlines_tabs_etc(self):
     assert_equal(safe_str(b"\x00\xe4\n\t\r\\'"), "\x00\\xe4\n\t\r\\'")
示例#21
0
 def test_bytearray(self):
     assert_equal(safe_str(bytearray(b'hyv\xe4')), 'hyv\\xe4')
     assert_equal(safe_str(bytearray(b'\x00-\x01-\x02-\xe4')),
                  '\x00-\x01-\x02-\\xe4')
     assert_equal(safe_str(bytearray(b"\x00\xe4\n\t\r\\'")),
                  "\x00\\xe4\n\t\r\\'")
示例#22
0
 def test_failure_in_str(self):
     failing = StrFails()
     assert_equal(safe_str(failing), failing.unrepr)