示例#1
0
def toPretty(self, optns, state):
    key = self.get("key")
    key_quote = self.get("quote", '')
    if key_quote:
        quote = '"' if key_quote == 'doublequotes' else "'"
    elif ( key in lang.RESERVED 
           or not identifier_regex.match(key)
           # TODO: or not lang.NUMBER_REGEXP.match(key)
         ):
        print "Warning: Auto protect key: %r" % key
        quote = '"'
    else:
        quote = ''
    value = self.getChild("value").toPretty(optns, state)
    return quote + key + quote + ':' + value
示例#2
0
def toPretty(self, optns, state):
    r = self.commentsPretty(optns, state)
    key = self.get("key")
    key_quote = self.get("quote", '')
    if key_quote:
        quote = '"' if key_quote == 'doublequotes' else "'"
    elif (key in lang.RESERVED or not identifier_regex.match(key)
          # TODO: or not lang.NUMBER_REGEXP.match(key)
          ):
        print "Warning: Auto protect key: %r" % key
        quote = '"'
    else:
        quote = ''
    value = self.getChild("value").toPretty(optns, state)
    return r + quote + key + quote + ' : ' + value
示例#3
0
def format(self, optns, state):
    r = self.commentsPretty(self.comments, optns, state)
    key = self.get("key")
    key_quote = self.get("quote", "")
    if key_quote:
        quote = '"' if key_quote == "doublequotes" else "'"
    elif (
        key in lang.RESERVED
        or not identifier_regex.match(key)
        # TODO: or not lang.NUMBER_REGEXP.match(key)
    ):
        print "Warning: Auto protect key: %r" % key
        quote = '"'
    else:
        quote = ""
    value = self.getChild("value").format(optns, state)
    return r + quote + key + quote + " : " + value