I have created an api service (see below) and I am wondering why the MyServiceClass.__call__(...)
is called even if the request doesn't contains @my_service_class
as e.g.:
curl \
-s \
-X GET http://192.168.45.133:8080/Plone \
-H "Accept: application/json" \
--user admin:***
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone">
<adapter factory=".get.MyServiceClass"
name="my_service_class"
/>
<plone:service
method="GET"
for="zope.interface.Interface"
factory=".get.MyServiceClassGet"
name="@my_service_class"
permission="zope2.View"
/>
</configure>
# -*- coding: utf-8 -*-
from plone import api
from plone.restapi.interfaces import IExpandableElement
from plone.restapi.services import Service
from zope.component import adapter
from zope.interface import implementer, Interface
import pprint
@implementer(IExpandableElement)
@adapter(Interface, Interface)
class MyServiceClass(object):
def __init__(self, context, request):
self.context = context.aq_explicit
self.request = request
def __call__(self, expand=False):
print("self.request", self.request) # <- this is called
return {}
class MyServiceClassGet(Service):
def reply(self):
service_factory = MyServiceClass(self.context, self.request)
return service_factory(expand=True)['my_service_class']