当前位置: 首页>>代码示例>>Python>>正文


Python authorizers.DummyAuthorizer方法代码示例

本文整理汇总了Python中pyftpdlib.authorizers.DummyAuthorizer方法的典型用法代码示例。如果您正苦于以下问题:Python authorizers.DummyAuthorizer方法的具体用法?Python authorizers.DummyAuthorizer怎么用?Python authorizers.DummyAuthorizer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyftpdlib.authorizers的用法示例。


在下文中一共展示了authorizers.DummyAuthorizer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_override_perm_recursive_paths

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def test_override_perm_recursive_paths(self):
        auth = DummyAuthorizer()
        auth.add_user(USER, PASSWD, HOME, perm='elr')
        self.assertEqual(auth.has_perm(USER, 'w', self.tempdir), False)
        auth.override_perm(USER, self.tempdir, perm='w', recursive=True)
        self.assertEqual(auth.has_perm(USER, 'w', HOME), False)
        self.assertEqual(auth.has_perm(USER, 'w', self.tempdir), True)
        self.assertEqual(auth.has_perm(USER, 'w', self.tempfile), True)
        self.assertEqual(auth.has_perm(USER, 'w', self.subtempdir), True)
        self.assertEqual(auth.has_perm(USER, 'w', self.subtempfile), True)

        self.assertEqual(auth.has_perm(USER, 'w', HOME + '@'), False)
        self.assertEqual(auth.has_perm(USER, 'w', self.tempdir + '@'), False)
        path = os.path.join(self.tempdir + '@',
                            os.path.basename(self.tempfile))
        self.assertEqual(auth.has_perm(USER, 'w', path), False)
        # test case-sensitiveness
        if (os.name in ('nt', 'ce')) or (sys.platform == 'cygwin'):
            self.assertEqual(auth.has_perm(USER, 'w',
                             self.tempdir.upper()), True) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:22,代码来源:test_authorizers.py

示例2: test_override_perm_not_recursive_paths

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def test_override_perm_not_recursive_paths(self):
        auth = DummyAuthorizer()
        auth.add_user(USER, PASSWD, HOME, perm='elr')
        self.assertEqual(auth.has_perm(USER, 'w', self.tempdir), False)
        auth.override_perm(USER, self.tempdir, perm='w')
        self.assertEqual(auth.has_perm(USER, 'w', HOME), False)
        self.assertEqual(auth.has_perm(USER, 'w', self.tempdir), True)
        self.assertEqual(auth.has_perm(USER, 'w', self.tempfile), True)
        self.assertEqual(auth.has_perm(USER, 'w', self.subtempdir), False)
        self.assertEqual(auth.has_perm(USER, 'w', self.subtempfile), False)

        self.assertEqual(auth.has_perm(USER, 'w', HOME + '@'), False)
        self.assertEqual(auth.has_perm(USER, 'w', self.tempdir + '@'), False)
        path = os.path.join(self.tempdir + '@',
                            os.path.basename(self.tempfile))
        self.assertEqual(auth.has_perm(USER, 'w', path), False)
        # test case-sensitiveness
        if (os.name in ('nt', 'ce')) or (sys.platform == 'cygwin'):
            self.assertEqual(auth.has_perm(USER, 'w', self.tempdir.upper()),
                             True) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:22,代码来源:test_authorizers.py

示例3: __init__

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def __init__(self, addr=None):
        threading.Thread.__init__(self)
        self._timeout = None
        self._serving = False
        self._stopped = False
        if addr is None:
            addr = (HOST, 0)

        authorizer = DummyAuthorizer()
        authorizer.add_user(USER, PASSWD, HOME, perm='elradfmwM')  # full perms
        authorizer.add_anonymous(HOME)
        self.handler.authorizer = authorizer
        # lower buffer sizes = more "loops" while transfering data
        # = less false positives
        self.handler.dtp_handler.ac_in_buffer_size = 4096
        self.handler.dtp_handler.ac_out_buffer_size = 4096
        self.server = self.server_class(addr, self.handler)
        self.host, self.port = self.server.socket.getsockname()[:2] 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:20,代码来源:__init__.py

示例4: main

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def main():
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()

    # anonymous user
    authorizer.add_anonymous(os.getcwd())

    # Instantiate FTP handler class
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.permit_foreign_addresses = True

    # Instantiate FTP server class and listen on 0.0.0.0:21
    address = ('', 21)
    server = FTPServer(address, handler)

    # start ftp server
    server.serve_forever() 
开发者ID:hunters-forge,项目名称:mordor,代码行数:20,代码来源:ftp_server_start.py

