def py_to_go_cookie(py_cookie):
    '''Convert a python cookie to the JSON-marshalable Go-style cookie form.'''
    # TODO (perhaps):
    #   HttpOnly
    #   Creation
    #   LastAccess
    #   Updated
    # not done properly: CanonicalHost.
    go_cookie = {
        'Name': py_cookie.name,
        'Value': py_cookie.value,
        'Domain': py_cookie.domain,
        'HostOnly': not py_cookie.domain_specified,
        'Persistent': not py_cookie.discard,
        'Secure': py_cookie.secure,
        'CanonicalHost': py_cookie.domain,
    }
    if py_cookie.path_specified:
        go_cookie['Path'] = py_cookie.path
    if py_cookie.expires is not None:
        unix_time = datetime.datetime.fromtimestamp(py_cookie.expires)
        # Note: fromtimestamp bizarrely produces a time without
        # a time zone, so we need to use accept_naive.
        go_cookie['Expires'] = pyrfc3339.generate(unix_time, accept_naive=True)
    return go_cookie
Convert a python cookie to the JSON-marshalable Go-style cookie form.