Tools for auto-processing and formatting PL/SQL code
create statement. Result of processing multi-object files is unpredictable, so all tools (except str_decoder) will raise an exception.The only function decode_to_str tries to detect line encoding and re-code it to UTF-8.
Raises ValueError if encoding is impossible.
decode_to_str(line, probables=None)
line - bytes object with a text to decodeprobables - list of str with primary encodings to check. Default: ['cp866', 'cp1251', 'koi8-r']str (decoded and re-encoded to UTF-8)Decoding whole file to another file. Run this to get list of arguments:
python -m oc_sql_helpers.str_decoder --help
PLSQLWrapper class is a tool to work with Oracle-wrapped sources.
There are additional requirements to wrap files. Note that unwrap methods are working without it. These are due to usage of original wrap utility from Oracle which is not included to this package due to license violation. You have to install it separately.
ORACLE_HOME environment variable is to be set correctlywrap binary is to be placed under ${ORACLE_HOME}/bin and must have execute permission for effective userPLSQLWrapper() - to instantiate an object for that class
Methods
wrap_path(path_in, write_to=None)
path_in - str object with absolute or relative path to file to wrap.write_to - one of:
None - the wrapping result will be returned by this method as bytes objectfile - result will be written to the file-like object specified here. Must be opened in read-write binary mode ('w+b') and support seek operation.str - path to output file, absolute or relative. Result will be written there. Must have an extension - this is Oracle wrap utility featrue. It appends .plb suffix on its own if an extension omitted. Please specify the extension alwayswrite_to abovewrap_buf(fl_in, write_to=None)
fl_in - file or file-like object to wrap data from. Must be opened in binary mode and support seek operation ('rb').write_to - the same as for wrap_pathwrap_pathunwrap_path(path_in, write_to=None)
path_in - str object with absolute or relative path to file to unwrap.write_to - one of:
None - the unwrapping result will be returned by this method as bytes objectfile - result will be written to the file-like object specified here. Must be opened in read-write binary mode ('w+b') and support seek operation.str - path to output file, absolute or relative. Result will be written there.write_to aboveunwrap_buf(fl_in, write_to=None)
fl_in - file or file-like object to wrap data from. Must be opened in binary mode and support seek operation ('rb').write_to - the same as for unwrap_pathunwrap_pathWrapping/unwrapping whole file to another file. Run this to get list of arguments:
python -m oc_sql_helpers.wrapper --help
PLSQLNormalizer class is or PL/SQL code normalization.
Normalization means almost the same as code style does, but less strictly. This means normalization result may be unusable even if source is correct one from PL/SQL point of view.
Default normalization is:
CREATE statement is removed.CREATE statement itself is ordered to the first line up to AS (or IS, or WRAPPED) token, including object name, type and schema. Extra space characters and comments are replaced with single space.CREATE statement) is UPPRCASED, including schema and object name." then those double-quotes will be removed where possible. Example: "schema"."name" will be SCHEMA.NAME after normalization, while "another.schema"."another.name" will have the doble quotes: "ANOTHER.SCHEMA"."ANOTHER.NAME"Another normalization flags:
uppercase: all language lexemes in object body will be uppercased except literalsno-comments: all comments inside the body, including comment signs themselves, will be replaced with single space.no-spaces: all repeating space-characters (space itself, newline, tabulation...) will be replaced with general single space. Example: var := 'the value' will be translated to var := 'the value'. Note that no replacement is done inside a literal 'the value'. This flag may not be used witout no-commentsno-literals: all string literal values will be replaced to empty ones. Literal signs themselves are not changed.comments-only: Discard the whole file content but comments, including comment signs themselves. Each comment will be started with a new line. This flag is not compatible with anyone abovePLSQLNormalizer() - to instantiate an object for this class
Methods
normalize_path(path, flags=None, lines=None, write_to=None)
path - str object with absolute or relative path to file to normalize.flags - normalization flags, list of integers from PLSQLNormalizationFlags enumeration, see below. None value means do default (CREATE definition) normalization only.lines - int, limit normalization lines (counted from source). Default: None, means normalize whole sourcewrite_to - one of:
None - the wrapping result will be returned by this method as bytes objectfile - result will be written to the file-like object specified here. Must be opened in read-write binary mode ('w+b') and support seek operation.str - path to output file, absolute or relative. Result will be written there. Must have an extension - this is Oracle wrap utility featrue. It appends .plb suffix on its own if an extension omitted. Please specify the extension alwayswrite_to abovenormalize(fl, flags, lines=None write_to=None)
fl - one of:
file or file-like object to normalize data from. Must be opened in binary mode and support seek operation ('rb').str - string data to normalizebytes - "binary" data to normalizeflags - the same as for normalize_pathlines - the same as for normalize_pathwrite_to - the same as for normalize_pathnormalize_pathis_sql(fl) - check the data given is supported PL/SQL code
fl - the same as for normalizebool, wrapped PL/SQL code or notis_sql_path(path) - the same as is_sql but argument is treated as a path to a file with possible codeis_wrapped(fl) - check the data given is supported wrapped PL/SQL code
fl - the same as for normalizebool, supported PL/SQL code or notis_wrapped_path(path) - the same as is_wrapped but argument is treated as a path to a file with possible codeis_wrappable(fl) - check the data given is supported wrapped PL/SQL code
fl - the same as for normalizebool, wrappable PL/SQL object in the code or notis_wrappable_path(path) - the same as is_wrappable but argument is treated as a path to a file with possible codePLSQLNormalizationFlags - enumeration of flags:
uppercaseno_commentsno_spacesno_literalscomments_onlySee detailed description above in Another normalization flags chapter from The Normalization Term section.
Normalizing whole file to another file. Run this to get list of arguments:
python -m oc_sql_helpers.normalizer --help