/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/urlutils.py

  • Committer: Jelmer Vernooij
  • Date: 2018-06-15 13:10:28 UTC
  • mto: (6973.12.2 python3-k)
  • mto: This revision was merged to the branch mainline in revision 6993.
  • Revision ID: jelmer@jelmer.uk-20180615131028-abolpmqrid8th0cd
More bees.

Show diffs side-by-side

added added

removed removed

Lines of Context:
154
154
 
155
155
def escape(relpath):
156
156
    """Escape relpath to be a valid url."""
157
 
    if not isinstance(relpath, str):
 
157
    if not isinstance(relpath, str) and sys.version_info[0] == 2:
158
158
        relpath = relpath.encode('utf-8')
159
159
    return quote(relpath, safe='/~')
160
160
 
593
593
    new_parameters.update(existing_parameters)
594
594
    for key, value in parameters.items():
595
595
        if not isinstance(key, str):
596
 
            raise TypeError("parameter key %r is not a bytestring" % key)
 
596
            raise TypeError("parameter key %r is not a str" % key)
597
597
        if not isinstance(value, str):
598
 
            raise TypeError("parameter value %r for %s is not a bytestring" %
 
598
            raise TypeError("parameter value %r for %s is not a str" %
599
599
                (key, value))
600
600
        if "=" in key:
601
601
            raise InvalidURLJoin("= exists in parameter key", url,
878
878
        :param url: URL as bytestring
879
879
        """
880
880
        # GZ 2017-06-09: Actually validate ascii-ness
881
 
        if not isinstance(url, str):
882
 
            raise InvalidURL('should be ascii:\n%r' % url)
 
881
        # pad.lv/1696545: For the moment, accept both native strings and unicode.
 
882
        if isinstance(url, str):
 
883
            pass
 
884
        elif isinstance(url, unicode):
 
885
            try:
 
886
                url = url.encode()
 
887
            except UnicodeEncodeError:
 
888
                raise InvalidURL(url)
 
889
        else:
 
890
            raise InvalidURL(url)
883
891
        (scheme, netloc, path, params,
884
892
         query, fragment) = urlparse.urlparse(url, allow_fragments=False)
885
893
        user = password = host = port = None