Beispiel #1
0
 def ssurt(self):
     '''
     Format this URL with a field order suitable for sorting.
     '''
     ssurt_host = urlcanon.ssurt_host(self.host)
     return (self.leading_junk + ssurt_host + self.slashes + self.port +
             self.colon_before_port + self.scheme + self.at_sign +
             self.username + self.colon_before_password + self.password +
             self.colon_after_scheme + self.path + self.question_mark +
             self.query + self.hash_sign + self.fragment +
             self.trailing_junk)
Beispiel #2
0
 def surt(self, trailing_comma=True, with_scheme=True):
     result = self.leading_junk
     if with_scheme:
         result += self.scheme + self.colon_after_scheme + self.slashes
     if self.host:
         surt_host = b''
         if with_scheme:
             surt_host += b'('
         surt_host += urlcanon.ssurt_host(self.host, trailing_comma)
         surt_host += self.colon_before_port + self.port
         result += surt_host + b')'
     result += (self.path + self.question_mark + self.query +
                self.hash_sign + self.fragment + self.trailing_junk)
     return result
Beispiel #3
0
    def surt_ancestry(self):
        # For now, we only support SURT parts for certain cases.
        if self.scheme not in urlcanon.SPECIAL_SCHEMES.keys():
            return []

        result = []
        parts = []

        # Build a list of all of the parts of the SURT.
        parts.append(self.scheme + self.colon_after_scheme + self.slashes)
        if self.host:
            parts.append(parts.pop() + b'(')
            for part in urlcanon.ssurt_host(self.host,
                                            trailing_comma=False).split(b','):
                parts.append(part + b',')
            # Closing paren is its own part to allow for incomplete and
            # incomplete hosts
            # (e.g: http://(com,examle) and http://(com,example )
            if self.port:
                parts.append(self.colon_before_port + self.port + b')')
            else:
                parts.append(b')')
        # Remove initial b'' which appears due to leading slash on the path.
        path_parts = self.path.split(b'/')
        if path_parts[0] == b'':
            path_parts.remove(b'')
        for part in path_parts:
            parts.append(b'/' + part)
        if self.query:
            parts.append(self.question_mark + self.query)
        if self.fragment:
            parts.append(self.hash_sign + self.fragment)
        if self.trailing_junk:
            parts.append(self.trailing_junk)

        # Build a list of SURT fragments.
        while parts != []:
            result.append(b''.join(parts))
            parts.pop()

        return result
Beispiel #4
0
def test_ssurt_host(host, ssurt_host):
    assert urlcanon.ssurt_host(host) == ssurt_host