This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Declare our array | |
declare -A PARAMS | |
function parse_param() { | |
# Syntax: parse_param "PARAMETER=VALUE" | |
# Extract parameter and value and store it in Shell array" | |
local _PARAM=$1 | |
[[ "$_PARAM" == *"="* ]] || exit_on_error "Option -p must have the syntax PARAMETER=VALUE" | |
p=${_PARAM%=*} | |
v=${_PARAM#*=} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def root_sourceline(source, resolver=None): | |
"""Gets the starting line number of the start-tag of root | |
:param source: | |
:type source: file name/path, file object, file-like object, URL | |
:param etree.Resolver resolver: custom resolver | |
:return: (line number, column) | |
:rtype: tuple | |
""" | |
if hasattr(source, 'read'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<article xml:lang="en" version="5.0" | |
xmlns="http://docbook.org/ns/docbook" | |
xmlns:xi="http://www.w3.org/2001/XInclude" | |
xmlns:xlink="http://www.w3.org/1999/xlink"> | |
<title>Test</title> | |
<para xml:id="first"><glossterm>XML</glossterm></para> | |
<para xml:id="second">bla bla bla <glossterm>XML</glossterm></para> | |
<glossary> | |
<title>Glossary</title> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://crunchyfrog.googlecode.com/hg/utils/command/build_manpage.py | |
"""build_manpage command -- Generate man page from setup()""" | |
import datetime | |
from distutils.command.build import build | |
from distutils.core import Command | |
from distutils.errors import DistutilsOptionError | |
import optparse | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
# Taken from nosetest: see file nose/tools/nontrivial.py | |
class raises(object): | |
"""Test must raise one of expected exceptions to pass. | |
Example use:: | |
@raises(TypeError, ValueError) | |
def test_raises_type_error(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Use py.test: | |
# $ pytest test_mock.py | |
from unittest.mock import patch | |
import os.path | |
def my_isfile(filename): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Checks a given DocBook XML file for stylistic errors | |
Usage: | |
sdsc [-h | --help] | |
sdsc [options] INPUTFILE [OUTPUTFILE] | |
Required arguments: | |
INPUTFILE the DocBook XML file to check for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkgutil | |
import inspect | |
def members(module, predicate=None): | |
"""Yields all functions and classes of a module if predicate=None""" | |
def func_or_class(obj): | |
"""Inspects an object if it is a function or a class (=True), | |
otherwise False | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original source from http://asyncio.readthedocs.io/en/latest/producer_consumer.html | |
# Rewritten for Python >=3.4 | |
import asyncio | |
import random | |
@asyncio.coroutine | |
def produce(queue, n): | |
for x in range(n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Iterable | |
def flatten(items, ltypes=Iterable): | |
"""flatten(sequence) -> list | |
Returns a single, flat list which contains all elements retrieved from the sequence | |
""" | |
if not isinstance(items, list): | |
yield items | |
stack = [iter(items)] |
OlderNewer