Return a parse of page.content. Wraps PyQuery.
330003
def parse(page_to_parse):
    """"""
    global _parsed
    if not isinstance(page_to_parse, page.Page):
        raise TypeError("parser.parse requires a parker.Page object.")

    if page_to_parse.content is None:
        raise ValueError("parser.parse requires a fetched parker.Page object.")

    try:
        parsed = _parsed[page_to_parse]
    except KeyError:
        parsed = parsedpage.ParsedPage(
            page=page_to_parse,
            parsed=PyQuery(page_to_parse.content, parser='html')
        )
        _parsed[page_to_parse] = parsed

    return parsed
816429
def parse_content(self, content):
        
        self.rows = []
        if len(content) < 2:
            self.no_data = True
            return

        # Parse header, remembering column numbers for data capture.  We use
        # a finditer to get the positions, and we find by field rather than
        # splitting on three or more spaces because of this.
        headers = []
        field_re = re.compile(r'\w+(\s\w+)*')
        for match in field_re.finditer(content[0]):
            headers.append({'name': match.group(), 'start': match.start()})

        # Parse the rest of the line.  Each field starts at the column
        # given by the header and ends with at least three spaces.
        for line in content[1:]:
            # I think the dictionary comprehension version of this is too
            # complicated for words :-)
            row = {}
            for header in headers:
                value = line[header['start']:].split('   ', 1)[0]
                if value == '':
                    value = None
                row[header['name']] = value
            self.rows.append(row)

        # If we have a key_field set, construct a data dictionary on it.
        # Note that duplicates will be overwritten, but we ignore '<none>'.
        if self.key_field and self.key_field in self.rows[0]:
            self.data = {}
            for row in self.rows:
                k = row[self.key_field]
                if k is not None and k != '<none>':
                    self.data[k] = row
856581
def decode_page(page):
    
    if hasattr(page, 'read'):  # urllib
        if py3k:
            encoding = page.headers.get_param("charset") or "utf-8"
        else:
            encoding = page.headers.getparam("charset") or "utf-8"
        return text_type(page.read(), encoding=encoding)
    else:  # requests?
        encoding = page.headers.get("charset") or "utf-8"
        return text_type(page.content, encoding=encoding)
910645
def page(self, page_number=0) -> list:
        
        # workaround flask-sqlalchemy/issues/516
        offset = page_number * self.limit
        sql = 'SELECT * FROM %s {} LIMIT :li OFFSET :o' \
            % (self.model.__tablename__)
        filter_query = self.__filter_query()
        if filter_query is None:
            sql = text(sql.format(''))
            result = self.model.db.engine.execute(
                sql, li=self.limit, o=offset)
        else:
            filter_query['binds']['li'] = self.limit
            filter_query['binds']['o'] = offset
            sql = text(sql.format(filter_query['query']))
            result = self.model.db.engine.execute(
                sql, **filter_query['binds'])
        result_keys = result.keys()
        result_models = []
        for row in result:
            model = self.model()
            key_count = 0
            for key in result_keys:
                setattr(model, key, row[key_count])
                key_count = key_count + 1
            result_models.append(model)
        return result_models
1349130
def parse_content(self, text):
        """"""
        match = re.search(
            self.usage_re_str.format(self.usage_name),
            text,
            flags=(re.DOTALL
                   if self.case_sensitive
                   else (re.DOTALL | re.IGNORECASE)))

        if match is None:
            return

        dic = match.groupdict()
        logger.debug(dic)
        self.raw_content = dic['raw']
        if dic['sep'] in ('\n', '\r\n'):
            self.formal_content = dic['section']
            return

        reallen = len(dic['name'])
        replace = ''.ljust(reallen)
        drop_name = match.expand('%s\\g<sep>\\g<section>' % replace)
        self.formal_content = self.drop_started_empty_lines(drop_name).rstrip()
