posativ / acrylamid

(unmaintained) static blog generator in python with incremental rendering ⛺
http://posativ.org/acrylamid/
Other
277 stars 40 forks source link

ValueError: invalid literal for int() with base 10 when using hyphenation #237

Closed islander closed 9 years ago

islander commented 9 years ago

Hi

I'm trying to use hyphenation for russian language and get this error:

$ acrylamid new
Entry's title: test hyphenation
     create  content/2015/test-hyphenation.txt
(blog)user@hostname:~/projects/blog$ acrylamid co
     update  [0.03s] output/articles/index.html
Traceback (most recent call last):
  File "/home/user/.virtualenvs/blog/bin/acrylamid", line 9, in <module>
    load_entry_point('acrylamid==0.7.10', 'console_scripts', 'acrylamid')()
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/__init__.py", line 179, in Acryl
    commands.compile(conf, env)
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/commands.py", line 219, in compile
    for buf, path in v.generate(conf, env, data):
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/views/entry.py", line 71, in generate
    prev=prev, next=next, route=expand(self.path, entry)))
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/templates/jinja2.py", line 121, in render
    self.template.stream(**kw).dump(buf)
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/jinja2/environment.py", line 1072, in dump
    fp.writelines(iterable)
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/jinja2/environment.py", line 1116, in next
    return self._next()
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/jinja2/environment.py", line 918, in generate
    yield self.environment.handle_exception(exc_info, True)
  File "theme/main.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "theme/base.html", line 32, in top-level template code
    {%- block content -%}
  File "theme/main.html", line 21, in block "content"
    {% include 'entry.html' %}
  File "theme/entry.html", line 8, in top-level template code
    {{ entry.content }}
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/jinja2/environment.py", line 372, in getattr
    return getattr(obj, attribute)
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/readers.py", line 444, in content
    res = f.transform(res, self, *f.args)
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/filters/__init__.py", line 119, in <lambda>
    cls, dct.get('transform', bases[0].transform))(cls, x, y, *z)
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/filters/hyphenation.py", line 183, in transform
    hyphenate_word = self.default
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/utils.py", line 83, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/filters/hyphenation.py", line 167, in default
    return build(self.conf['lang'].replace('_', '-'))
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/filters/hyphenation.py", line 150, in build
    hyphenator = Hyphenator(chars, patterns, exceptions='')
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/filters/hyphenation.py", line 42, in __init__
    self._insert_pattern(pattern)
  File "/home/user/.virtualenvs/blog/local/lib/python2.7/site-packages/acrylamid/filters/hyphenation.py", line 53, in _insert_pattern
    points = [int(d or 0) for d in re.split(self.chars, pattern)]
ValueError: invalid literal for int() with base 10: '-'

Files downloaded:

$ ls -1 ~/.virtualenvs/blog/lib/python2.7/site-packages/acrylamid/filters/hyph
hyph-de-1996.chr.txt
hyph-de-1996.lic.txt
hyph-de-1996.pat.txt
hyph-en-us.chr.txt
hyph-en-us.lic.txt
hyph-en-us.pat.txt
hyph-fr.chr.txt
hyph-fr.lic.txt
hyph-fr.pat.txt
hyph-ru.chr.txt
hyph-ru.lic.txt
hyph-ru.pat.txt

Any workaround for this issue?

islander commented 9 years ago

Ok, it was a problem with self.chars regex pattern: [.-абвгдежзийклмнопрстуфхцчшщъыьэюяё]. '-' should be escaped here, so I proposed pull request #238. Pattern now looks like this: [.-\а\б\в\г\д\е\ж\з\и\й\к\л\м\н\о\п\р\с\т\у\ф\х\ц\ч\ш\щ\ъ\ы\ь\э\ю\я\ё], is it correct?