django.utils.six.moves.urllib.parse.urlsplit.netloc

Here are the examples of the python api django.utils.six.moves.urllib.parse.urlsplit.netloc taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: sayit
Source File: opengraph_tests.py
View license
    def assert_opengraph_matches(self, response, graph):
        """Check that the response matches the graph.

        The graph should be passed in as a dictionary of opengraph
        property name to a content test. The test can be either
          * A string - this must be equal to the content of that key, or
          * A compliled regular expression - which must be found in the
            content for that OpenGraph key in a regex search.

        For example:
        {
            'title': 'OpenGraph title of the page',
            'url:': re.compile('http://testing.example.com:8000/images/*.jpg'),
        }

        Extra items in the graph in resp will be ignored - we're only
        checking that everything in graph appears correctly.
        """
        # Keys that should be URLs if they exist
        url_keys = set((
            'url', 'image', 'audio', 'video', 'image:url',
            'image:secure_url', 'video:secure_url', 'audio:secure_url'))

        parser = lxml.html.HTMLParser(encoding='utf-8')
        root = lxml.html.fromstring(response.content, parser=parser)

        for key, test in graph.items():
            content = root.xpath(".//meta[@property='og:%s']/@content" % key)
            self.assertEqual(len(content), 1)
            content = content[0]

            if hasattr(test, 'pattern'):
                assertRegex(self, content, test)
            else:
                self.assertEqual(content, test)

            if key in url_keys:
                # Check that the url is absolute.
                self.assertTrue(
                    urllib.parse.urlsplit(content).netloc,
                    'og:%s must be an absolute URL, not %s' % (key, content)
                    )

Example 2

Project: sayit
Source File: opengraph_tests.py
View license
    def assert_opengraph_matches(self, response, graph):
        """Check that the response matches the graph.

        The graph should be passed in as a dictionary of opengraph
        property name to a content test. The test can be either
          * A string - this must be equal to the content of that key, or
          * A compliled regular expression - which must be found in the
            content for that OpenGraph key in a regex search.

        For example:
        {
            'title': 'OpenGraph title of the page',
            'url:': re.compile('http://testing.example.com:8000/images/*.jpg'),
        }

        Extra items in the graph in resp will be ignored - we're only
        checking that everything in graph appears correctly.
        """
        # Keys that should be URLs if they exist
        url_keys = set((
            'url', 'image', 'audio', 'video', 'image:url',
            'image:secure_url', 'video:secure_url', 'audio:secure_url'))

        parser = lxml.html.HTMLParser(encoding='utf-8')
        root = lxml.html.fromstring(response.content, parser=parser)

        for key, test in graph.items():
            content = root.xpath(".//meta[@property='og:%s']/@content" % key)
            self.assertEqual(len(content), 1)
            content = content[0]

            if hasattr(test, 'pattern'):
                assertRegex(self, content, test)
            else:
                self.assertEqual(content, test)

            if key in url_keys:
                # Check that the url is absolute.
                self.assertTrue(
                    urllib.parse.urlsplit(content).netloc,
                    'og:%s must be an absolute URL, not %s' % (key, content)
                    )