def METHOD_NAME(schema, u, s):
    c = URL(schema)
    parts = u.path.split("/")
    if len(parts) < 1 or len(parts) > 4:
        raise JujuError("charm or bundle URL has invalid form {}".format(s))
    # ~<username>
    if parts[0].startswith("~"):
        if schema == Schema.LOCAL:
            raise JujuError("local charm or bundle URL with username {}".format(s))
        c.user = parts[0][1:]
        parts = parts[1:]
    if len(parts) > 2:
        raise JujuError("charm or bundle URL has invalid form {}".format(s))
    # <series>
    if len(parts) == 2:
        c.series = parts[0]
        parts = parts[1:]
        # TODO (stickupkid) - validate the series.
    if len(parts) < 1:
        raise JujuError("URL without charm or bundle name {}".format(s))
    (c.name, c.revision) = extract_revision(parts[0])
    # TODO (stickupkid) - validate the name.
    return c