<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def s3_url_context(service_endpoint, bucket=None, object_name=None):
 """ Create a URL based on the given service endpoint and suitable for the given bucket or object. @param service_endpoint: The service endpoint on which to base the resulting URL. @type service_endpoint: L{AWSServiceEndpoint} @param bucket: If given, the name of a bucket to reference. @type bucket: L{unicode} @param object_name: If given, the name of an object or object subresource to reference. @type object_name: L{unicode} """


    # Define our own query parser which can handle the consequences of
    # `?acl` and such (subresources).  At its best, parse_qsl doesn't
    # let us differentiate between these and empty values (such as
    # `?acl=`).
    def p(s):
        results = []
        args = s.split(u"&")
        for a in args:
            pieces = a.split(u"=")
            if len(pieces) == 1:
                results.append((unquote(pieces[0]),))
            elif len(pieces) == 2:
                results.append(tuple(map(unquote, pieces)))
            else:
                raise Exception("oh no")
        return results

    query = []
    path = []
    if bucket is None:
        path.append(u"")
    else:
        if isinstance(bucket, bytes):
            bucket = bucket.decode("utf-8")
        path.append(bucket)
        if object_name is None:
            path.append(u"")
        else:
            if isinstance(object_name, bytes):
                object_name = object_name.decode("utf-8")
            if u"?" in object_name:
                object_name, query = object_name.split(u"?", 1)
                query = p(query)
            object_name_components = object_name.split(u"/")
            if object_name_components[0] == u"":
                object_name_components.pop(0)
            if object_name_components:
                path.extend(object_name_components)
            else:
                path.append(u"")
    return _S3URLContext(
        scheme=service_endpoint.scheme.decode("utf-8"),
        host=service_endpoint.get_host().decode("utf-8"),
        port=service_endpoint.port,
        path=path,
        query=query,
    )