示例5: test_override_perm_recursive_paths

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def test_override_perm_recursive_paths(self):
        auth = DummyAuthorizer()
        auth.add_user(USER, PASSWD, HOME, perm='elr')
        self.assertEqual(auth.has_perm(USER, 'w', self.tempdir), False)
        auth.override_perm(USER, self.tempdir, perm='w', recursive=True)
        self.assertEqual(auth.has_perm(USER, 'w', HOME), False)
        self.assertEqual(auth.has_perm(USER, 'w', self.tempdir), True)
        self.assertEqual(auth.has_perm(USER, 'w', self.tempfile), True)
        self.assertEqual(auth.has_perm(USER, 'w', self.subtempdir), True)
        self.assertEqual(auth.has_perm(USER, 'w', self.subtempfile), True)

        self.assertEqual(auth.has_perm(USER, 'w', HOME + '@'), False)
        self.assertEqual(auth.has_perm(USER, 'w', self.tempdir + '@'), False)
        path = os.path.join(self.tempdir + '@',
                            os.path.basename(self.tempfile))
        self.assertEqual(auth.has_perm(USER, 'w', path), False)
        # test case-sensitiveness
        if (os.name in ('nt', 'ce')) or (sys.platform == 'cygwin'):
            self.assertTrue(auth.has_perm(USER, 'w', self.tempdir.upper())) 
开发者ID:giampaolo,项目名称:pyftpdlib,代码行数:21,代码来源:test_authorizers.py

示例6: main

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', os.getcwd(), perm='elradfmwMT')
    authorizer.add_anonymous(os.getcwd())

    dtp_handler = ThrottledDTPHandler
    dtp_handler.read_limit = 30720  # 30 Kb/sec (30 * 1024)
    dtp_handler.write_limit = 30720  # 30 Kb/sec (30 * 1024)

    ftp_handler = FTPHandler
    ftp_handler.authorizer = authorizer
    # have the ftp handler use the alternative dtp handler class
    ftp_handler.dtp_handler = dtp_handler

    server = FTPServer(('', 2121), ftp_handler)
    server.serve_forever() 
开发者ID:giampaolo,项目名称:pyftpdlib,代码行数:18,代码来源:throttled_ftpd.py

示例7: setUpClass

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def setUpClass(cls):
        from pyftpdlib.test import ThreadedTestFTPd

        super(TestFTPFS, cls).setUpClass()

        cls._temp_dir = tempfile.mkdtemp("ftpfs2tests")
        cls._temp_path = os.path.join(cls._temp_dir, text_type(uuid.uuid4()))
        os.mkdir(cls._temp_path)

        cls.server = ThreadedTestFTPd()
        cls.server.shutdown_after = -1
        cls.server.handler.authorizer = DummyAuthorizer()
        cls.server.handler.authorizer.add_user(
            cls.user, cls.pasw, cls._temp_path, perm="elradfmw"
        )
        cls.server.handler.authorizer.add_anonymous(cls._temp_path)
        cls.server.start()

        # Don't know why this is necessary on Windows
        if platform.system() == "Windows":
            time.sleep(0.1)
        # Poll until a connection can be made
        if not cls.server.is_alive():
            raise RuntimeError("could not start FTP server.") 
开发者ID:PyFilesystem,项目名称:pyfilesystem2,代码行数:26,代码来源:test_ftpfs.py

示例8: test_override_perm_interface

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def test_override_perm_interface(self):
        auth = DummyAuthorizer()
        auth.add_user(USER, PASSWD, HOME, perm='elr')
        # raise exc if user does not exists
        self.assertRaises(KeyError, auth.override_perm, USER + 'w',
                          HOME, 'elr')
        # raise exc if path does not exist or it's not a directory
        self.assertRaisesRegex(ValueError,
                               'no such directory',
                               auth.override_perm, USER, '?:\\', 'elr')
        self.assertRaisesRegex(ValueError,
                               'no such directory',
                               auth.override_perm, USER, self.tempfile, 'elr')
        # raise on wrong permission
        self.assertRaisesRegex(ValueError,
                               "no such permission", auth.override_perm,
                               USER, HOME, perm='?')
        # expect warning on write permissions assigned to anonymous user
        auth.add_anonymous(HOME)
        for p in "adfmw":
            self.assertRaisesRegex(
                RuntimeWarning,
                "write permissions assigned to anonymous user.",
                auth.override_perm, 'anonymous', HOME, p)
        # raise on attempt to override home directory permissions
        self.assertRaisesRegex(ValueError,
                               "can't override home directory permissions",
                               auth.override_perm, USER, HOME, perm='w')
        # raise on attempt to override a path escaping home directory
        if os.path.dirname(HOME) != HOME:
            self.assertRaisesRegex(ValueError,
                                   "path escapes user home directory",
                                   auth.override_perm, USER,
                                   os.path.dirname(HOME), perm='w')
        # try to re-set an overridden permission
        auth.override_perm(USER, self.tempdir, perm='w')
        auth.override_perm(USER, self.tempdir, perm='wr') 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:39,代码来源:test_authorizers.py

