Beispiel #1
0
  def service_mappings(services, registry_path='/_rpc/meta', protocols=None):

    '''  '''

    if not protocols:
      from canteen.base import protocol
      protocols = protocol.Protocol.mapping

    if isinstance(services, dict):
      services = services.iteritems()

    final_mapping, paths, registry_map = (
      [],
      set(),
      {} if registry_path else None
    )

    for service_path, service_factory in services:
      service_class = service_factory.service_class if hasattr(service_factory, 'service_class') else service_factory

      if service_path not in paths:
        paths.add(service_path)
      else:
        raise premote.ServiceConfigurationError(
          'Path %r is already defined in service mapping' %
          service_path.encode('utf-8'))

      if registry_map is not None: registry_map[service_path] = service_class
      final_mapping.append(pservice.service_mapping(service_factory, service_path, protocols=protocols))

    if registry_map is not None:
      final_mapping.append(pservice.service_mapping(
        pregistry.RegistryService.new_factory(registry_map), registry_path, protocols=protocols))

    return pwsgi_util.first_found(final_mapping)
    def CreateWsgiApplication(self):
        """Create WSGI application used on the server side for testing."""
        my_service = service.service_mapping(webapp_test_util.TestService,
                                             '/my/service')
        my_other_service = service.service_mapping(
            webapp_test_util.TestService.new_factory('initialized'),
            '/my/other_service',
            protocols=self.protocols)

        return util.first_found([my_service, my_other_service])
Beispiel #3
0
  def  CreateWsgiApplication(self):
    """Create WSGI application used on the server side for testing."""
    my_service = service.service_mapping(webapp_test_util.TestService,
                                         '/my/service')
    my_other_service = service.service_mapping(
      webapp_test_util.TestService.new_factory('initialized'),
      '/my/other_service',
      protocols=self.protocols)

    return util.first_found([my_service, my_other_service])
  def  CreateWsgiApplication(self):
    """Create WSGI application used on the server side for testing."""
    my_service = service.service_mapping(webapp_test_util.TestService,
                                         '/my/service')
    my_other_service = service.service_mapping(
      webapp_test_util.TestService.new_factory('initialized'),
      '/my/other_service',
      protocols=self.protocols)

    def request_router(environ, start_response):
      path_info = environ['PATH_INFO']
      if path_info.startswith('/my/service'):
        return my_service(environ, start_response)
      elif path_info.startswith('/my/other_service'):
        return my_other_service(environ, start_response)
      raise AssertionError('Should never get here')
    return request_router
Beispiel #5
0
    def service_mappings(services, registry_path='/_rpc/meta', protocols=None):
        '''  '''

        if not protocols:
            from canteen.base import protocol
            protocols = protocol.Protocol.mapping

        if isinstance(services, dict):
            services = services.iteritems()

        final_mapping, paths, registry_map = ([], set(),
                                              {} if registry_path else None)

        for service_path, service_factory in services:
            service_class = service_factory.service_class if hasattr(
                service_factory, 'service_class') else service_factory

            if service_path not in paths:
                paths.add(service_path)
            else:
                raise premote.ServiceConfigurationError(
                    'Path %r is already defined in service mapping' %
                    service_path.encode('utf-8'))

            if registry_map is not None:
                registry_map[service_path] = service_class
            final_mapping.append(
                pservice.service_mapping(service_factory,
                                         service_path,
                                         protocols=protocols))

        if registry_map is not None:
            final_mapping.append(
                pservice.service_mapping(
                    pregistry.RegistryService.new_factory(registry_map),
                    registry_path,
                    protocols=protocols))

        return pwsgi_util.first_found(final_mapping)
from google.appengine.ext.webapp import util
from protorpc.wsgi import service
import logging
import deliveryservice

logging.debug('Handling service...')
# Map the RPC service and path (/DeliverService)
delivery_service = service.service_mapping(deliveryservice.DeliveryService, '/DeliveryService.*')

def main():
  util.run_wsgi_app(delivery_service)

if __name__ == '__main__':
  main()
Beispiel #7
0
					logging.error('An error occured %s' % resp)
			else:
				logging.info('No download url for file %s' % f['title'])

		logging.info('User email: %s' % users.get_current_user().email())
		curUser = User.get_or_insert(users.get_current_user().email(),email=users.get_current_user().email())
		for f in resultlist:
			Doc.get_or_insert(f['id'],parent=curUser.key(),title=f['id'],totalPages=f['numpages'],user=curUser)

		template_values = {
			'filelist' : resultlist
		}
		template = jinja_environment.get_template('home.html')
		self.response.out.write(template.render(template_values))

