Exemple #1
0
 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='"'))
Exemple #2
0
  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)
Exemple #4
0
 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)
Exemple #5
0
 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)))
Exemple #7
0
 def encode_string(clazz, s, quoted = True):
   if s is None:
     return 'null'
   if quoted:
     return string_util.quote(s, quote_char = "'")
   return s
Exemple #8
0
 def _value_to_yaml_string(clazz, value):
     if clazz._value_is_number(value):
         return string_util.quote(value)
     return value
Exemple #9
0
 def _quoted_keys(clazz, kvl):
     return [string_util.quote(key) for key in kvl.all_keys()]
Exemple #10
0
 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
Exemple #11
0
 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))
Exemple #12
0
 def quote(self):
     self._values = [string_util.quote(s) for s in self._values]
Exemple #13
0
 def _value_for_set(self, value):
     if self._string_quote_char:
         return string_util.quote(value, quote_char=self._string_quote_char)
     return value
Exemple #14
0
 def value_to_text(self, key, value):
     return string_util.quote(value, quote_char='"')