Hi,
My use case implies that I don't want to create a custom new request but a
clone of the initial request!
I investigated a little more and found that "request.copy()" duplicates
most of the initial query attributes, including properties added via
"add_request_method()" (reifyed or not), except "root" and "registry".
So finally I use a function like this:

def copy_request(request):
    """Create clone of given request, keeping registry and root as well"""
    root = request.root
    request = request.copy()
    if not hasattr(request, 'registry'):
        registry = get_current_registry()
        if registry is None:
            registry = get_global_registry()
        request.registry = registry
    request.root = root
    return request


Any advise is still welcome!  ;)

Best regards,
Thierry


Le mar. 15 janv. 2019 à 21:22, Bobby <dekalb1...@gmail.com> a écrit :

> The following works for me whenever celery needs a dup request:
>
> import plaster
> from pyramid.request import Request, apply_request_extensions
>
> def make_request():
>     loader = plaster.get_loader('development.ini', protocols=['wsgi'])
>     app = loader.get_wsgi_app()
>     r = Request.blank('/localhost:6543')
>     r.registry = app.registry
>     apply_request_extensions(r)
>     return r
>
>
>
> On Tuesday, January 15, 2019 at 5:09:18 AM UTC-5, Thierry Florac wrote:
>>
>> Hi,
>> Simple question: I have a use case where I need to create an exact copy
>> (a clone) of a request, to update it's properties and make "simulations"
>> (actually by providing custom marker interfaces) without modifying the
>> original request.
>> Is there a good way to do this?
>> Actually I just tried to do a "request.copy()", but then I get errors
>> like "AttributeError: 'Request' object has no attribute 'root'" when trying
>> to get access to "root" attribute...
>>
>> Thanks for any help,
>> Thierry
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pylons-discuss+unsubscr...@googlegroups.com.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pylons-discuss/feac8d1c-4f07-46a6-af06-dc94eb1b2d69%40googlegroups.com
> <https://groups.google.com/d/msgid/pylons-discuss/feac8d1c-4f07-46a6-af06-dc94eb1b2d69%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
  http://pyams.readthedocs.io

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAPX_VWCJ6E13CL3wuDJmXmcUp%3DSNSTEtegJ%3D1JP61Wuvw%2Biq9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to