brainkim/archieml-python

Parsing bug with some nested data.

Closed this issue · 6 comments

A nested structure like the one below will fail in your parser. I believe it is due to the multiple "image" typed objects.

You can pass the same structure to the ArchieML sandbox on the official site and it parsers fine. So my first guess is that this is a bug in your code. I've attached the traceback I get as well.

[.profiles]
  who:The women’s <br>rights activist
  full_profile:y
  one_liner:‘Keep us alive in your thoughts’
  photo:order-4
  frame_position:left
  [.+copy]
  {.image}
    bleed:normal,
    photo:order-4
    top:35%
    left:55%
    width:65
    height:65
    fit:cover
    placement:left
    order:1
  {}

  {.who}
  {}

  When Mahbouba Seraj talks about her fears, an unusual thing happens: She sounds more indomitable than ever.

   {.image}
    bleed:normal,
    photo:p1-2
    top:65%
    left:20%
    width:40
    height:55
    fit:cover
    placement:left
    order:6
  {}

  At 73, Seraj is the doyenne of Afghan women’s rights activists — a stature and status that put her in the crosshairs of Taliban rulers.

  “Of course I’m afraid,” she said. “Everyone’s afraid.”

  But Seraj, who spent more than a quarter-century in exile in the United States before returning in 2003 to help build a women’s movement and women’s institutions, is standing fast in her refusal to leave, and to find ways of continuing her work.

  {.image}
    bleed:normal,
    photo:p1-3
    top:70%
    left:65%
    width:60
    height:40
    fit:cover
    placement:left
    order:10
  {}

  “I’m staying,” she said, interviewed in her Kabul home weeks after the Taliban seized control.

  Seraj said she believed — or hoped, at least — that the Taliban movement would come to understand that the Afghanistan of today is not the same country it was 20 years ago.

  “We are 18 million women; we have close to 6 million who are educated,” she said, pointing to the roles women carved out for themselves in business, education, medicine, media and government.

  A niece of Amanullah Khan, the Afghan sovereign who led the country to independence from Britain in 1919, Seraj has a more finely honed sense than many of history’s vicissitudes.

  Named one of Time magazine’s 100 most influential people in 2021, she thinks there is much to be learned from the two-decade-long U.S. presence in Afghanistan. The role of Afghan women was vastly elevated, she said — but in allocating aid and jobs, outsiders also trampled at times on the sensibilities of women reluctant to adopt certain Western mores.

  Now, she said, the country’s women must seek a new path.

  “If you can, keep us alive in your thoughts and your memory — read about us, ask about us…. It will be a great help,” she said. “We really have to be strong.”

  []
[]
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/palewire/.local/share/virtualenvs/afghan-women-in-hiding-YJqOGRxh/lib/python3.9/site-packages/archieml/__init__.py", line 237, in load
    return Loader().load(fp)
  File "/home/palewire/.local/share/virtualenvs/afghan-women-in-hiding-YJqOGRxh/lib/python3.9/site-packages/archieml/__init__.py", line 158, in load
    self.load_scope(m.group('brace'), m.group('flags'), m.group('scope_key'))
  File "/home/palewire/.local/share/virtualenvs/afghan-women-in-hiding-YJqOGRxh/lib/python3.9/site-packages/archieml/__init__.py", line 205, in load_scope
    self.set_value(
  File "/home/palewire/.local/share/virtualenvs/afghan-women-in-hiding-YJqOGRxh/lib/python3.9/site-packages/archieml/__init__.py", line 129, in set_value
    data[k] = value
IndexError: list assignment index out of range

Good tidings! I’m sorry to hear about the bug. I haven’t looked at this repository, nor honestly written much Python, in a good bit of time, so it might take me a while before I get a chance to fix this, just because of the nature of context switching. Nevertheless, I would be happy to accept any pull requests which fix this bug! Otherwise, I’ll try to look at it when I can.

Thanks for the report!

Great. I sent you a PR with a simplified test file that reproduces the bug. I'm trying to sort through it myself right now and find the route to a fix, but haven't found anything yet. Your expertise would def. be welcome when you have the time.

Well we did get an extra hour today I guess. I’ll take a look!

@palewire Seems like a little weird bug in the freeform array syntax. Again, thanks for the report, and I hope I didn’t mess with any deadlines. This was shipped in 0.3.5.

Wow. Thank you so much!

I worked around it on deadline by relying on a Node.JS parser instead. I can switch back to Python now!

FWIW, your handiwork helped make a page like this possible today. https://www.latimes.com/projects/afghan-women/

@palewire Harrowing stories, well presented! If ever you need to make any changes to this repository, let me know, I’m happy to share the burden of maintenance. Thanks again for reaching out.