Thanks!  So that means some objects last across multiple scopes, and they
can create another obj that only lasts for one specific scope?
I am still confused how the different layers of middleware wrap around the
real asgi application -- a obj just lasts for one scope.
I need to go through the code deeper.

Thanks
Drew



On Fri, Oct 26, 2018 at 4:07 PM Andrew Godwin <and...@aeracode.org> wrote:

> Hi Drew,
>
> The return value is indeed an object, but if you look closely at it you'll
> see it defines a __call__ method - meaning that when it's called as an ASGI
> application, it then returns a further object to act inside the scope.
>
> Andrew
>
> On Fri, Oct 26, 2018 at 2:55 PM Zhiyu/Drew Li <zyli2...@gmail.com> wrote:
>
>> Hi,
>>
>> Newbie here. (please bear with me if this a stupid question)
>>
>> I am going through the tutorial and doc and got this question regarding how 
>> ProtocolTypeRouter works.
>> ProtocolTypeRouter.__init__ takes a dict "application_mapping" and append a 
>> key-value pair to it: "http': class AsgiHandler
>> As doc says ASGI application is created on a per scope basis, I think I 
>> vaguely understand how the "http" one works.
>> Once a http scope comes in, an instance/object of class AsgiHandler is 
>> initiated, which lasts for the duration of the scope.
>> So it is one scope leads to one ASGI application/object
>>
>> But I am confused about this one:
>> application = ProtocolTypeRouter({
>>     # (http->django views is added by default)
>>     'websocket': AuthMiddlewareStack(
>>         URLRouter(
>>             chat.routing.websocket_urlpatterns
>>         )
>>     ),
>> })
>> The whole value of this key-value pair 
>> AuthMiddlewareStack(URLRouter(chat.routing.websocket_urlpatterns)) seems to 
>> be a object not a class,
>> so that means the application already exists before a websocket scope comes 
>> in. How does this conform to "one scope one application" rule?
>>
>> Any help would be appreciated.
>>
>> Thanks
>> Drew
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/f6088bd4-457a-4106-b883-332af9a99337%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/f6088bd4-457a-4106-b883-332af9a99337%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFwN1urusiZjfH2HSnkaRcuNVUXMgLuLRxs%3DxH9tK%3D35enFDow%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAFwN1urusiZjfH2HSnkaRcuNVUXMgLuLRxs%3DxH9tK%3D35enFDow%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMmsbU%3D0nwz44EzCnMriL2FS-oOL7LyrYOJpp5ocPO3i%3Dj5CFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to