Pyramid Framework disables JSONP feedback format for AngularJS

The pyramid’s web framework prohibits AngularJS JSONP callbacks, since newer versions (working in 1.5.3, do not run in 1.5.6) throw the error "Invalid JSONP callback function name". when used with AngularJS (V1.2.28), which passes the callback as follows: ptth: // example /? callback = angular.callbacks._0

What will be the workaround?

There seems to be no good option to fix this on AngularJS (doesn't allow changing the callback structure) or the Pyramid side.

https://pyramid.readthedocs.org/en/master/_modules/pyramid/renderers.html JSONP_VALID_CALLBACK = re.compile (r "^ [a-zA-Z_ $] [0-9a-zA-Z_ $] + $ ")

from pyramid.renderers import JSONP
config.add_renderer('jsonp',JSONP(param_name='callback'))

https://github.com/Pylons/pyramid/issues/1644

+4
source share
1 answer

It appears that the regex in Pyramid does not allow a dot (.) In the callback name:

JSONP_VALID_CALLBACK = re.compile(r"^[a-zA-Z_$][0-9a-zA-Z_$]+$")

The workaround for this would be to subclass pyramid.renderers.JSONP, override its method __call__and force it to use the corrected regular expression. You can then register your own render with pyramid.config.Configurator.add_rendererand use it instead of Pyramid's built-in renderer.

When the problem is fixed in Pyramid, you simply remove your subclass and use the Pyramid renderer. Good thing you filed an error message.

0
source

Source: https://habr.com/ru/post/1584210/


All Articles