/usr/lib/python2.7/dist-packages/uritools/defrag.py is in python-uritools 1.0.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | from __future__ import unicode_literals
import collections
from .encoding import uridecode
class DefragResult(collections.namedtuple('DefragResult', 'uri fragment')):
"""Class to hold :func:`uridefrag` results."""
__slots__ = () # prevent creation of instance dictionary
def geturi(self):
"""Return the recombined version of the original URI as a string."""
fragment = self.fragment
if fragment is None:
return self.uri
elif isinstance(fragment, bytes):
return self.uri + b'#' + fragment
else:
return self.uri + '#' + fragment
def getfragment(self, default=None, encoding='utf-8', errors='strict'):
"""Return the decoded fragment identifier, or `default` if the
original URI did not contain a fragment component.
"""
fragment = self.fragment
if fragment is not None:
return uridecode(fragment, encoding, errors)
else:
return default
def uridefrag(uristring):
"""Remove an existing fragment component from a URI string."""
if isinstance(uristring, bytes):
parts = uristring.partition(b'#')
else:
parts = uristring.partition('#')
return DefragResult(parts[0], parts[2] if parts[1] else None)
|