示例9: start

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def start(self):

        self.authorizer = DummyAuthorizer()


        if self.config.get('usessl') == 'Yes':
            self.logger.debug('Using SSL socket.')

            keyfile_path = 'listeners/ssl_utils/privkey.pem'
            keyfile_path = ListenerBase.abs_config_path(keyfile_path)
            if keyfile_path is None:
                self.logger.error('Could not locate %s', keyfile_path)
                sys.exit(1)

            self.handler = TLS_FakeFTPHandler
            self.handler.certfile = keyfile_path

        else:
            self.handler = FakeFTPHandler

        self.handler.banner = self.genBanner()

        self.handler.ftproot_path = self.ftproot_path
        self.handler.abstracted_fs = FakeFS

        self.handler.authorizer = self.authorizer
        self.handler.passive_ports = self.expand_ports(self.config.get('pasvports', '60000-60010'))


        self.server = ThreadedFTPServer((self.local_ip, int(self.config['port'])), self.handler)

        # Override pyftpdlib logger name
        logging.getLogger('pyftpdlib').name = self.name


        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.daemon = True
        self.server_thread.start() 
开发者ID:fireeye,项目名称:flare-fakenet-ng,代码行数:40,代码来源:FTPListener.py

示例10: run

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def run(ns):
    """starts the server."""
    auth = DummyAuthorizer()
    if ns.user is not None:
        auth.add_user(ns.user, ns.pswd, ns.path, perm=ns.perm)
    else:
        auth.add_anonymous(ns.path, perm=ns.perm)
    handler = FTPHandler
    handler.authorizer = auth
    handler.banner = "StaSh v{v} FTP-Server".format(v=_stash.__version__)
    address = ("0.0.0.0", ns.port)
    server = FTPServer(address, handler)
    server.max_cons = 128
    server.max_cons_per_ip = 128
    # setup logging
    logger = logging.getLogger("pyftpdlib")
    logger.setLevel(logging.CRITICAL)
    logger.propagate = False
    # server needs to run in a thread to be killable
    thr = threading.Thread(name="FTP-Server Thread", target=server.serve_forever)
    thr.daemon = True
    thr.start()
    print("FTP-Server started on {h}:{p}".format(h=address[0], p=str(address[1])))
    try:
        while True:
            time.sleep(0.2)
    except KeyboardInterrupt:
        print("Stopping Server...")
        server.close_all() 
开发者ID:ywangd,项目名称:stash,代码行数:31,代码来源:ftpserver.py

示例11: run

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def run(self):
        authorizer = DummyAuthorizer()
        authorizer.add_user(self.username, self.password, os.environ['HOME'], perm="elradfmw")

        handler = FTPHandler
        handler.authorizer = authorizer

        self.__server = FTPServer(('0.0.0.0', self.port), handler)

        if self.enabled:
            ftp_thread = threading.Thread(target=self.__server.serve_forever)
            ftp_thread.daemon = True
            ftp_thread.start() 
开发者ID:gamer-os,项目名称:steam-buddy,代码行数:15,代码来源:server.py

示例12: setup_server

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def setup_server(handler, server_class, addr=None):
    addr = (HOST, 0) if addr is None else addr
    authorizer = DummyAuthorizer()
    # full perms
    authorizer.add_user(USER, PASSWD, HOME, perm='elradfmwMT')
    authorizer.add_anonymous(HOME)
    handler.authorizer = authorizer
    handler.auth_failed_timeout = 0.001
    # lower buffer sizes = more "loops" while transfering data
    # = less false positives
    handler.dtp_handler.ac_in_buffer_size = 4096
    handler.dtp_handler.ac_out_buffer_size = 4096
    server = server_class(addr, handler)
    return server 
开发者ID:giampaolo,项目名称:pyftpdlib,代码行数:16,代码来源:__init__.py

示例13: main

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.', perm='elradfmwMT')
    authorizer.add_anonymous('.')
    handler = AntiFloodHandler
    handler.authorizer = authorizer
    server = FTPServer(('', 2121), handler)
    server.serve_forever(timeout=1) 
开发者ID:giampaolo,项目名称:pyftpdlib,代码行数:10,代码来源:anti_flood_ftpd.py

示例14: main

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.')
    handler = FTPHandler
    handler.authorizer = authorizer
    server = ThreadedFTPServer(('', 2121), handler)
    server.serve_forever() 
开发者ID:giampaolo,项目名称:pyftpdlib,代码行数:9,代码来源:multi_thread_ftp.py

示例15: main

# 需要导入模块: from pyftpdlib import authorizers [as 别名]
# 或者: from pyftpdlib.authorizers import DummyAuthorizer [as 别名]
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.')
    handler = FTPHandler
    handler.authorizer = authorizer
    server = MultiprocessFTPServer(('', 2121), handler)
    server.serve_forever() 
开发者ID:giampaolo,项目名称:pyftpdlib,代码行数:9,代码来源:multi_proc_ftp.py


注:本文中的pyftpdlib.authorizers.DummyAuthorizer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。