perllib package¶
Module contents¶
- perllib.Dumper(*args)[source]¶
Implementation of Data::Dumper
- class perllib.File_stat(_dev: int, _ino: int, _mode: int, _nlink: int, _uid: int, _gid: int, _rdev: int, _size: int, _atime: int, _mtime: int, _ctime: int, _blksize: int, _blocks: int)[source]¶
Bases:
Sequence
- perllib.IOFile_open(fh, filename, mode=None, perms=None)[source]¶
Implementation of perl $fh->open method
- perllib.add_tie_call(func, package)[source]¶
Add a call to _tie_call for functions defined in a tie package
- perllib.add_tie_methods(obj)[source]¶
Create a subclass for the object and add the methods to it to implement ‘tie’, like __getitem__ etc. The call to this functions is generated on any ‘return’ statement (or implicit return) in TIEHASH or TIEARRAY
- perllib.assign_global(packname, varname, value)[source]¶
Assigns a value to a package global variable and returns the value
- perllib.assign_hash(h, keys, values)[source]¶
Assign a hash with a list of hash keys and a list of values
- perllib.assign_meta(packname, varname, value)[source]¶
Assigns a value in the metaclass of a package global variable and returns the value. Creates the metaclass if need be. This is use for tie $scalar
- perllib.assign_sparse(lst, indexes, values)[source]¶
Assign a list with a sparse list of indexes and a list of values
- perllib.chomp_element(base, index, value)[source]¶
Implementation of perl = and chomp on an array element
- perllib.chomp_global(packname, varname, value)[source]¶
Assigns a value to a package global variable, does a chomp and returns the number of chars chopped
- perllib.chomp_with_result(var)[source]¶
Implementation of chomp where the count of chars removed is needed. Returns a tuple of (result, count).
- perllib.chop_element(base, index, value)[source]¶
Implementation of perl = and chop on an array element
- perllib.chop_global(packname, varname, value)[source]¶
Assigns a value to a package global variable, does a chop and returns the value chopped
- perllib.chop_with_result(var)[source]¶
Implementation of chop where the last char removed is needed. Returns a tuple of (result, last_c).
- perllib.chop_without_result(var)[source]¶
Implementation of chop where the last char removed is not needed. Returns a tuple of (result, ‘’).
- perllib.curdir()[source]¶
Implementation of File::Spec->curdir
- perllib.dirname(fullname)[source]¶
Emulation of File::Basename qw(dirname) for unix
- perllib.dup(file, mode, checked=True, equals=False, encoding=None, errors=None)[source]¶
Replacement for perl built-in open function when the mode contains ‘&’. Keyword arg ‘checked’ means the result will be checked. Keyword arg ‘equals’ means that ‘&=’ was specified, so skip the os.dup operation.
- perllib.extract_bracketed(text, delimiters='{}()[]<>', prefix_pattern='^\\s*')[source]¶
Implementation of Text::Bracketed::extract_bracketed in list context. Returns a list with (extracted_substring, updated_text, skipped_prefix)
- perllib.extract_bracketed_s(text, delimiters='{}()[]<>', prefix_pattern='^\\s*')[source]¶
Implementation of Text::Bracketed::extract_bracketed in scalar context. Returns a tuple with (updated_text, extracted_substring)
- perllib.fetch_out_parameter(arg)[source]¶
Fetch the value of a sub out parameter from the location where _store_out_parameter saved it. This is called after the sub returns. arg is the argument index, starting at 0. Returns the value we saved.
- perllib.fetch_out_parameters(var, start=0)[source]¶
Fetch the values of all sub out parameters from the location where _store_out_parameter saved them. This is called after the sub returns. var is the array or hash to store them in. start is the argument starting index, defaulting to 0. Returns the array or hash we saved.
- perllib.fetch_perl_global(perlname)[source]¶
Fetch the value of a package global variable specified by it’s perl name
- perllib.fileinput_next(files=None, inplace=False, backup='', *, mode='r', openhook=None, encoding=None, errors=None)[source]¶
Implementation of fileinput.input() where it can be called multiple times for the same <> operator
- perllib.fileparse(*args)[source]¶
Split a path into basename, dirpath, and (optional) suffixes. Translated from perl File::Basename for unix, plus annotations
- perllib.filter_map(f, i)[source]¶
Given a function f that returns a tuple of (new_val, include) and an iterable i, return an iterable of new_vals where include is True
- perllib.finditer_next(pattern, string, flags=0)[source]¶
Implementation of re.finditer() where it can be called multiple times for the same pattern and string
- perllib.flt(expr)[source]¶
Convert expr to a float number Ref: https://squareperl.com/en/how-perl-convert-string-to-number
- perllib.format_(fmt, args=None)[source]¶
Like % formatter in python, but auto-converts the args to the proper types
- perllib.get_element(base, index)[source]¶
Safe element getter from a list, tuple, or Array - returns None if the element doesn’t exist
- perllib.get_subref(ref)[source]¶
Convert a sub reference to a callable sub. ‘ref’ may already be callable or it could be the name of the sub. Returns None if the sub isn’t callable
- perllib.handle_open_pragma(mode, encoding, errors, newline='\n')[source]¶
Handle any “use open” pragma that may be in effect
- perllib.hires_alarm(floating_seconds, interval_floating_seconds=0)[source]¶
Implementation of Time::HiRes::alarm
- perllib.hires_getitimer_s(which)[source]¶
Implementation of Time::HiRes::getitimer in scalar context
- perllib.hires_setitimer_s(which, floating_seconds, interval_floating_seconds=0)[source]¶
Implementation of Time::HiRes::setitimer in scalar context
- perllib.import_(globals, path, module=None, fromlist=None, version=None, is_do=False)[source]¶
Handle use/require statement from perl. ‘path’ is the relative or absolute path to the .py file of the module (the extension is ignored if specified). If ‘module’ is specified, then that is effectively added to the path, ‘fromlist’ is the list of desired functions to import. ‘version’ will perform a version check. ‘is_do’ handles a ‘do EXPR;’ statement.
- perllib.init_global(packname, varname, value)[source]¶
Return the proper value to initialize a package global variable only once
- perllib.init_out_parameters(arglist, *_args)[source]¶
Initialize sub’s out parameters. Pass the arglist of the sub and a list of the sub’s out parameters, counting from 0. If no list is passed, then all args are assumed to be out parameters
- perllib.init_package(name, is_class=False, isa=(), autovivification=True)[source]¶
Initialize a package by creating a namespace for it
- perllib.lcfirst(string)[source]¶
Implementation of lcfirst and l in interpolated strings: lowercase the first char of the given string
- perllib.list_of_at_least_n(lst, n)[source]¶
For assignment to (list, …, *last) - make this list at least the right size.
- perllib.lstat(path)[source]¶
Handle lstat call with or without “use File::stat;”
- perllib.make_list(*args)[source]¶
For push/unshift @arr, expr; We use extend/[0:0] so make sure expr is iterable
- perllib.maketrans_c(arg1, arg2, delete=False)[source]¶
Make a complement tr table for the ‘c’ flag. If the ‘d’ flag is passed, then delete=True. Ranges are expanded in arg1 and arg2 but arg2 is not otherwise normalized
- perllib.method_call(cls_or_obj, methodname, *args, **kwargs)[source]¶
Call a method by name in a class that can also be specified by name
- perllib.mkdtemp(template)[source]¶
Implementation of File::Temp::mkdtemp()
- perllib.mkstemp(template)[source]¶
Implementation of File::Temp::mkstemp()
- perllib.mkstemps(template, suffix)[source]¶
Implementation of File::Temp::mkstemps()
- perllib.mktemp(template)[source]¶
Implementation of File::Temp::mktemp()
- perllib.num(expr)[source]¶
Convert expr to a number Ref: https://squareperl.com/en/how-perl-convert-string-to-number
- perllib.open_(file, mode, encoding=None, errors=None, checked=True, newline='\n')[source]¶
Replacement for perl built-in open function when the mode is known.
- perllib.open_dynamic(file, mode=None, encoding=None, errors=None, checked=True)[source]¶
Replacement for perl built-in open function when the mode is unknown.
- perllib.openhandle(fh)[source]¶
Return the file handle if this is an opened file handle, else return None
- perllib.overload_Method(obj, op)[source]¶
Given an object and an operation string, return a reference to the code if it’s overloaded, else return None
- perllib.overload_Overloaded(obj)[source]¶
Given an object, return 1 if it has any overloads defined, else return ‘’
- perllib.package_call(package, function, *args, **kwargs)[source]¶
Call a function in a different package
- perllib.perl_print(*args, **kwargs)[source]¶
Replacement for perl built-in print/say/warn functions. Note that by default this acts like ‘say’ in that it appends a newline. To prevent the newline, pass the end=’’ keyword argument. To write to a different file, pass the file=… keyword argument. To flush the output after writing, pass flush=True. To replace the OUTPUT_FIELD_SEPARATOR, pass sep=’…’. It returns 1 if successful
- perllib.postprocess_arguments(parser, parser_rem)[source]¶
After argument parsing, see if we have any leftover arguments and flag those as errors
- perllib.preprocess_arguments()[source]¶
Pre-process the command line arguments, changing -option to –option
- perllib.quotemeta(string)[source]¶
Implementation of perl quotemeta - all chars not matching /[A-Za-z_0-9]/ will be preceded by a backslash
- perllib.range_(var, pat1, flags1, pat2, flags2, key)[source]¶
The line-range operator. See https://perldoc.perl.org/perlop#Range-Operators
- perllib.read(fh, var, length, offset=0, need_len=False)[source]¶
Read length bytes from the fh, and return the result to store in var if need_len is False, else return a tuple with the result and the length read
- perllib.readline(fh)[source]¶
Reads a line from a file. (instead use _readline_full if you need support for perl $/ or $.)
- perllib.readlink(path)[source]¶
Returns the value of a symbolic link. If there is a system error, returns the undefined value and sets OS_ERROR (errno).
- perllib.ref_scalar(r)[source]¶
ref function in perl - called when being passed a scalar without a backslash
- perllib.set_breakpoint()[source]¶
Sets a debugger breakpoint, but only if pdb is active, mimicking $DB::single
- perllib.set_element(base, index, value)[source]¶
Implementation of perl = on an array element or hash key
- perllib.set_last_ndx(arr, ndx)[source]¶
Implementation of assignment to perl array last index $#array
- perllib.set_signal(sig, handler)[source]¶
Set a signal handler to either a code reference or a string containing a perl code name or IGNORE or DEFAULT
- perllib.split(pattern, string, maxsplit=0, flags=0)[source]¶
Split function in perl is similar to re.split but not quite the same - this function makes it the same
- perllib.split_s(pattern, string, maxsplit=0, flags=0)[source]¶
Split function in perl is similar to re.split but not quite the same - this is the version used in scalar context
- perllib.splitdir(*_args)[source]¶
Implementation of File::Spec->splitdir
- perllib.splitpath(*_args)[source]¶
Implementation of File::Spec->splitpath
- perllib.stat(path)[source]¶
Handle stat call with or without “use File::stat;”
- perllib.stat_cando(self, mode, eff)[source]¶
Implementation of File::Stat::stat_cando. This takes an arrayref containing the return values of stat or lstat as its first argument, and interprets it for you
- perllib.store_out_parameter(arglist, arg, value, shifts=0)[source]¶
Store the value of a sub out parameter both in the arglist and in a location where _fetch_out_parameter can retrieve it after the sub returns. arg is the argument index, starting at 0, and value is the value to be stored. shifts specifies the number of shift operations that have been performed on the arglist. Returns the value.
- perllib.store_perl_global(perlname, value, infer_suffix=False, method_type=False)[source]¶
Assigns a value to a package global variable specified by it’s perl name and returns the value. Optional keyword argument infer_suffix will map the variable’s suffix based on the type of the value, e.g. it will add _h for a hash. Optional keyword argument method_type will set this to a MethodType if True, or will check if the name is ‘new’ or ‘make’ and set this to a MethodType if None
- perllib.store_perl_meta(perlname, value, infer_suffix=False)[source]¶
Assigns a value to a package meta variable specified by it’s perl name and returns the value. Optional keyword argument infer_suffix will map the variable’s suffix based on the type of the value, e.g. it will add _h for a hash. This is used for tie ${“${pkg}::$scalarname”}
- perllib.strftime(fmt, sec, min=None, hour=None, mday=None, mon=None, year=None, wday=0, yday=0, isdst=0)[source]¶
Implementation of perl strftime
- perllib.substitute_and_count(this, that, var, replace=True, count=0)[source]¶
Perform a re substitute, but also count the # of matches
- perllib.substitute_element(base, index, this, that, count=0, replace=True)[source]¶
Perform a re substitution on an array element or hash value, and also count the # of matches
- perllib.substitute_global(packname, varname, this, that, replace=True, count=0)[source]¶
Perform a re substitute on a global, and also count the # of matches
- perllib.substr(this, start, length, replacement)[source]¶
Handle substr with replacement - returns a tuple with (new_this, chars_removed)
- perllib.switch(s_val)[source]¶
Implementation of switch/given statement in perl. This returns a function that is called for each case.
- perllib.sysread(fh, var, length, offset=0, need_len=False)[source]¶
Read length bytes from the fh, and return the result to store in var if need_len is False, else return a tuple with the result and the length read. For compatability with perl, the result is returned as a str, not bytes.
- perllib.tempdir(*args)[source]¶
Implementation of File::Temp::tempdir()
- perllib.tempfile_(*args)[source]¶
Implementation of File::Temp::tempfile() in list context
- perllib.tempfile_s(*args)[source]¶
Implementation of File::Temp::tempfile() in scalar context
- perllib.tempnam(template, suffix)[source]¶
Implementation of File::Temp::tempnam()
- perllib.tie_call(func, _args, _kwargs=None)[source]¶
Call a function in a package that uses TIEARRAY or TIEHASH. This is an internal routine whose call is automatically generated.
- perllib.timegm(sec, min, hour, mday, mon, year, wday=0, yday=0, isdst=0)[source]¶
Replacement for perl built-in timegm function
- perllib.timelocal(sec, min, hour, mday, mon, year, wday=0, yday=0, isdst=0)[source]¶
Replacement for perl built-in timelocal function
- perllib.tmpfile()[source]¶
Implementation of File::Temp tmpfile()
- perllib.translate(table, var, replace=True, complement=False, delete=False, squash=False)[source]¶
Perform a tr translate operation
- perllib.translate_and_count(table, var, replace=True, complement=False, delete=False, squash=False)[source]¶
Perform a tr translate, but also count the # of matches
- perllib.translate_element(base, index, table, replace=True, complement=False, delete=False, squash=False)[source]¶
Perform a tr translate on an array element, and also count the # of matches
- perllib.translate_global(packname, varname, table, replace=True, complement=False, delete=False, squash=False)[source]¶
Perform a tr translate on a global, and also count the # of matches
- perllib.ucfirst(string)[source]¶
Implementation of ucfirst and u in interpolated strings: uppercase the first char of the given string
- perllib.unassign_meta(packname, varname)[source]¶
Unassigns a variable in the metaclass of a package global variable. This is use for untie $scalar
- perllib.unpack(template, bytestr)[source]¶
Unpack bytestr using the template and return a list of values
- perllib.updir()[source]¶
Implementation of File::Spec->updir
- perllib.utf8_downgrade(s, fail_ok=False)[source]¶
Implementation of utf8::downgrade. Returns a tuple of string and success
- perllib.utf8_native_to_unicode(c)[source]¶
Implementation of utf8::native_to_unicode. Returns it’s argument
- perllib.utf8_unicode_to_native(c)[source]¶
Implementation of utf8::unicode_to_native. Returns it’s argument