OstrichLib Documentation

Similar documents
ffmpy3 Documentation Release Eric Ahn

ffmpy Documentation Andriy Yurchuk

monolith Documentation

CS Programming Languages: Python

Python Utils Documentation

pylatexenc Documentation

Python Utils Documentation

pybdg Documentation Release 1.0.dev2 Outernet Inc

Contents: 1 Basic socket interfaces 3. 2 Servers 7. 3 Launching and Controlling Processes 9. 4 Daemonizing Command Line Programs 11

System Workers. 1 of 11

semidbm Documentation

msgpack Documentation

FriendlyShell Documentation

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

pyvcd Documentation Release Peter Grayson and Steven Sprouse

IHIH Documentation. Release Romain Dartigues

Moulinette Documentation

pygenbank Documentation

Files. Files need to be opened in Python before they can be read from or written into Files are opened in Python using the open() built-in function

python-anyvcs Documentation

logstack Documentation

Python StatsD Documentation

Dogeon Documentation. Release Lin Ju

Cross-platform daemonization tools.

redis-lua Documentation

streamio Documentation

Python Mock Tutorial Documentation

ZeroVM Package Manager Documentation

Programming in Python

This is a list of questions and answers about Unicode in Perl, intended to be read after perlunitut.

python-unrar Documentation

rpaths Documentation Release 0.2 Remi Rampin

Chapter 1 - Introduction. September 8, 2016

tolerance Documentation

bottle-rest Release 0.5.0

IP address. Subnetting. Ping command in detail. Threads in Python. Sub process in Python

More Scripting and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

tld Documentation Release 0.9 Artur Barseghyan

print STDERR "This is a debugging message.\n";

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

edeposit.amqp.calibre Release 1.1.4

Slicing. Open pizza_slicer.py

man.m.sourcentral.org

pingparsing Documentation

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 4 (document version 1.1) Sockets and Server Programming using C

Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8

databuild Documentation

Fasteners Documentation

A shell can be used in one of two ways:

CIS192 Python Programming

xmodels Documentation

Uranium Documentation

filemagic Documentation

CIS192 Python Programming

htmlmin Documentation

translationstring Documentation

PySpec Documentation. Release Zac Stewart

yarl Documentation Release Andrew Svetlov

The WSGI Reference Library

Python Overpass API Documentation

Representing text on the computer: ASCII, Unicode, and UTF 8

COMP26120 Academic Session: Lab Exercise 2: Input/Output; Strings and Program Parameters; Error Handling

yagmail Documentation

Readline: Terminal Interaction

Sherlock Documentation

pymemcache Documentation

Python Print Decode Error - Output Not Utf-8

WordEmbeddingLoader Documentation

rpaths Documentation Release 0.13 Remi Rampin

Ertza Documentation. Release Benoit Rapidel, ExMachina

Standard File Pointers

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

What we already know. more of what we know. results, searching for "This" 6/21/2017. chapter 14

Lecture 03 Bits, Bytes and Data Types

viki-fabric-helpers Documentation

FIQL Parser. Release 0.15

Python StatsD Documentation

Asterisk IVR Documentation

IMAPClient Documentation

CSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Lazarus Documentation

pyds9 Documentation Release 1.8 Eric Mandel

1993: renamed "Java"; use in a browser instead of a microwave : Sun sues Microsoft multiple times over Java

FILE HANDLING AND EXCEPTIONS

argcomplete Documentation

CS 11 python track: lecture 2

Introduction to python

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

py-couchdb Documentation

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

needs to be reliable, easy to change, retarget efficiency is secondary implemented as interpreter, with virtual machine

edeposit.amqp.antivirus Release 1.0.1

Shell Programming (bash)

requests-cache Documentation

pymarc Documentation Release Ed Summers

Kuyruk Documentation. Release 0. Cenk Altı

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

pysharedutils Documentation

Commodity Documentation

Transcription:

OstrichLib Documentation Release 0.0.0 Itamar Ostricher May 10, 2016

Contents 1 utils package 3 1.1 collections utils module......................................... 3 1.2 path utils module............................................. 4 1.3 proc utils module............................................. 4 1.4 text utils module............................................. 5 2 Indices and tables 7 Python Module Index 9 i

ii

OstrichLib Documentation, Release 0.0.0 Mostly, just a bunch of useful Python functions. Come visit an Ostrich on GitHub! Contents 1

OstrichLib Documentation, Release 0.0.0 2 Contents

CHAPTER 1 utils package 1.1 collections utils module collections utils module A bunch of collections-related utility functions. Hazza! ostrich.utils.collections.listify(args) Return args as a list. If already a list - return as is. >>> listify([1, 2, 3]) [1, 2, 3] If a set - return as a list. >>> listify(set([1, 2, 3])) [1, 2, 3] If a tuple - return as a list. >>> listify(tuple([1, 2, 3])) [1, 2, 3] If a generator (also range / xrange) - return as a list. >>> listify(x + 1 for x in range(3)) [1, 2, 3] >>> from past.builtins import xrange >>> from builtins import range >>> listify(xrange(1, 4)) [1, 2, 3] >>> listify(range(1, 4)) [1, 2, 3] If a single instance of something that isn t any of the above - put as a single element of the returned list. >>> listify(1) [1] If empty (None or False or or anything else that evaluates to False), return an empty list ([]). >>> listify(none) [] 3

