Exemplo n.º 1
0
def ConvertDispatchHandler(handler):
    """Create conversion function which handles dispatch rules.

  Extract domain and path from dispatch url,
  set service value from service or module info.

  Args:
    handler: Result of converting handler according to schema.

  Returns:
    Handler which has 'domain', 'path' and 'service' fields.
  """
    dispatch_url = dispatchinfo.ParsedURL(handler['url'])
    dispatch_service = handler['service']

    dispatch_domain = dispatch_url.host
    if not dispatch_url.host_exact:
        dispatch_domain = '*' + dispatch_domain

    dispatch_path = dispatch_url.path
    if not dispatch_url.path_exact:
        dispatch_path = dispatch_path.rstrip('/') + '/*'

    new_handler = {}
    new_handler['domain'] = dispatch_domain
    new_handler['path'] = dispatch_path
    new_handler['service'] = dispatch_service

    return new_handler
Exemplo n.º 2
0
    def _HandlerToDict(self, handler):
        parsed_url = dispatchinfo.ParsedURL(handler.url)
        dispatch_domain = parsed_url.host
        if not parsed_url.host_exact:
            dispatch_domain = '*' + dispatch_domain

        dispatch_path = parsed_url.path
        if not parsed_url.path_exact:
            dispatch_path = dispatch_path.rstrip('/') + '/*'
        return {
            'domain': dispatch_domain,
            'path': dispatch_path,
            'service': handler.service,
        }
Exemplo n.º 3
0
    def _HandlerToDict(self, handler):
        """Converst a dispatchinfo handler into a 1p-ready dict."""
        parsed_url = dispatchinfo.ParsedURL(handler.url)
        dispatch_domain = parsed_url.host
        if not parsed_url.host_exact:
            dispatch_domain = '*' + dispatch_domain

        dispatch_path = parsed_url.path
        if not parsed_url.path_exact:
            trailing_matcher = '/*' if dispatch_path.endswith('/') else '*'
            dispatch_path = dispatch_path.rstrip('/') + trailing_matcher
        return {
            'domain': dispatch_domain,
            'path': dispatch_path,
            'service': handler.service,
        }
Exemplo n.º 4
0
def ConvertDispatchHandler(handler):
    """Create conversion function which handles dispatch rules.

  Extract domain and path from dispatch url,
  set service value from service or module info.

  Args:
    handler: Result of converting handler according to schema.

  Returns:
    Handler which has 'domain', 'path' and 'service' fields.

  Raises:
    ValueError: if both module and service presented in dispatch entry
    or no module or service presented in dispatch entry.
  """
    dispatch_url = dispatchinfo.ParsedURL(handler['url'])

    dispatch_service = None
    if 'module' in handler:
        dispatch_service = handler['module']
    if 'service' in handler:
        if dispatch_service:
            raise ValueError("Both 'module' and 'service' in dispatch rule, "
                             "please use only one: %s" % handler)
        else:
            dispatch_service = handler['service']
    if not dispatch_service:
        raise ValueError(
            "Missing required value 'service' in dispatch rule: %s" % handler)

    dispatch_domain = dispatch_url.host
    if not dispatch_url.host_exact:
        dispatch_domain = '*' + dispatch_domain

    dispatch_path = dispatch_url.path
    if not dispatch_url.path_exact:
        dispatch_path = dispatch_path.rstrip('/') + '/*'

    new_handler = {}
    new_handler['domain'] = dispatch_domain
    new_handler['path'] = dispatch_path
    new_handler['service'] = dispatch_service

    return new_handler