def init_loggers(verbose_level): _set_verbose_level(verbose_level) modules_with_loggers = [ import_module(module) for module in MODULES_WITH_LOGGERS ] for lib in modules_with_loggers: lib.logger = init_logger(lib.LOGGER_NAME)
def imp(self, spec): # This serves as a backwards compatibility if type(spec) is dict: # Old style... for key, vals in spec.items(): for val in vals: if isinstance(val, dict): if not self.check_validity: val["check_validity"] = False self.load(key, **val) else: self.load(key, val) else: for item in spec: try: key = item['class'] except (KeyError, AttributeError): raise SAMLError("Misconfiguration in metadata %s" % item) mod, clas = key.rsplit('.', 1) try: mod = import_module(mod) MDloader = getattr(mod, clas) except (ImportError, AttributeError): raise SAMLError("Unknown metadata loader %s" % key) # Separately handle MDExtern if MDloader == MetaDataExtern: kwargs = { 'http': self.http, 'security': self.security } else: kwargs = {} if self.filter: kwargs["filter"] = self.filter for key in item['metadata']: # Separately handle MetaDataFile and directory if MDloader == MetaDataFile and os.path.isdir(key[0]): files = [f for f in os.listdir(key[0]) if isfile(join(key[0], f))] for fil in files: _fil = join(key[0], fil) _md = MetaDataFile(self.attrc, _fil) _md.load() self.metadata[_fil] = _md if _md.to_old: self.to_old[_fil] = _md.to_old return if len(key) == 2: kwargs["cert"] = key[1] _md = MDloader(self.attrc, key[0], **kwargs) _md.load() self.metadata[key[0]] = _md if _md.to_old: self.to_old[key[0]] = _md.to_old
def test_init_loggers(): init_loggers(logging.INFO) modules_with_loggers = [ import_module(module) for module in MODULES_WITH_LOGGERS ] for module in modules_with_loggers: assert isinstance(module.logger, _loggerClass)
def _load(self, fil): head, tail = os.path.split(fil) if head == "": if sys.path[0] != ".": sys.path.insert(0, ".") else: sys.path.insert(0, head) return import_module(tail)
def test_templates(self): """Templates can compile properly and there's no mismatched tags""" # get app template dirs template_dirs = [] apps = [app for app in settings.INSTALLED_APPS] for app in apps: mod = import_module(app) template_dirs.append( path.join(path.dirname(mod.__file__), 'templates')) # find all templates (*.html) print("this is template dirs", template_dirs) templates = [] for template_dir in template_dirs: templates += glob.glob('%s/*.html' % template_dir) for root, dirnames, filenames in walk(template_dir): for dirname in dirnames: template_folder = path.join(root, dirname) templates += glob.glob('%s/*.html' % template_folder) for template in templates: # print(template) with open(template, 'r') as f: source = f.read() # template compilation fails on impaired or invalid blocks tags try: Template(source) except TemplateSyntaxError as e: raise TemplateSyntaxError('%s in %s' % (e, template)) # check for badly formatted tags or filters self.assertEqual(source.count('{%'), source.count('%}'), "Found impaired {%% and %%} in %s" % template) self.assertEqual(source.count('{{'), source.count('}}'), "Found impaired {{ and }} in %s" % template) # create an object of BeautifulSoup soup = BeautifulSoup(f, 'html.parser') # Check if the HTML File has a title tag self.assertIsNotNone( soup.title, "Template -> " + str(template) + " Does not have a title Tag\n") # check if the title tag is empty self.assertIsNotNone( soup.title.string, "Template -> " + str(template) + " Does not have a title\n") # check if head tag is defined more than once self.assertEquals(len(soup.find_all('head')), 1, "Head Tag defined more than once")
def get_metadata_loader(func): if hasattr(func, '__call__'): return func i = func.rfind('.') module, attr = func[:i], func[i + 1:] try: mod = import_module(module) except Exception as e: raise RuntimeError( 'Cannot find metadata provider function %s: "%s"' % (func, e)) try: metadata_loader = getattr(mod, attr) except AttributeError: raise RuntimeError( 'Module "%s" does not define a "%s" metadata loader' % ( module, attr)) if not hasattr(metadata_loader, '__call__'): raise RuntimeError( 'Metadata loader %s.%s must be callable' % (module, attr)) return metadata_loader
from __future__ import absolute_import, division, print_function, unicode_literals from future.builtins import filter, str from future import utils import os import sys import ssl import pprint import socket from future.backports.urllib import parse as urllib_parse from future.backports.http.server import (HTTPServer as _HTTPServer, SimpleHTTPRequestHandler, BaseHTTPRequestHandler) from future.backports.test import support threading = support.import_module("threading") here = os.path.dirname(__file__) HOST = support.HOST CERTFILE = os.path.join(here, 'keycert.pem') # This one's based on HTTPServer, which is based on SocketServer class HTTPSServer(_HTTPServer): def __init__(self, server_address, handler_class, context): _HTTPServer.__init__(self, server_address, handler_class) self.context = context def __str__(self): return ('<%s %s:%s>' % (self.__class__.__name__, self.server_name,
from future.builtins import filter, str from future import utils import os import sys import ssl import pprint import socket from future.backports.urllib import parse as urllib_parse from future.backports.http.server import ( HTTPServer as _HTTPServer, SimpleHTTPRequestHandler, BaseHTTPRequestHandler, ) from future.backports.test import support threading = support.import_module("threading") here = os.path.dirname(__file__) HOST = support.HOST CERTFILE = os.path.join(here, "keycert.pem") # This one's based on HTTPServer, which is based on SocketServer class HTTPSServer(_HTTPServer): def __init__(self, server_address, handler_class, context): _HTTPServer.__init__(self, server_address, handler_class) self.context = context def __str__(self):