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

Issue with simple field #238

Open
botzill opened this issue Apr 22, 2017 · 0 comments
Open

Issue with simple field #238

botzill opened this issue Apr 22, 2017 · 0 comments

Comments

@botzill
Copy link
Contributor

botzill commented Apr 22, 2017

We have a scenario which fails with the following error:

Traceback (most recent call last):
  File "/Users/geo/PycharmProjects/pydocx/tt/t.py", line 74, in <module>
    html = PyDocX.to_html(open(file_path, 'rb'))
  File "/Users/geo/PycharmProjects/pydocx/pydocx/pydocx.py", line 13, in to_html
    return PyDocXHTMLExporter(path_or_stream).export()
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/html.py", line 211, in export
    for result in super(PyDocXHTMLExporter, self).export()
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/html.py", line 209, in <genexpr>
    result.to_html() if isinstance(result, HtmlTag)
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 123, in export
    for result in self.export_node(document):
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 218, in export_node
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/html.py", line 127, in apply
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 218, in export_node
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/html.py", line 127, in apply
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 252, in yield_nested
    for result in func(item):
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 218, in export_node
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/html.py", line 127, in apply
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 252, in yield_nested
    for result in func(item):
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 218, in export_node
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/html.py", line 127, in apply
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 267, in yield_nested_with_line_breaks_between_paragraphs
    for result in func(item):
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 218, in export_node
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/html.py", line 280, in export_paragraph
    results = is_not_empty_and_not_only_whitespace(results)
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/html.py", line 78, in is_not_empty_and_not_only_whitespace
    for item in gen:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 252, in yield_nested
    for result in func(item):
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 218, in export_node
    for result in results:
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 252, in yield_nested
    for result in func(item):
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 216, in export_node
    results = caller(node)
  File "/Users/geo/PycharmProjects/pydocx/pydocx/export/base.py", line 524, in export_simple_field
    parsed_instr = simple_field.parse_instr()
  File "/Users/geo/PycharmProjects/pydocx/pydocx/openxml/wordprocessing/simple_field.py", line 43, in parse_instr
    m = self._parse_instr_into_field_type_and_arg_string()
  File "/Users/geo/PycharmProjects/pydocx/pydocx/openxml/wordprocessing/simple_field.py", line 35, in _parse_instr_into_field_type_and_arg_string
    return re.match('^\s*([^\s]+)\s*(.*)$', self.instr)
  File "/Users/geo/.virtualenvs/pydocx/lib/python2.7/re.py", line 141, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or buffer

After some investigations I see that we can have None values for this: https://github.com/CenterForOpenScience/pydocx/blob/master/pydocx/openxml/wordprocessing/simple_field.py#L23.

So, I guess a simple check here: https://github.com/CenterForOpenScience/pydocx/blob/master/pydocx/openxml/wordprocessing/simple_field.py#L41 should solve the issue?

I did not get into mush details here related to complex -> simple field conversion.

botzill added a commit to botzill/pydocx that referenced this issue Apr 22, 2017
botzill added a commit to botzill/pydocx that referenced this issue Apr 22, 2017
botzill added a commit to botzill/pydocx that referenced this issue Apr 22, 2017
botzill added a commit to botzill/pydocx that referenced this issue May 19, 2018
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

1 participant