class ApiService(remote.Service):
	@remote.method(UserInfoMessage,BookListMessage)
	def list(self,request):
		q=User.get(Key.from_path('User',request.user_email))
		results = q.documents
		logging.info(results)
		messagesdocs = map(lambda doc:BookMessage(bookid=doc.key().name(),total_pages=doc.totalPages,current_page=doc.currentPage),results)
		return BookListMessage(books=messagesdocs)

	@remote.method(ReadEventMessage,message_types.VoidMessage)
	def readevent(self,request):
		pass

app = webapp2.WSGIApplication([ ('/',MainPage),(decorator.callback_path, decorator.callback_handler())],debug=True)
api = protoservice.service_mapping(ApiService)
Beispiel #8
0
__author__ = '[email protected] (Vlad Lego)'
package = 'webocrat'

from protorpc.wsgi import service

#import hub
import hartacainilor
#import wmap_object
#import comment
#import ego

HartaCainilor = service.service_mapping(hartacainilor.HartaCainilorService,
                                        '/hc')
#hubService = service.service_mapping(hub.hub_service, '/h-')
#ego = service.service_mapping(ego.ego_service, '/e-')
#comment = service.service_mapping(comment.comment_service, '/comment')

#wmapServices = service.service_mappings(
#    [
#        ('/map', wmap.wMapObjectService),
#        ('/m-', wmap.wMapObjectService)
#    ])
Beispiel #9
0
__author__ = "[email protected] (Vlad Lego)"
package = "webocrat"

from protorpc.wsgi import service

# import hub
import hartacainilor

# import wmap_object
# import comment
# import ego


HartaCainilor = service.service_mapping(hartacainilor.HartaCainilorService, "/hc")
# hubService = service.service_mapping(hub.hub_service, '/h-')
# ego = service.service_mapping(ego.ego_service, '/e-')
# comment = service.service_mapping(comment.comment_service, '/comment')

# wmapServices = service.service_mappings(
#    [
#        ('/map', wmap.wMapObjectService),
#        ('/m-', wmap.wMapObjectService)
#    ])
Beispiel #10
0
  def service_mappings(services, registry_path='/_rpc/meta', protocols=None):

    """ Generates mappings from `url -> service` for registered Canteen RPC
        services.

        Takes an iterable of URL and service mappings, wraps with appropriate
        WSGI utilities, and registers with registry service for Endpoints/meta
        integration.

        :param services: Iterable of services, preferably a ``list`` of
          ``tuples``, where each is in the format ``(url, service)``. ``url``
          should be a relative prefix for matching requests, like
          ``/_rpc/hello`` for something called ``HelloService``.

        :param registry_path: Path prefix for ``RegistryService``, which returns
          metadata about registered RPC services. Required for integration with
          Google Cloud Endpoints or the various ProtoRPC client-side library
          generation options out there.

        :param protocols: Protocols to use for dispatching services. Custom
          protocol implementations are supported and two are shipped with
          canteen - ``JSON`` and ``msgpack`` RPC formats (note: not necessarily
          affiliated with any standards that are actually called "msgpack-rpc"
          or "jsonrpc").

        :returns: WSGI application prepared by :py:mod:`protorpc`, which, upon
          dispatch, will attempt to delegate response to the first matching
          ``Service`` implementation, as governed by the mappings generated in
          this function from ``services``. """

    if not protocols:
      # load canteen builtin protocols
      from canteen.base import protocol
      protocols = protocol.Protocol.mapping

    if isinstance(services, dict):
      services = services.iteritems()

    final_mapping, paths, registry_map = (
      [],
      set(),
      {} if registry_path else None
    )

    for service_path, service_factory in services:
      service_class = service_factory.service_class if (
        hasattr(service_factory, 'service_class')) else service_factory

      if service_path not in paths:
        paths.add(service_path)
      else:
        raise premote.ServiceConfigurationError(
          'Path %r is already defined in service mapping' %
          service_path.encode('utf-8'))

      if registry_map is not None: registry_map[service_path] = service_class
      final_mapping.append((
        pservice.service_mapping(*(
          service_factory, service_path), protocols=protocols)))

    if registry_map is not None:
      final_mapping.append(pservice.service_mapping(*(
        pregistry.RegistryService.new_factory(registry_map), registry_path),
            protocols=protocols))

    return pwsgi_util.first_found(final_mapping)