OstrichLib Documentation, Release 0.0.0 >>> listify(false) [] >>> listify('') [] >>> listify(0) [] >>> listify([]) [] 1.2 path utils module path utils module ostrich.utils.path.commonpath(paths) Return the longest common sub-path of each pathname in paths sequence. Raise ValueError if paths contains both absolute and relative pathnames, or if paths is empty. Unlike os.path.commonprefix(), this returns a valid path: >>> print(commonpath(['foo/bar', 'foo/baz', 'foo/baaam'])) foo >>> from os.path import commonprefix >>> print(commonprefix(['foo/bar', 'foo/baz', 'foo/baaam'])) foo/ba Adapted from the source code of Python 3.5.1. 1.3 proc utils module proc utils module An adaptation of Python 3.5 subprocess.run function source: https://github.com/python/cpython/blob/3.5/lib/subprocess.py exception ostrich.utils.proc.calledprocesserror(returncode, cmd, output=none, stderr=none) This exception is raised when a process run by run() with check=true returns a non-zero exit status. The exit status will be stored in the returncode attribute; The cmd (run args) will be stored in the cmd attribute; The output will be stored in output / stdout attribute; The stderr will be stored in stderr attribute. stdout Alias for output attribute, to match stderr class ostrich.utils.proc.completedprocess(args, returncode, stdout=none, stderr=none) A process that has finished running. This is returned by run(). Attributes: args: The list or str args passed to run(). returncode: The exit code of the process, negative for signals. stdout: The standard output (None if not captured). 4 Chapter 1. utils package

OstrichLib Documentation, Release 0.0.0 stderr: The standard error (None if not captured). check_returncode() Raise CalledProcessError if the exit code is non-zero. ostrich.utils.proc.run(*popenargs, **kwargs) Run command with arguments and return a CompletedProcess instance. The returned instance will have attributes args, returncode, stdout and stderr. By default, stdout and stderr are not captured, and those attributes will be None. Pass stdout=pipe and/or stderr=pipe in order to capture them. If check is True and the exit code was non-zero, it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute, and output & stderr attributes if those streams were captured. If timeout is given, and the process takes too long, a TimeoutExpired exception will be raised, if timeout is supported in the underlying Popen implementation (e.g. Python >= 3.2, or an available subprocess32 package). There is an optional argument input, allowing you to pass a string to the subprocess s stdin. If you use this argument you may not also use the Popen constructor s stdin argument, as it will be used internally. The other arguments are the same as for the Popen constructor. If universal_newlines=true is passed, the input argument must be a string and stdout/stderr in the returned object will be strings rather than bytes. 1.4 text utils module text utils module A collection of text-related utility functions. Hurray! ostrich.utils.text.as_text(str_or_bytes, encoding=u utf-8, errors=u strict ) Return input string as a text string. Should work for input string that s unicode or bytes, given proper encoding. >>> print(as_text(b'foo')) foo >>> b'foo'.decode('utf-8') == u'foo' True ostrich.utils.text.get_safe_path(in_str) Return in_str converted to a string that can be be safely used as a path (either filename, or directory name). >>> print(get_safe_path("hello world, what's up?.txt")) hello_world what_s_up_.txt Surrounding spaces are removed, and other bad characters are replaced with an underscore. The function attempts to replace unicode symbols (outside ASCII range) with ASCII equivalents (NFKD normalization). Everything else is also replaced with underscore. Warning The function just returns a safe string to be used as a path. It DOES NOT promise anything about the existence or uniqueness of the path in the filesystem! Because of the conversions, many input strings will result the same output string, so it is the responsibility of the caller to decide how to handle this! >>> get_safe_path(' foo/bar.baz') == get_safe_path('foo$bar.baz ') True 1.4. text utils module 5

OstrichLib Documentation, Release 0.0.0 6 Chapter 1. utils package

CHAPTER 2 Indices and tables genindex modindex search 7

OstrichLib Documentation, Release 0.0.0 8 Chapter 2. Indices and tables

Python Module Index o ostrich.utils.collections, 3 ostrich.utils.path, 4 ostrich.utils.proc, 4 ostrich.utils.text, 5 9

OstrichLib Documentation, Release 0.0.0 10 Python Module Index

Index A as_text() (in module ostrich.utils.text), 5 C CalledProcessError, 4 check_returncode() (ostrich.utils.proc.completedprocess method), 5 commonpath() (in module ostrich.utils.path), 4 CompletedProcess (class in ostrich.utils.proc), 4 G get_safe_path() (in module ostrich.utils.text), 5 L listify() (in module ostrich.utils.collections), 3 O ostrich.utils.collections (module), 3 ostrich.utils.path (module), 4 ostrich.utils.proc (module), 4 ostrich.utils.text (module), 5 R run() (in module ostrich.utils.proc), 5 S stdout (ostrich.utils.proc.calledprocesserror attribute), 4 11