mercurial/url.py
changeset 34694 2976cf87a60a
parent 34467 1232f7fa00c3
child 35443 e7bb5fc4570c
equal deleted inserted replaced
34693:56bb07a0b75c 34694:2976cf87a60a
    27 
    27 
    28 httplib = util.httplib
    28 httplib = util.httplib
    29 stringio = util.stringio
    29 stringio = util.stringio
    30 urlerr = util.urlerr
    30 urlerr = util.urlerr
    31 urlreq = util.urlreq
    31 urlreq = util.urlreq
       
    32 
       
    33 def escape(s, quote=None):
       
    34     '''Replace special characters "&", "<" and ">" to HTML-safe sequences.
       
    35     If the optional flag quote is true, the quotation mark character (")
       
    36     is also translated.
       
    37 
       
    38     This is the same as cgi.escape in Python, but always operates on
       
    39     bytes, whereas cgi.escape in Python 3 only works on unicodes.
       
    40     '''
       
    41     s = s.replace(b"&", b"&amp;")
       
    42     s = s.replace(b"<", b"&lt;")
       
    43     s = s.replace(b">", b"&gt;")
       
    44     if quote:
       
    45         s = s.replace(b'"', b"&quot;")
       
    46     return s
    32 
    47 
    33 class passwordmgr(object):
    48 class passwordmgr(object):
    34     def __init__(self, ui, passwddb):
    49     def __init__(self, ui, passwddb):
    35         self.ui = ui
    50         self.ui = ui
    36         self.passwddb = passwddb
    51         self.passwddb = passwddb