Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError when Parsing an Email Address #29

Closed
sfstpala opened this issue Jun 27, 2011 · 4 comments
Closed

NameError when Parsing an Email Address #29

sfstpala opened this issue Jun 27, 2011 · 4 comments
Milestone

Comments

@sfstpala
Copy link

I'm getting a NameError when trying to parse an email address like this:

markdown.markdown("<bug@markdown.com>")

Here's the complete traceback:

>>> import markdown
>>> markdown.markdown("<bug@markdown.com>")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/markdown/__init__.py", line 598, in markdown
    return md.convert(text)
  File "/usr/local/lib/python3.2/dist-packages/markdown/__init__.py", line 395, in convert
    newRoot = treeprocessor.run(root)
  File "/usr/local/lib/python3.2/dist-packages/markdown/treeprocessors.py", line 271, in run
    text), child)
  File "/usr/local/lib/python3.2/dist-packages/markdown/treeprocessors.py", line 95, in __handleInline
    data, patternIndex, startIndex)
  File "/usr/local/lib/python3.2/dist-packages/markdown/treeprocessors.py", line 219, in __applyPattern
    node = pattern.handleMatch(match)
  File "/usr/local/lib/python3.2/dist-packages/markdown/inlinepatterns.py", line 363, in handleMatch
    letters = [codepoint2name(ord(letter)) for letter in email]
  File "/usr/local/lib/python3.2/dist-packages/markdown/inlinepatterns.py", line 363, in <listcomp>
    letters = [codepoint2name(ord(letter)) for letter in email]
  File "/usr/local/lib/python3.2/dist-packages/markdown/inlinepatterns.py", line 357, in codepoint2name
    entity = html.entities.codepoint2name.get(code)
NameError: global name 'html' is not defined

Links of the same format, <url>, work well.

Hope this helps to solve the Problem. In the meantime, any workarounds would be appreciated.

This is Python Markdown 2.0.3 running on Python 3.2

@waylan
Copy link
Member

waylan commented Jun 27, 2011

How did you install markdown?

Was the 2to3 tool run on the source before installation?

If I recall correctly the import path for html.entities is one of the
things the 2to3 tool changes, which suggests to me that the 2to3 tool
wasn't run before installation.

Unfortunately, when we released Markdown 2.0.3 we had not yet set up
the installation so that the 2to3 tool would run automatically. This
has since been rectified and will be available in our next release.

On Mon, Jun 27, 2011 at 6:10 AM, sfstpala
reply@reply.github.com
wrote:

I'm getting a NameError when trying to parse an email address like this:

   markdown.markdown("bug@markdown.com")

Here's the complete traceback:

   >>> import markdown
   >>> markdown.markdown("bug@markdown.com")
   Traceback (most recent call last):
     File "", line 1, in
     File "/usr/local/lib/python3.2/dist-packages/markdown/init.py", line 598, in markdown
       return md.convert(text)
     File "/usr/local/lib/python3.2/dist-packages/markdown/init.py", line 395, in convert
       newRoot = treeprocessor.run(root)
     File "/usr/local/lib/python3.2/dist-packages/markdown/treeprocessors.py", line 271, in run
       text), child)
     File "/usr/local/lib/python3.2/dist-packages/markdown/treeprocessors.py", line 95, in __handleInline
       data, patternIndex, startIndex)
     File "/usr/local/lib/python3.2/dist-packages/markdown/treeprocessors.py", line 219, in __applyPattern
       node = pattern.handleMatch(match)
     File "/usr/local/lib/python3.2/dist-packages/markdown/inlinepatterns.py", line 363, in handleMatch
       letters = [codepoint2name(ord(letter)) for letter in email]
     File "/usr/local/lib/python3.2/dist-packages/markdown/inlinepatterns.py", line 363, in
       letters = [codepoint2name(ord(letter)) for letter in email]
     File "/usr/local/lib/python3.2/dist-packages/markdown/inlinepatterns.py", line 357, in codepoint2name
       entity = html.entities.codepoint2name.get(code)
   NameError: global name 'html' is not defined

Hope this helps. In the meantime, any workarounds would be appreciated.

This is Markdown 2.0.3 running on Python 3.2

Reply to this email directly or view it on GitHub:
#29


\X/ /-\ `/ |_ /-\ ||
Waylan Limberg

@sfstpala
Copy link
Author

The Code I'm using comes from EnigmaCurry's repo. It's supposedly nothing more than 2.0.3 run through 2to3. Should I do it differently until the next release?

On a side note: Perhaps you should remove the Python 3 tag from the PyPI entry until the usual installation works.

Thanks a lot for the prompt reply. It's a big help, since I have this version of Python Markdown running on a production server.

@waylan
Copy link
Member

waylan commented Jun 27, 2011

Ok, I just looked at the source (and EnigmaCurry's repo - interesting I didn't know it existed). The problem stems from a bug in the 2to3 tool which shipped with Python 3.0, which was the only version available when we shipped Markdown 2.0.3. That bug has since been fixed in Python 3.1. Unfortunately, the fix in the Python 3.1+ version of the 2to3 tool broke our workaround.

As we have already fixed this in our repo (next release coming soon), I'd suggest filing a bug report with EnigmaCurry to fix the import in markdown/inlinepatterns.py line 48. Probably something like this (untested):

+ import html
- if sys.version >= "3.0":
-     from html import entities as htmlentitydefs
- else:
-     import html.entities

Regarding our claim to support Python 3.0. That is correct, Markdown 2.0.3 only supports (the buggy) Python 3.0, not 3.1 or greater. Therefore, I will not be changing our note in that regard. However, our next release will not support Python 3.0 but will support Python3.1 or greater.

As there is no issue for use to fix here, I'm closing this.

@waylan waylan closed this as completed Jun 27, 2011
@sfstpala
Copy link
Author

This is excellent, thanks a lot Waylan.

Here's what I'm running now:

+ import html.entities
- if sys.version >= "3.0":
-     from html import entities as htmlentitydefs
- else:
-     import html.entities

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants