1506N/A# The contents of this file are subject to the terms of the 1506N/A# Common Development and Distribution License (the "License"). 1506N/A# You may not use this file except in compliance with the License. 1506N/A# See the License for the specific language governing permissions 1506N/A# and limitations under the License. 1506N/A# When distributing Covered Code, include this CDDL HEADER in each 1506N/A# If applicable, add the following below this CDDL HEADER, with the 1506N/A# fields enclosed by brackets "[]" replaced with your own identifying 1506N/A# information: Portions Copyright [yyyy] [name of copyright owner] 3324N/A# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 1506N/A """This routine adds a transform tuple to the list used 1506N/A # make error messages familiar 3158N/A _(
"transform ({transform}) has regexp error " 3158N/A "({err}) in matching clause" 1506N/A # use closures to encapsulate desired operation 3158N/A _(
"transform ({0}) has 'drop' operation syntax error" 3158N/A _(
"transform ({0}) has 'set' operation syntax error" 3158N/A _(
"transform ({0}) has 'default' operation syntax error" 3158N/A _(
"transform ({0}) has 'add' operation syntax error" 3158N/A _(
"transform ({0}) has 'edit' operation syntax error" 3158N/A _(
"transform ({0}) has 'edit' operation syntax error" 1950N/A # Run args[1] (the regexp) through substitute_values() with a 1950N/A # bunch of bogus values to see whether it triggers certain 1950N/A # exceptions. If it does, then substitution would have 1950N/A # occurred, and we can't compile the regex now, but wait until 1950N/A # we can correctly run substitute_values(). 3158N/A _(
"transform ({transform}) has 'edit' operation " 1950N/A # It's now appropriate to compile the regexp, if there 1950N/A # are substitutions to be made. So do the substitution 3158N/A _(
"transform ({transform}) has edit " 2826N/A "operation with replacement string regexp " 3158N/A _(
"transform ({0}) has 'delete' operation syntax error" 3158N/A _(
"transform ({0}) has 'delete' operation syntax error" 3158N/A _(
"transform ({transform}) has 'delete' operation" 3158N/A _(
"transform ({transform}) has delete " 2826N/A "operation with replacement string regexp " 1949N/A """Substitute tokens in messages which can be expanded to the action's 1949N/A if " " in s
or "'" in s
or "\"" in s
or s ==
"":
1950N/A # Now see if there are any backreferences to match groups 3250N/A "%<{ref}> refers to an unmatched string" 1506N/A """Return specified attribute as list; 1506N/A an empty list if no such attribute exists""" 1506N/A """Apply all transforms to action, returning modified action 1506N/A or None if action is dropped""" 1506N/A # skip if types are specified and none match 1506N/A # skip if some attrs don't exist 1950N/A # Check to make sure all matching attrs actually match. The 1950N/A # order is effectively arbitrary, since they come from a dict. 1950N/A # Map each pattern to its position in the original match string. 1950N/A # Attributes might be quoted even if they don't need it, 1950N/A # and lead to a mis-match. These three patterns are all 1950N/A # safe to try. If we fail to find the match expression, 1950N/A # it's probably because it used different quoting rules 1950N/A # than the action code does, or from these three rules. 1950N/A # It might very well be okay, so we go ahead, but these 1950N/A # oddly quoted patterns will sort at the beginning, and 1950N/A # backref matching may be off. 3158N/A for qs in (
"{0}={1}",
"{0}=\"{1}\"",
"{0}='{1}'"):
1950N/A # Then sort the matches list by those positions. 1506N/A # time to apply transform operation 1949N/A # Any newly-created actions need to have the transforms applied, too. 1506N/A """ implement include hierarchy """ 1506N/A """Apply macro subs defined on command line... keep applying 1506N/A macros until no translations are found.""" 1506N/A break # look for more substitutions 1506N/A break # no more substitutable tokens 3263N/A """ return the lines in the file as a list of tuples containing 3263N/A (line, filename, line number); handle continuation and <include "path"> 3263N/A """Print the error message or raise the actual exception if no 3263N/A error printing callback specified.""" 3263N/A """Entry point for mogrify logic. 3263N/A file_args: input files to be mogrified. If not provided, use stdin 3263N/A ingoreincludes: whether to ignore <include ...> directives in input 3263N/A verbose: whether to include verbose action processing information 3263N/A in mogrify output. Useful for debug. 3263N/A includes: a list of directory paths used for searching include files. 3263N/A macros: a list of macros for substitution. 3263N/A printinfo: used to collect a list print info along processing. Could be 3263N/A output: used to collect mogrify output. Empty initially. 3263N/A error_cb: used to supply a error printing callback. 3263N/A sys_supply_files: used for other systems or modules to supply 1903N/A # doesn't handle nested macros