def peg_value(peg):
    """
    PEG revisions are natural numbers

    >>> peg_value('42')
    42
    >>> peg_value('')
    >>> peg_value(1)
    1
    >>> peg_value(0)
    Traceback (most recent call last):
    ...
    ValueError: peg revision needs to be >= 1 (0)
    >>> peg_value('PREV')
    Traceback (most recent call last):
    ...
    ValueError: peg revision must be a number >= 1 ('PREV')
    """
    if peg in (None, ''):
        return None
    try:
        val = int(peg)
    except ValueError:
        raise ValueError('peg revision must be a number >= 1 (%(peg)r)' %
            locals())
    else:
        if val <= 0:
            raise ValueError('peg revision needs to be >= 1 (%(val)r)' %
                locals())
        return val
