def test_quote(self): self.assertEqual('"foo"', string_util.quote('foo')) self.assertEqual('\'foo\'', string_util.quote('foo', quote_char="'")) self.assertEqual('\'fo"o\'', string_util.quote('fo"o')) self.assertEqual('"fo\'o"', string_util.quote('fo\'o')) self.assertEqual('"foo"', string_util.quote('"foo"')) self.assertEqual('\'foo\'', string_util.quote('\'foo\'')) self.assertEqual('\'foo\'', string_util.quote('"foo"', quote_char="'")) self.assertEqual('\'foo\'', string_util.quote('\'foo\'', quote_char="'")) self.assertEqual('\"foo\"', string_util.quote('"foo"', quote_char='"')) self.assertEqual('\"foo\"', string_util.quote('\'foo\'', quote_char='"'))
def tag(clazz, root_dir, tag, allow_downgrade = False, push = False, commit = None, annotation = None): check.check_string(root_dir) check.check_string(tag) check.check_bool(allow_downgrade) check.check_bool(push) check.check_string(commit, allow_none = True) check.check_string(annotation, allow_none = True) if not allow_downgrade: greatest_tag = git.greatest_local_tag(root_dir) if greatest_tag: if software_version.compare(greatest_tag.name, tag) >= 0: raise ValueError('new tag \"{}\" is older than \"{}\". Use allow_downgrade to force it.'.format(tag, greatest_tag.name)) if not commit: commit = clazz.last_commit_hash(root_dir, short_hash = True) args = [ 'tag', tag, commit ] if annotation: args.append('--annotate') args.append('--message') args.append(string_util.quote(annotation)) rv = git_exe.call_git(root_dir, args) if push: clazz.push_tag(root_dir, tag)
def _make_log_attributes(self, cr, include_state = True): attributes = [] if include_state: attributes.append('state=%s' % (self.name)) attributes.append('c=|%s(%s)|' % (cr.char, cr.ctype.name)) try: attributes.append('buffer=%s' % (string_util.quote(self.lexer.buffer_value()))) except AttributeError as ex: attributes.append('buffer=None') return ' '.join(attributes)
def _make_log_attributes(self, c, include_state=True): attributes = [] if include_state: attributes.append('state=%s' % (self.name)) attributes.append('c=|%s|' % (self.lexer.char_to_string(c))) try: attributes.append('buffer=%s' % (string_util.quote(self.lexer.buffer_value()))) except AttributeError as ex: attributes.append('buffer=None') attributes.append('is_escaping=%s' % (self.lexer.is_escaping)) return ' '.join(attributes)
def get_value(self, what, filename, key): check.check_string(what) check.check_string(filename) check.check_string(key) table_name = self._table_name(what, filename) if not self._db.has_table(table_name): return None sql = 'select value from {table_name} where key={key}'.format( table_name=table_name, key=string_util.quote(key)) result = self._db.select_one(sql) if result is None: return None return result[0]
def log_handle_char(self, cr): try: buffer_value = string_util.quote(self.lexer.buffer_value()) except AttributeError as ex: buffer_value = 'None' self.log_d('handle_char() %s' % (self._make_log_attributes(cr)))
def encode_string(clazz, s, quoted = True): if s is None: return 'null' if quoted: return string_util.quote(s, quote_char = "'") return s
def _value_to_yaml_string(clazz, value): if clazz._value_is_number(value): return string_util.quote(value) return value
def _quoted_keys(clazz, kvl): return [string_util.quote(key) for key in kvl.all_keys()]
def value_to_text(self, key, value): if self._value_is_number(value): return string_util.quote(value, quote_char=self._QUOTE_CHAR) return value
def quote_strings(self): for i, kv in enumerate(self._values): if string_util.is_string(kv.value): self._values[i] = key_value(kv.key, string_util.quote(kv.value))
def quote(self): self._values = [string_util.quote(s) for s in self._values]
def _value_for_set(self, value): if self._string_quote_char: return string_util.quote(value, quote_char=self._string_quote_char) return value
def value_to_text(self, key, value): return string_util.quote(value, quote_char='"')