def compile(node, opts, enableBreaks=False, enableVerbose=False): options = opts options.prettypIndentString = eval("'" + options.prettypIndentString + "'") options.prettypCommentsInlinePadding = eval("'" + options.prettypCommentsInlinePadding + "'") # allow for escapes like "\t" # split trailing comment cols into an array if (options.prettypCommentsTrailingCommentCols and isinstance(options.prettypCommentsTrailingCommentCols, basestring)): options.prettypCommentsTrailingCommentCols = [int(column.strip()) for column in options.prettypCommentsTrailingCommentCols.split(",")] options.prettypCommentsTrailingCommentCols.sort() # make sure they are ascending! # or make sure it's a list of int's elif (isinstance(options.prettypCommentsTrailingCommentCols, list) and reduce(lambda y,z: y and z, [isinstance(x,int) for x in options.prettypCommentsTrailingCommentCols], True)): options.prettypCommentsTrailingCommentCols.sort() # make sure they are ascending! # or pass else: #raise TypeError, "Unsuitable type for option --pretty-print-comments-trailing-commentCols" pass result = [u""] if opts.prettyPrint: comment.fill(node) result = prettyM.prettyNode(node, opts, result) else: packer = Packer() result = packer.serializeNode(node, opts, result, enableBreaks) return u"".join(result)
def prettyNode(node, opts, rslt, enableBreaks=False, enableVerbose=False): global indent global result global pretty global verbose global breaks global afterLine global afterBreak global afterDoc global afterDivider global afterArea global options result = rslt options = opts opts.prettypIndentString = eval("'" + opts.prettypIndentString + "'") opts.prettypCommentsInlinePadding = eval( "'" + opts.prettypCommentsInlinePadding + "'") # allow for escapes like "\t" # split trailing comment cols into an array if (opts.prettypCommentsTrailingCommentCols and isinstance( opts.prettypCommentsTrailingCommentCols, basestring)): opts.prettypCommentsTrailingCommentCols = [ int(column.strip()) for column in opts.prettypCommentsTrailingCommentCols.split(",") ] opts.prettypCommentsTrailingCommentCols.sort( ) # make sure they are ascending! # or make sure it's a list of int's elif (isinstance(opts.prettypCommentsTrailingCommentCols, list) and reduce( lambda y, z: y and z, [isinstance(x, int) for x in opts.prettypCommentsTrailingCommentCols], True)): opts.prettypCommentsTrailingCommentCols.sort( ) # make sure they are ascending! # or pass else: #raise TypeError, "Unsuitable type for option --pretty-print-comments-trailing-commentCols" pass if opts.prettypCommentsBlockAdd: comment.fill(node) indent = 0 result = [u""] pretty = opts.prettyPrint verbose = enableVerbose breaks = enableBreaks afterLine = False afterBreak = False afterDoc = False afterDivider = False afterArea = False return _prettyNode(node, opts, result)
def serializeNode(node, opts, rslt, enableBreaks=False, enableVerbose=False): global indent global result global pretty global verbose global breaks global afterLine global afterBreak global afterDoc global afterDivider global afterArea global options result = rslt options = opts opts.prettypIndentString = eval("'" + opts.prettypIndentString + "'") opts.prettypCommentsInlinePadding = eval("'" + opts.prettypCommentsInlinePadding + "'") # allow for escapes like "\t" # split trailing comment cols into an array if (opts.prettypCommentsTrailingCommentCols and isinstance(opts.prettypCommentsTrailingCommentCols, basestring)): opts.prettypCommentsTrailingCommentCols = [int(column.strip()) for column in opts.prettypCommentsTrailingCommentCols.split(",")] opts.prettypCommentsTrailingCommentCols.sort() # make sure they are ascending! # or make sure it's a list of int's elif (isinstance(opts.prettypCommentsTrailingCommentCols, list) and reduce(lambda y,z: y and z, [isinstance(x,int) for x in opts.prettypCommentsTrailingCommentCols], True)): opts.prettypCommentsTrailingCommentCols.sort() # make sure they are ascending! # or pass else: #raise TypeError, "Unsuitable type for option --pretty-print-comments-trailing-commentCols" pass if opts.prettypCommentsBlockAdd: comment.fill(node) indent = 0 result = [u""] pretty = opts.prettyPrint verbose = enableVerbose breaks = enableBreaks afterLine = False afterBreak = False afterDoc = False afterDivider = False afterArea = False return [ Packer.symbol_base.emit(node) ] # caller expects []
def compile(node, opts, enableBreaks=False, enableVerbose=False): options = opts options.prettypIndentString = eval("'" + options.prettypIndentString + "'") options.prettypCommentsInlinePadding = eval( "'" + options.prettypCommentsInlinePadding + "'") # allow for escapes like "\t" # split trailing comment cols into an array if (options.prettypCommentsTrailingCommentCols and isinstance( options.prettypCommentsTrailingCommentCols, basestring)): options.prettypCommentsTrailingCommentCols = [ int(column.strip()) for column in options.prettypCommentsTrailingCommentCols.split(",") ] options.prettypCommentsTrailingCommentCols.sort( ) # make sure they are ascending! # or make sure it's a list of int's elif (isinstance(options.prettypCommentsTrailingCommentCols, list) and reduce(lambda y, z: y and z, [ isinstance(x, int) for x in options.prettypCommentsTrailingCommentCols ], True)): options.prettypCommentsTrailingCommentCols.sort( ) # make sure they are ascending! # or pass else: #raise TypeError, "Unsuitable type for option --pretty-print-comments-trailing-commentCols" pass result = [u""] if opts.prettyPrint: comment.fill(node) result = prettyM.prettyNode(node, opts, result) else: packer = Packer() result = packer.serializeNode(node, opts, result, enableBreaks) return u"".join(result)