def ensure_timezone(dt, tz=None):
if dt.tzinfo is None:<EOL><INDENT>return dt.replace(tzinfo=tz or tzlocal())<EOL><DEDENT>else:<EOL><INDENT>return dt<EOL><DEDENT>
Make sure the datetime <dt> has a timezone set, using timezone <tz> if it
doesn't. <tz> defaults to the local timezone.