示例#1
0
 def get_fake_context(self):
     context = self.root.context_cls()
     context.soup_message = SoupMessage()
     context.path = '/'
     context.database = self.database
     context.server = self
     set_context(context)
     return context
示例#2
0
文件: server.py 项目: kennym/itools
    def init_context(self, context):
        # (1) Initialize the response status to None, it will be changed
        # through the request handling process.
        context.status = None

        # (2) The server, the data root and the authenticated user
        context.server = self
        context.root = self.root

        # (3) The authenticated user
        self.find_user(context)

        # (4) The Site Root
        self.find_site_root(context)
        context.site_root.before_traverse(context)  # Hook

        # (5) Keep the context
        set_context(context)
示例#3
0
    def init_context(self, context):
        # (1) Initialize the response status to None, it will be changed
        # through the request handling process.
        context.status = None

        # (2) The server, the data root and the authenticated user
        context.server = self
        context.root = self.root

        # (3) The authenticated user
        self.find_user(context)

        # (4) The Site Root
        self.find_site_root(context)
        context.site_root.before_traverse(context)  # Hook

        # (5) Keep the context
        set_context(context)
    def validate_user_token(self):
        if not self._user_auth_middleware:
            # following config forces keystone middleware to always return the
            # result back in HTTP_X_IDENTITY_STATUS env variable
            conf_info = self._conf_info.copy()
            conf_info['delay_auth_decision'] = True
            self._user_auth_middleware = auth_token.AuthProtocol(
                self.token_valid, conf_info)

        if not self._user_auth_middleware:
            return False, (403, " Permission denied")

        request_attrs = {
            'REQUEST_METHOD': get_request().route.method,
            'bottle.app': get_request().environ['bottle.app'],
        }
        if 'HTTP_X_AUTH_TOKEN' in get_request().environ:
            request_attrs['HTTP_X_AUTH_TOKEN'] =\
                get_request().environ['HTTP_X_AUTH_TOKEN'].encode("ascii")
        elif 'HTTP_X_USER_TOKEN' in get_request().environ:
            request_attrs['HTTP_X_USER_TOKEN'] =\
                get_request().environ['HTTP_X_USER_TOKEN'].encode("ascii")
        else:
            return False, (400, "User token needed for validation")
        b_req = bottle.BaseRequest(request_attrs)
        # get permissions in internal context
        orig_context = get_context()
        i_req = ApiInternalRequest(b_req.url, b_req.urlparts, b_req.environ,
                                   b_req.headers, None, None)
        set_context(ApiContext(internal_req=i_req))
        try:
            token_info = self._user_auth_middleware(
                get_request().headers.environ, self.start_response)
        finally:
            set_context(orig_context)

        return True, token_info
    def validate_user_token(self):
        if not self._user_auth_middleware:
            # following config forces keystone middleware to always return the
            # result back in HTTP_X_IDENTITY_STATUS env variable
            conf_info = self._conf_info.copy()
            conf_info['delay_auth_decision'] = True
            self._user_auth_middleware = auth_token.AuthProtocol(
                self.token_valid, conf_info)

        if not self._user_auth_middleware:
            return False, (403, " Permission denied")

        request_attrs = {
            'REQUEST_METHOD': get_request().route.method,
            'bottle.app': get_request().environ['bottle.app'],
        }
        if 'HTTP_X_AUTH_TOKEN' in get_request().environ:
            request_attrs['HTTP_X_AUTH_TOKEN'] =\
                get_request().environ['HTTP_X_AUTH_TOKEN'].encode("ascii")
        elif 'HTTP_X_USER_TOKEN' in get_request().environ:
            request_attrs['HTTP_X_USER_TOKEN'] =\
                get_request().environ['HTTP_X_USER_TOKEN'].encode("ascii")
        else:
            return False, (400, "User token needed for validation")
        b_req = bottle.BaseRequest(request_attrs)
        # get permissions in internal context
        orig_context = get_context()
        i_req = ApiInternalRequest(b_req.url, b_req.urlparts, b_req.environ,
                                   b_req.headers, None, None)
        set_context(ApiContext(internal_req=i_req))
        try:
            token_info = self._user_auth_middleware(
                get_request().headers.environ, self.start_response)
        finally:
            set_context(orig_context)

        return True, token_info
import context
context.set_context()

import os
from pathlib import Path
import logging
import sys
import json

from datetime import datetime

import exiftool

import util
import gphoto
from gphoto.local_library import LocalLibrary
from gphoto.google_library import GoogleLibrary
from gphoto.google_images import GoogleImages
from gphoto.imageutils import ImageUtils


# -----------------------------------------------------
# do_work
# -----------------------------------------------------
def do_work(et, google_image_filter, album_folder_path, list_only):

    # Find folder album in the database
    LocalLibrary.load_library('raw')
    local_library_cache = LocalLibrary.cache_raw()
    images = local_library_cache['images']
    albums = local_library_cache['albums']
import context; context.set_context()
import os
import sys
from pathlib import Path
import logging
import sys
import json

from datetime import datetime

import exiftool

import util
import gphoto
from gphoto.local_library import LocalLibrary
from gphoto.imageutils import ImageUtils

# -----------------------------------------------------
# Execute
# -----------------------------------------------------
def execute(album_path_filter):

    LocalLibrary.load_library('raw')

    album_path_filter_leaf = None
    if album_path_filter:
        album_path_filter_leaf = os.path.basename(album_path_filter)

    # The result is going to be of the form
    #     {
示例#8
0
from context import set_context
from iface import Iface
from node import Node

if __name__ == "__main__":
    set_context()
    x = Node("wea")
    iface_x = Iface(x, "123")
    iface_x.run()
    x.set_iface(iface_x)
    iface_x.send("hello world")

    print("Running")