GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Unparseable: local variable 'enc' referenced before assignment · Issue #41 · buriy/python-readability

Unparseable: local variable 'enc' referenced before assignment #41

New issue
Copy link
New issue
Copy link
Closed
Closed
Unparseable: local variable 'enc' referenced before assignment#41
Copy link

Description

@Telofy
Telofy
opened on Oct 10, 2013
Issue body actions

Hi there!

Extracting doesn’t work anymore when you predecode the strings. This looks pretty trivial though. enc could be initialized with None, unless that would cause any problems in other parts of the code.

By the way, I would discourage the use of the old chardet library. The range of encodings it can detect is very limited and it’s slow on top. I’ve found cchardet to be a lot better, but really there is the excellent UnicodeDammit library in BeautifulSoup that first tries to extract various explicit encoding specifications and then falls back on such implicit methods. Thanks to their latest refactoring, I could even remove a number of ugly hacks I needed to use the older version.

/home/telofy/.buildout/eggs/readability_lxml-0.3.0.1-py2.7.egg/readability/readability.pyc in summary(self, html_partial)
    152             ruthless = True
    153             while True:
--> 154                 self._html(True)
    155                 for i in self.tags(self.html, 'script', 'style'):
    156                     i.drop_tree()

/home/telofy/.buildout/eggs/readability_lxml-0.3.0.1-py2.7.egg/readability/readability.pyc in _html(self, force)
    117     def _html(self, force=False):
    118         if force or self.html is None:
--> 119             self.html = self._parse(self.input)
    120         return self.html
    121 

/home/telofy/.buildout/eggs/readability_lxml-0.3.0.1-py2.7.egg/readability/readability.pyc in _parse(self, input)
    121 
    122     def _parse(self, input):
--> 123         doc, self.encoding = build_doc(input)
    124         doc = html_cleaner.clean_html(doc)
    125         base_href = self.options.get('url', None)

/home/telofy/.buildout/eggs/readability_lxml-0.3.0.1-py2.7.egg/readability/htmls.pyc in build_doc(page)
     15         page_unicode = page.decode(enc, 'replace')
     16     doc = lxml.html.document_fromstring(page_unicode.encode('utf-8', 'replace'), parser=utf8_parser)
---> 17     return doc, enc
     18 
     19 def js_re(src, pattern, flags, repl):

Unparseable: local variable 'enc' referenced before assignment

Activity

  1. buriy
    added a commit that references this issue on Oct 10, 2013

    Quickfix for #41

    d8595b7
  2. buriy commented on Oct 10, 2013

    @buriy
    buriy
    on Oct 10, 2013
    Owner
    More actions

    Thanks. I applied the obvious quickfix.
    Will leave the ticket opened to check later if I can integrate UnicodeDammit into the package.
    Can UnicodeDammit guess the incorrect encoding specified in the headers?

  3. buriy
    closed this as completedon Oct 10, 2013
  4. buriy
    reopened this on Oct 10, 2013
  5. buriy commented on Oct 10, 2013

    @buriy
    buriy
    on Oct 10, 2013
    Owner
    More actions

    Hm... Won't like to edit this issue title... Created issue #42 to track UnicodeDammit, and closing this one.

  6. buriy
    closed this as completedon Oct 10, 2013
  7. oldcai commented on Nov 8, 2013

    @oldcai
    oldcai
    on Nov 8, 2013
    More actions

    @Telofy Hi, could you tell me how the exception print format can be set like yours, it's very clear and useful.

  8. buriy commented on Nov 8, 2013

    @buriy
    buriy
    on Nov 8, 2013
    Owner
    More actions

    @oldcai, I bet he uses ipython

  9. Telofy commented on Nov 8, 2013

    @Telofy
    Telofy
    on Nov 8, 2013
    Author
    More actions

    Hehe, correct. It’s the default in IPython.

  10. oldcai commented on Nov 8, 2013

    @oldcai
    oldcai
    on Nov 8, 2013
    More actions

    @buriy @Telofy Thanks, I'll have a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.