611523
def get_instance(page_to_consume):
    """"""
    global _instances
    if isinstance(page_to_consume, basestring):
        uri = page_to_consume
        page_to_consume = page.get_instance(uri)
    elif isinstance(page_to_consume, page.Page):
        uri = page_to_consume.uri
    else:
        raise TypeError(
            "get_instance() expects a parker.Page or basestring derivative."
        )

    page_to_consume.fetch()
    parsed_page = parser.parse(page_to_consume)

    try:
        instance = _instances[uri]
    except KeyError:
        instance = ConsumePage(
            parsed_page
        )
        _instances[uri] = instance

    return instance
962152
def parse_resource_document(self, content):
        """"""

        content = content.strip()

        if not content.startswith('<html>'):
            # this is not a full HTML doc, probably content w/o title, tags, etc
            return dict(body=content)

        result = {}
        if '<title>' in content and '</title>' in content:
            result['subject'] = content[content.find('<title>') + 7:content.find('</title>')].strip()
        result['body'] = content[content.find('<body>') + 6:content.find('</body>')].strip()

        return result
48448
def _parse_result_page(self, url, payload, only_region=False):
        
        data = []
        try:

            if only_region:
                html = self.scraper._get_html(url)
            else:
                html = self.scraper._post_html(url, payload=payload)

        except RequestException500:

            self.scraper.log.warning(u"Status code 500 on {} with {}".format(url, payload))
            return None


        current_selection = self._get_current_selection(html)

        table = Datatable(html)
        data = []
        for row in table.data:
            region_or_unit_id, region_or_unit_label = row["region_or_unit"]
            if region_or_unit_label in self.regions:
                row["region"] = region_or_unit_label
                row["unit"] = None
            else:
                row["region"] = None
                row["unit"] = region_or_unit_label

            value = row["value"]

            row.pop("value", None)
            row.pop("region_or_unit", None)

            for dim in self.dimensions:
                if dim.id not in row:
                    row[dim.id] = current_selection[dim.id][1] # gets label



            data.append(Result(value, row))
        return data
741360
def _get_content(context, page, content_type, lang, fallback=True):
    """"""
    if not page:
        return ''

    if not lang and 'lang' in context:
        lang = context.get('lang', pages_settings.PAGE_DEFAULT_LANGUAGE)

    page = get_page_from_string_or_id(page, lang)

    if not page:
        return ''

    content = Content.objects.get_content(page, lang, content_type, fallback)
    return content
194040
def get_content(self):
        """"""
        url = self.build_url()
        try:
            self.content_page = requests.get(url)
            if not(self.content_page.status_code == requests.codes.ok):
                self.content_page.raise_for_status()
        except requests.exceptions.RequestException as ex:
            logging.info('A requests exception has ocurred: ' + str(ex))
            logging.error(traceback.format_exc())
            sys.exit(0)
469107
def _parse_content(self, text):
        '''
        '''
        try:
            return json.loads(text)
        except ValueError:
            raise exc.UnexpectedlyNotJSON(
                "The resource at {.uri} wasn't valid JSON", self)
784021
def _get_page_elements(self):
        
        page_elements = []
        for attribute, value in list(self.__dict__.items()) + list(self.__class__.__dict__.items()):
            if attribute != 'parent' and isinstance(value, CommonObject):
                page_elements.append(value)
        return page_elements
4186
def pq(self) -> PyQuery:
        
        if self._pq is None:
            self._pq = PyQuery(self.raw_xml)

        return self._pq
594792
def content(self):
        """"""
        return _content.Content(url=self._url + "/content",
                                securityHandler=self._securityHandler,
                                proxy_url=self._proxy_url,
                                proxy_port=self._proxy_port)
552278
function parsePage(book, page) {
    var fs = book.getContentFS();
    var file = page.getFile();

    return fs.readAsString(file.getPath())
    .then(function(content) {
        return parsePageFromString(page, content);
    });
}
452036
def parse(self, content):
    
    if self.format == 'json_map':
      try:
        return assert_list(json.loads(content.decode(self.encoding))[self.index])
      except (KeyError, UnicodeDecodeError, ValueError) as e:
        raise self.ResponseParserError("Error while parsing response content: {0}".format(str(e)))

    # Should never get here.
    raise ValueError('Unknown content format: "{}"'.format(self.format))
1176090
def response(self, url):
        """"""
        
        resp = requests.get(url).content
        return self.parseresponse(resp)