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

fix chameleon default handling #315

Closed
wants to merge 2 commits into from
Closed

Conversation

d-maurer
Copy link

Use the default_marker integration parameter rather than a locally defined marker("default") as representation of the TALES default object.

This fix would resolve "zopefoundation/Zope#853".

@malthe
Copy link
Owner

malthe commented Jun 20, 2020

I need to integrate Travis in this repository, but I can see that this pull request introduces test failures: https://travis-ci.org/github/malthe/chameleon/builds/700298576.

Let me try and take a look at the Zope test failures.

@d-maurer
Copy link
Author

d-maurer commented Jun 20, 2020 via email

@d-maurer
Copy link
Author

d-maurer commented Jun 20, 2020 via email

@d-maurer
Copy link
Author

The PageTemplate parameter literal_false is documented as:

      ``literal_false``

        Attributes are not dropped for a value of ``False``. Instead,
        the value is coerced to a string.

        This setting exists to provide compatibility with the
        reference implementation.

It applies only to attributes and has nothing to do with the TALES default; instead it is strongly related to Python's False. (Likely, it should apply to all Python false values not just False.)

The documentation of MacroProgram.default_marker

    # This default marker value has the semantics that if an
    # expression evaluates to that value, the expression default value
    # is returned. For an attribute, if there is no default, this
    # means that the attribute is dropped.

seems to indicate that it implements the TALES default.

BUT, default_marker is defined as Builtin('__default') or Builtin('False') depending on literal_false. This looks wrong: the TALES default should be independent of literal_false.

@d-maurer
Copy link
Author

I have changed the "literal_default" handling. The chameleon tests are now passing.

I have slightly changed 2 tests (more precisely 1 test to fix problems with 2 subtests). First I defined default to fix a "NameError: default not defined". After this the alternative default | ... no longer gave the second alternative (as the test required); I replaced default by undefined.
There is a further change in the tests -- but this one not voluntary: my editor could not handle some characters and replaced them by ?.

@malthe
Copy link
Owner

malthe commented Jun 21, 2020

I think the default_marker naming here is a little confusing and misleading.

There are really two separate concerns here:

  1. To enable the HTML-like "literal attributes" such as checked="checked" – where I believe there can be a default value, too – which is then either False or the string given in a static attribute definition. If literal attributes are not used, then we just use a regular marker object.
  2. For attribute content, the default value should be the precomputed contents. But I think that for some reason, a marker value was used. This is probably a mistake.

The compiler definitely evolved organically and this shows in the design. Some of the abstractions seem quite leaky. The question is how much time should be invested in fixing it?

@d-maurer
Copy link
Author

d-maurer commented Jun 21, 2020 via email

@malthe
Copy link
Owner

malthe commented Jun 22, 2020

The TALES engine just has to assign a value to the provided target.

I'm not sure I agree that it needs disentanglement from the TAL layer – which is currently implemented at the program level.

I think we're relatively close to a solution for the issue at hand here. Rewriting the whole handling of attributes is out of scope I think. There are a lot of corner cases – beware of dragons!

@d-maurer
Copy link
Author

d-maurer commented Jun 22, 2020 via email

@malthe
Copy link
Owner

malthe commented Jun 22, 2020

@d-maurer would you mind looking at #317 to see if this could fix the situation?

@d-maurer
Copy link
Author

d-maurer commented Jun 23, 2020 via email

@malthe
Copy link
Owner

malthe commented Jun 23, 2020

@d-maurer I have pushed 1aa5b40, which changes it from a class to a module.

@d-maurer
Copy link
Author

d-maurer commented Jul 2, 2020

@malthe has solved the original problem differently.

@d-maurer d-maurer closed this Jul 2, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants