<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def expand(template, variables=None):
 """ Expand a URL template string using the passed variables """

    if variables is None:
        variables = {}
    return patterns.sub(functools.partial(_replace, variables), template)