import re
import string


def strip_punc(s, all=False):
    """
    Removes punctuation from a string.
    :param s: The string.
    :param all: Remove all punctuation. If False, only removes punctuation from
        the ends of the string.
    """
    if all:
        return re.compile('[{0}]'.format(re.escape(string.punctuation))).sub('', s.strip())
    else:
        return s.strip().strip(string.punctuation)