index
int64
repo_name
string
branch_name
string
path
string
content
string
import_graph
string
35,059,238
hendrix/hendrix
refs/heads/main
/examples/django_hx_chatserver/example_app/chat/views.py
from django.shortcuts import render from .models import ChatMessage # Create your views here. def home(request, chat_channel_name=None): """ if we have a chat_channel_name kwarg, have the response include that channel name so the javascript knows to subscribe to that channel... """ if not chat_channel_name: chat_channel_name = 'homepage' context = { 'address': chat_channel_name, 'history': [], } if ChatMessage.objects.filter(channel=chat_channel_name).exists(): context['history'] = ChatMessage.objects.filter( channel=chat_channel_name) # TODO add https websocket_prefix = "ws" websocket_port = 9000 context['websocket_prefix'] = websocket_prefix context['websocket_port'] = websocket_port return render(request, 'chat.html', context)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,239
hendrix/hendrix
refs/heads/main
/test/debug_test_application.py
''' Runs the test WSGI application on a real HendrixDeploy. Useful for poking and prodding to discover how to cover those hard-to-reach parts of the service flow. ''' from twisted.internet import reactor from hendrix.deploy.base import HendrixDeploy from resources import application if __name__ == "__main__": threadPool = reactor.getThreadPool() threadPool.adjustPoolsize(3, 5) options = {'wsgi': application} deployer = HendrixDeploy(options=options) deployer.run()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,240
hendrix/hendrix
refs/heads/main
/hendrix/mechanics/concurrency/__init__.py
import threading from hendrix.mechanics.concurrency.exceptions import ThreadHasNoResponse def get_response_for_thread(thread=None): if not thread: thread = threading.current_thread() try: response = thread.response_object except AttributeError: raise ThreadHasNoResponse('thread %s has no associated response object.' % thread) return response def get_tasks_to_follow_current_response(thread=None): response = get_response_for_thread(thread) return response.crosstown_tasks
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,241
hendrix/hendrix
refs/heads/main
/examples/django_hx_chatserver/example_app/chat/models.py
from django.db import models from django.template import loader from django.utils import timezone from hendrix.contrib.concurrency.signals import message_signal from hendrix.experience import hey_joe # Create your models here. class ChatMessage(models.Model): """ a model that stores chat history """ sender = models.CharField(max_length=100) channel = models.CharField(max_length=100, db_index=True) content = models.TextField('enter a message') date_created = models.DateTimeField(default=timezone.now) def save_chat_message(*args, **kwargs): """ kwargs will always include: 'data': # will always be exactly what your client sent on the socket # in this case... {u'message': u'hi', u'sender': u'anonymous', u'channel': u'homepage'}, 'dispatcher': # the dispatcher that will allow for broadcasting a response <hendrix.contrib.concurrency.messaging.MessageDispatcher object at 0x10ddb1c10>, """ data = kwargs.get('data') if data.get('message') and data.get('channel'): cm = ChatMessage.objects.create( sender=data.get('sender'), content=data.get('message'), channel=data.get('channel') ) t = loader.get_template('message.html') # now send broadcast a message back to anyone listening on the channel hey_joe.send({'html': t.render({'message': cm})}, cm.channel) message_signal.connect(save_chat_message)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,242
hendrix/hendrix
refs/heads/main
/hendrix/ux.py
""" A module to encapsulate the user experience logic """ from __future__ import with_statement import os import re import subprocess import sys import time import traceback import chalk from twisted.logger import globalLogPublisher from watchdog.events import FileSystemEventHandler from watchdog.observers import Observer from hendrix.contrib import SettingsError from hendrix.deploy import base, cache from hendrix.logger import hendrixObserver from hendrix.mechanics.concurrency.exceptions import RedisException from hendrix.options import cleanOptions from .options import HendrixOptionParser try: from tiempo.conn import REDIS from tiempo.locks import lock_factory redis_available = True except ImportError: redis_available = False class Reload(FileSystemEventHandler): def __init__(self, options, *args, **kwargs): super(Reload, self).__init__(*args, **kwargs) self.reload, self.options = cleanOptions(options) if not self.reload: raise RuntimeError( 'Reload should not be run if --reload has not been passed to ' 'the command as an option.' ) self.process = subprocess.Popen( ['hx', 'start_reload'] + self.options ) def on_any_event(self, event): if event.is_directory: return ext = os.path.splitext(event.src_path)[1] if ext == '.py': self.process = self.restart() chalk.eraser() chalk.yellow("Detected changes, restarting...") def restart(self): self.process.kill() process = subprocess.Popen( ['hx', 'start_reload'] + self.options ) return process def hendrixLauncher(action, options, with_tiempo=False): """ Decides which version of HendrixDeploy to use and then launches it. """ if options['key'] and options['cert'] and options['cache']: from hendrix.deploy import hybrid HendrixDeploy = hybrid.HendrixDeployHybrid elif options['key'] and options['cert']: from hendrix.deploy import tls HendrixDeploy = tls.HendrixDeployTLS elif options['cache']: HendrixDeploy = cache.HendrixDeployCache else: HendrixDeploy = base.HendrixDeploy if with_tiempo: deploy = HendrixDeploy(action='start', options=options) deploy.run() else: deploy = HendrixDeploy(action, options) deploy.run() def assignDeploymentInstance(action, options): try: hendrixLauncher(action, options) except Exception as e: tb = sys.exc_info()[2] msg = traceback.format_exc(tb) chalk.red(msg, pipe=chalk.stderr) os._exit(1) def logReload(options): """ encompasses all the logic for reloading observer. """ event_handler = Reload(options) observer = Observer() observer.schedule(event_handler, path='.', recursive=True) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() pid = os.getpid() chalk.eraser() chalk.green('\nHendrix successfully closed.') os.kill(pid, 15) observer.join() exit('\n') def launch(*args, **options): """ launch acts on the user specified action and options by executing Hedrix.run """ action = args[0] if options['reload']: logReload(options) else: assignDeploymentInstance(action, options) def findSettingsModule(): "Find the settings module dot path within django's manage.py file" try: with open('manage.py', 'r') as manage: manage_contents = manage.read() search = re.search( r"([\"\'](?P<module>[a-z\.]+)[\"\'])", manage_contents ) if search: # django version < 1.7 settings_mod = search.group("module") else: # in 1.7, manage.py settings declaration looks like: # os.environ.setdefault( # "DJANGO_SETTINGS_MODULE", "example_app.settings" # ) search = re.search( "\".*?\"(,\\s)??\"(?P<module>.*?)\"\\)$", manage_contents, re.I | re.S | re.M ) settings_mod = search.group("module") os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_mod) except IOError as e: msg = ( str(e) + '\nPlease ensure that you are in the same directory ' 'as django\'s "manage.py" file.' ) raise IOError(chalk.red(msg), None, sys.exc_info()[2]) except AttributeError: settings_mod = '' return settings_mod def djangoVsWsgi(options): # settings logic if not options['wsgi']: settings_mod = findSettingsModule() user_settings = options['settings'] if not settings_mod and not user_settings: msg = ( '\nEither specify:\n--settings mysettings.dot.path\nOR\n' 'export DJANGO_SETTINGS_MODULE="mysettings.dot.path"\nOR\n' 'in your manage.py file specify ' 'os.environ.setdefault("DJANGO_SETTINGS_MODULE", ' '"mysettings.dot.path")' ) raise SettingsError(chalk.red(msg), None, sys.exc_info()[2]) elif user_settings: # if the user specified the settings to use then these take # precedence options['settings'] = user_settings elif settings_mod: options['settings'] = settings_mod else: try: base.HendrixDeploy.importWSGI(options['wsgi']) except ImportError: raise ImportError("The path '%s' does not exist" % options['wsgi']) return options def exposeProject(options): # sys.path logic if options['pythonpath']: project_path = options['pythonpath'] if not os.path.exists(project_path): raise IOError("The path '%s' does not exist" % project_path) sys.path.append(project_path) else: sys.path.append(os.getcwd()) def devFriendly(options): # if the dev option is given then also set reload to true # note that clean options will remove reload so to honor that we use get # in the second part of the conditional dev_mode = options['dev'] options['reload'] = True if dev_mode else options.get('reload', False) options['loud'] = True if dev_mode else options['loud'] return options def noiseControl(options): # terminal noise/info logic # allows the specification of the log file location if not options['loud']: log_path = options['log'] globalLogPublisher.addObserver(hendrixObserver(log_path)) return None def subprocessLaunch(): """ This function is called by the hxw script. It takes no arguments, and returns an instance of HendrixDeploy """ if not redis_available: raise RedisException("can't launch this subprocess without tiempo/redis.") try: action = 'start' options = REDIS.get('worker_args') assignDeploymentInstance(action='start', options=options) except Exception: chalk.red('\n Encountered an unhandled exception while trying to %s hendrix.\n' % action, pipe=chalk.stderr) raise def main(args=None): "The function to execute when running hx" if args is None: args = sys.argv[1:] options, args = HendrixOptionParser.parse_args(args) options = vars(options) try: action = args[0] except IndexError: HendrixOptionParser.print_help() return exposeProject(options) options = djangoVsWsgi(options) options = devFriendly(options) redirect = noiseControl(options) try: launch(*args, **options) except Exception: chalk.red('\n Encountered an unhandled exception while trying to %s hendrix.\n' % action, pipe=chalk.stderr) raise
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,243
hendrix/hendrix
refs/heads/main
/hendrix/deploy/base.py
import importlib import os import pickle import shutil import time from os import environ from socket import AF_INET import autobahn import chalk from twisted.application.internet import TCPServer, SSLServer from twisted.internet import reactor from twisted.internet.defer import DeferredLock from twisted.python.threadpool import ThreadPool from hendrix import defaults from hendrix.facilities.gather import get_additional_resources, get_additional_services from hendrix.facilities.protocols import DeployServerProtocol from hendrix.facilities.services import HendrixService, HendrixTCPService from hendrix.options import options as hx_options from hendrix.utils import get_pid, import_string, PID_DIR class HendrixDeploy(object): """ HendrixDeploy encapsulates the necessary information needed to deploy the HendrixService on a single or multiple processes. """ def __init__(self, action='start', options={}, reactor=reactor, threadpool=None): self.action = action self.options = hx_options() self.options.update(options) self.services = [] self.resources = [] self.reactor = reactor self.threadpool = threadpool or ThreadPool(name="Hendrix Web Service") self.use_settings = True # because running the management command overrides self.options['wsgi'] if self.options['wsgi']: self.services = self.options.get('services') self.resources = self.options.get('resources') if hasattr(self.options['wsgi'], '__call__'): # If it has a __call__, we assume that it is the application # object itself. self.application = self.options['wsgi'] try: self.options['wsgi'] = "%s.%s" % ( self.application.__module__, self.application.__name__ ) except AttributeError: self.options['wsgi'] = self.application.__class__.__name__ else: # Otherwise, we'll try to discern an application in the belief # that this is a dot path. wsgi_dot_path = self.options['wsgi'] # will raise AttributeError if we can't import it. self.application = HendrixDeploy.importWSGI(wsgi_dot_path) self.use_settings = False else: os.environ['DJANGO_SETTINGS_MODULE'] = self.options['settings'] settings = import_string('django.conf.settings') self.services = get_additional_services(settings) self.resources = get_additional_resources(settings) self.options = HendrixDeploy.getConf(settings, self.options) if self.use_settings: django = importlib.import_module('django') if django.VERSION[:2] >= (1, 7): django.setup() wsgi_dot_path = getattr(settings, 'WSGI_APPLICATION', None) self.application = HendrixDeploy.importWSGI(wsgi_dot_path) self.is_secure = self.options['key'] and self.options['cert'] self.servers = [] self._lock = DeferredLock() @classmethod def importWSGI(cls, wsgi_dot_path): try: wsgi_module, application_name = wsgi_dot_path.rsplit('.', 1) except AttributeError: pid = os.getpid() chalk.red( "Unable to discern a WSGI application from '%s'" % wsgi_dot_path ) os.kill(pid, 15) try: wsgi = importlib.import_module(wsgi_module) except ImportError: chalk.red("Unable to Import module '%s'\n" % wsgi_dot_path) raise return getattr(wsgi, application_name, None) @classmethod def getConf(cls, settings, options): "updates the options dict to use config options in the settings module" ports = ['http_port', 'https_port', 'cache_port'] for port_name in ports: port = getattr(settings, port_name.upper(), None) # only use the settings ports if the defaults were left unchanged default = getattr(defaults, port_name.upper()) if port and options.get(port_name) == default: options[port_name] = port _opts = [ ('key', 'hx_private_key'), ('cert', 'hx_certficate'), ('wsgi', 'wsgi_application') ] for opt_name, settings_name in _opts: opt = getattr(settings, settings_name.upper(), None) if opt: options[opt_name] = opt if not options['settings']: options['settings'] = environ['DJANGO_SETTINGS_MODULE'] return options def addServices(self): """ a helper function used in HendrixDeploy.run it instanstiates the HendrixService and adds child services note that these services will also be run on all processes """ self.addHendrix() def addGlobalServices(self): """ This is where we put service that we don't want to be duplicated on worker subprocesses """ pass def getThreadPool(self): ''' Case to match twisted.internet.reactor ''' return self.threadpool def addHendrix(self): ''' Instantiates a HendrixService with this object's threadpool. It will be added as a service later. ''' self.hendrix = HendrixService( self.application, threadpool=self.getThreadPool(), resources=self.resources, services=self.services, loud=self.options['loud'] ) if self.options["https_only"] is not True: self.hendrix.spawn_new_server(self.options['http_port'], HendrixTCPService, max_upload_bytes=self.options['max_upload_bytes']) def catalogServers(self, hendrix): "collects a list of service names serving on TCP or SSL" for service in hendrix.services: if isinstance(service, (TCPServer, SSLServer)): self.servers.append(service.name) def _listening_message(self): message = "non-TLS listening on port {}".format(self.options['http_port']) return message def run(self): "sets up the desired services and runs the requested action" self.addServices() self.catalogServers(self.hendrix) action = self.action fd = self.options['fd'] if action.startswith('start'): chalk.blue(self._listening_message()) getattr(self, action)(fd) ########################### # annnnd run the reactor! # ########################### try: self.reactor.run() finally: shutil.rmtree(PID_DIR, ignore_errors=True) # cleanup tmp PID dir elif action == 'restart': getattr(self, action)(fd=fd) else: getattr(self, action)() @property def pid(self): "The default location of the pid file for process management" return get_pid(self.options) def getSpawnArgs(self): _args = [ 'hx', 'start', # action # kwargs '--http_port', str(self.options['http_port']), '--https_port', str(self.options['https_port']), '--cache_port', str(self.options['cache_port']), '--workers', '0', '--fd', pickle.dumps(self.fds), ] # args/signals if self.options['dev']: _args.append('--dev') if not self.use_settings: _args += ['--wsgi', self.options['wsgi']] return _args def start(self, fd=None): if fd is None: # anything in this block is only run once self.addGlobalServices() self.hendrix.startService() pids = [str(os.getpid())] # script pid if self.options['workers']: self.launchWorkers(pids) self.pid_file = self.openPidList(pids) else: fds = pickle.loads(fd) factories = {} for name in self.servers: factory = self.disownService(name) factories[name] = factory self.hendrix.startService() for name, factory in factories.iteritems(): self.addSubprocess(fds, name, factory) chalk.eraser() chalk.blue('Starting Hendrix...') def setFDs(self): """ Iterator for file descriptors. Seperated from launchworkers for clarity and readability. """ # 0 corresponds to stdin, 1 to stdout, 2 to stderr self.childFDs = {0: 0, 1: 1, 2: 2} self.fds = {} for name in self.servers: self.port = self.hendrix.get_port(name) fd = self.port.fileno() self.childFDs[fd] = fd self.fds[name] = fd def launchWorkers(self, pids): # Create a new listening port and several other processes to # help out. self.setFDs() args = self.getSpawnArgs() transports = [] for i in range(self.options['workers']): time.sleep(0.05) transport = self.reactor.spawnProcess( DeployServerProtocol(args), 'hx', args, childFDs=self.childFDs, env=environ ) transports.append(transport) pids.append(str(transport.pid)) def openPidList(self, pids): with open(self.pid, 'w') as pid_file: pid_file.write('\n'.join(pids)) return pid_file def addSubprocess(self, fds, name, factory): """ Public method for _addSubprocess. Wraps reactor.adoptStreamConnection in a simple DeferredLock to guarantee workers play well together. """ self._lock.run(self._addSubprocess, self, fds, name, factory) def _addSubprocess(self, fds, name, factory): self.reactor.adoptStreamConnection( fds[name], AF_INET, factory ) def stop(self, sig=9): with open(self.pid) as pid_file: pids = pid_file.readlines() for pid in pids: try: os.kill(int(pid), sig) except OSError: # OSError raised when it trys to kill the child processes pass os.remove(self.pid) chalk.green('Stopping Hendrix...') def start_reload(self, fd=None): self.start(fd=fd) def restart(self, fd=None): self.stop() time.sleep(1) # wait a second to ensure the port is closed self.start(fd) def disownService(self, name): """ disowns a service on hendirix by name returns a factory for use in the adoptStreamPort part of setting up multiple processes """ _service = self.hendrix.getServiceNamed(name) _service.disownServiceParent() return _service.factory def add_non_tls_websocket_service(self, websocket_factory): autobahn.twisted.websocket.listenWS(websocket_factory)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,244
hendrix/hendrix
refs/heads/main
/hendrix/contrib/__init__.py
class SettingsError(Exception): "Because we don't to inherit ImproperlyConfigured..." pass
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,245
hendrix/hendrix
refs/heads/main
/hendrix/contrib/concurrency/messaging.py
import copy import json import uuid import warnings warnings.warn("hendrix.contrib.concurrency.messaging is being deprecated. Use hendrix.experience.hey_joe instead.", DeprecationWarning) class RecipientManager(object): """ This class manages all the transports addressable by a single address. """ def __init__(self, transport, address): self.address = address self.transports = {} if transport is not None: self.add(transport) def __repr__(self): return 'RecipientManager object at %s with %d recipients' % ( self.address, len(self.transports) ) def add(self, transport): """ add a transport """ self.transports[transport.uid] = transport def send(self, message): # usually a json string... """ sends whatever it is to each transport """ for transport in self.transports.values(): transport.protocol.sendMessage(message) def remove(self, transport): """ removes a transport if a member of this group """ if transport.uid in self.transports: del (self.transports[transport.uid]) class MessageDispatcher(object): """ MessageDispatcher is a PubSub state machine that routes data packets through an attribute called "recipients". The recipients attribute is a dict structure where the keys are unique addresses and the values are instances of RecipientManager. "address"es (i.e. RecipientManagers) are created and/or subscribed to. Subscribing to an address results in registering a clientswebsocket (i.e. the transport associated to the SockJSResource protocol) within a dict that is internal to the Manager called "transports". RecipientManager's purpose is to expose functions that MessageDispatcher can leverage to execute the PubSub process. N.B. subscribing a client to an address opens that client to all data published to that address. As such it useful to think of addresses as channels. To acheive a private channel an obsure address is required. """ def __init__(self, *args, **kwargs): self.recipients = {} def add(self, transport, address=None): """ add a new recipient to be addressable by this MessageDispatcher generate a new uuid address if one is not specified """ if not address: address = str(uuid.uuid1()) if address in self.recipients: self.recipients[address].add(transport) else: self.recipients[address] = RecipientManager(transport, address) return address def remove(self, transport): """ removes a transport from all channels to which it belongs. """ recipients = copy.copy(self.recipients) for address, recManager in recipients.items(): recManager.remove(transport) if not len(recManager.transports): del self.recipients[address] def send(self, address, data_dict): """ address can either be a string or a list of strings data_dict gets sent along as is and could contain anything """ if type(address) == list: recipients = [self.recipients.get(rec) for rec in address] else: recipients = [self.recipients.get(address)] if recipients: for recipient in recipients: if recipient: recipient.send(json.dumps(data_dict).encode()) def subscribe(self, transport, data): """ adds a transport to a channel """ self.add(transport, address=data.get('hx_subscribe').encode()) self.send( data['hx_subscribe'], {'message': "%r is listening" % transport} ) def send_json_message(address, message, **kwargs): """ a shortcut for message sending """ data = { 'message': message, } if not kwargs.get('subject_id'): data['subject_id'] = address data.update(kwargs) hxdispatcher.send(address, data) def send_callback_json_message(value, *args, **kwargs): """ useful for sending messages from callbacks as it puts the result of the callback in the dict for serialization """ if value: kwargs['result'] = value send_json_message(args[0], args[1], **kwargs) return value def send_errback_json_message(error, *args, **kwargs): kwargs['error'] = error.getErrorMessage() send_json_message(args[0], args[1], **kwargs) error.trap(RuntimeError) hxdispatcher = MessageDispatcher()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,246
hendrix/hendrix
refs/heads/main
/hendrix/deploy/tls.py
import chalk from autobahn.twisted.websocket import listenWS from twisted.internet import reactor from twisted.internet.ssl import PrivateCertificate, DefaultOpenSSLContextFactory from twisted.protocols.tls import TLSMemoryBIOFactory from hendrix.facilities.services import HendrixTCPServiceWithTLS from .base import HendrixDeploy class HendrixDeployTLS(HendrixDeploy): """ A HendrixDeploy that listens only via TLS. This class can accept a key and certificate combination and can also pass arbitrary kwargs to the SSLContextFactory which governs it use. Notice that there's no hazmat here. For the main service, all of the TLS is done through Twisted (and thus PyOpenSSL) via the HendrixTCPServiceWithTLS class, which is worth a look if you're interested in how this thing is secured. """ def __init__(self, action='start', options={}, reactor=reactor, threadpool=None, key=None, cert=None, context_factory=None, context_factory_kwargs=None, *args, **kwargs): super(HendrixDeployTLS, self).__init__(action, options, reactor, threadpool, *args, **kwargs) if options.get("https_port") and not options.get("http_port"): self.options["https_only"] = True key = key or self.options['key'] cert = cert or self.options['cert'] if not (key and cert): raise ValueError("Can't launch with TLS unless you pass a valid key and cert.") self.key = key self.cert = cert if context_factory is None: self.context_factory = DefaultOpenSSLContextFactory else: self.context_factory = context_factory if context_factory_kwargs is None: self.context_factory_kwargs = {} else: self.context_factory_kwargs = context_factory_kwargs def addServices(self): """ a helper function used in HendrixDeploy.run it instanstiates the HendrixService and adds child services note that these services will also be run on all processes """ super(HendrixDeployTLS, self).addServices() self.addSSLService() def addSSLService(self): "adds a SSLService to the instaitated HendrixService" https_port = self.options['https_port'] self.tls_service = HendrixTCPServiceWithTLS(https_port, self.hendrix.site, self.key, self.cert, self.context_factory, self.context_factory_kwargs, self.options['max_upload_bytes']) self.tls_service.setServiceParent(self.hendrix) def addSubprocesses(self, fds, name, factory): super(HendrixDeployTLS, self).addSubprocesses(fds, name, factory) if name == 'main_web_ssl': privateCert = PrivateCertificate.loadPEM( open(self.options['cert']).read() + open(self.options['key']).read() ) factory = TLSMemoryBIOFactory( privateCert.options(), False, factory ) def getSpawnArgs(self): args = super(HendrixDeployTLS, self).getSpawnArgs() args += [ '--key', self.options.get('key'), '--cert', self.options.get('cert') ] return args def _listening_message(self): message = "TLS listening on port {}".format(self.options['https_port']) if self.options['https_only'] is not True: message += " and non-TLS on port {}".format(self.options['http_port']) return message def _add_tls_websocket_service_after_running(self, websocket_factory, *args, **kwargs): chalk.blue("TLS websocket listener on port {}".format(websocket_factory.port)) listenWS(factory=websocket_factory, contextFactory=self.tls_service.tls_context, *args, **kwargs) def add_tls_websocket_service(self, websocket_factory, *args, **kwargs): self.reactor.callWhenRunning(self._add_tls_websocket_service_after_running, websocket_factory, *args, **kwargs)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,247
hendrix/hendrix
refs/heads/main
/hendrix/defaults.py
import os CACHE_PORT = 8080 HTTP_PORT = 8000 HTTPS_PORT = 4430 DEFAULT_MAX_AGE = 3600 DEFAULT_LOG_PATH = os.path.dirname(__file__) DEFAULT_LOG_FILE = os.path.join(DEFAULT_LOG_PATH, 'default-hendrix.log')
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,248
hendrix/hendrix
refs/heads/main
/test/test_resources.py
import unittest from twisted.web.resource import getChildForRequest, NoResource from twisted.web.test.requesthelper import DummyRequest try: from unittest import mock except ImportError: import mock from hendrix.facilities.resources import HendrixResource, NamedResource, WSGIResource class TestHendrixResource(unittest.TestCase): def setUp(self): path = b'/path/to/child/' self.res = NamedResource(path) self.hr = HendrixResource(None, None, None) self.hr.putNamedChild(self.res) def test_putNamedChild_success(self): with mock.patch('hendrix.facilities.resources.WSGIResource') as wsgi: request = DummyRequest([b'path', b'to', b'child']) actual_res = getChildForRequest(self.hr, request) self.assertEqual(actual_res, self.res) def test_putNamedChild_very_wrong_request(self): "check that requests outside of the children go to the WSGIResoure" with mock.patch('hendrix.facilities.resources.WSGIResource') as wsgi: request = DummyRequest([b'very', b'wrong', b'uri']) actual_res = getChildForRequest(self.hr, request) self.assertIsInstance(actual_res, WSGIResource) def test_putNamedChild_sort_of_wrong_request(self): "requests to incorrect subpaths go to NoResource" with mock.patch('hendrix.facilities.resources.WSGIResource') as wsgi: request = DummyRequest([b'path', b'to', b'wrong']) actual_res = getChildForRequest(self.hr, request) self.assertIsInstance(actual_res, NoResource) def test_putNamedChild_duplicate(self): "check that duplicate resources work" with mock.patch('hendrix.facilities.resources.WSGIResource') as wsgi: request = DummyRequest([b'path', b'to', b'child']) actual_res = getChildForRequest(self.hr, request) self.assertEqual(actual_res, self.res) # Before duplicate duplicate = NamedResource(self.res.namespace) self.hr.putNamedChild(duplicate) request = DummyRequest([b'path', b'to', b'child']) actual_duplicate_res = getChildForRequest(self.hr, request) self.assertEqual(duplicate, actual_duplicate_res) # After duplicate
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,249
hendrix/hendrix
refs/heads/main
/hendrix/deploy/cache.py
from hendrix.contrib.services.cache import CacheService from .base import HendrixDeploy class HendrixDeployCache(HendrixDeploy): """ HendrixDeploy encapsulates the necessary information needed to deploy the HendrixService on a single or multiple processes. """ def addServices(self): super(HendrixDeployCache, self).addServices() if not self.options.get('global_cache') and self.options.get('cache'): self.addLocalCacheService() def getCacheService(self): cache_port = self.options.get('cache_port') http_port = self.options.get('http_port') return CacheService( host='localhost', from_port=cache_port, to_port=http_port, path='' ) def addLocalCacheService(self): "adds a CacheService to the instatiated HendrixService" _cache = self.getCacheService() _cache.setName('cache_proxy') _cache.setServiceParent(self.hendrix) def getSpawnArgs(self): _args = super(HendrixDeployCache, self).getSpawnArgs() _args.append('--cache') if self.options['global_cache']: _args.append('--global_cache') return _args def addGlobalServices(self): """ This is where we put service that we don't want to be duplicated on worker subprocesses """ if self.options.get('global_cache') and self.options.get('cache'): # only add the cache service here if the global_cache and cache # options were set to True _cache = self.getCacheService() _cache.startService()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,250
hendrix/hendrix
refs/heads/main
/hendrix/contrib/resources/static.py
import os from django.conf import settings from django.contrib.staticfiles import finders from hendrix.facilities.resources import DjangoStaticResource def generate_resources_for_location(disk_root, url): for root, dirs, files in os.walk(disk_root): yield DjangoStaticResource( root, url.strip('/') + '%s' % root.split(disk_root)[-1] ) class DjangoStaticsFinder(object): """ finds all static resources for this django installation and creates a static resource for each's base directory """ namespace = settings.STATIC_URL @staticmethod def get_resources(): # add a handler for MEDIA files if configured if settings.MEDIA_ROOT and settings.MEDIA_URL: yield DjangoStaticResource( settings.MEDIA_ROOT, settings.MEDIA_URL ) pipeline_finder = 'pipeline.finders.PipelineFinder' has_pipeline_finder = pipeline_finder in settings.STATICFILES_FINDERS if not settings.DEBUG or has_pipeline_finder: yield DjangoStaticResource( settings.STATIC_ROOT, settings.STATIC_URL ) else: existing = [] for finder in finders.get_finders(): for staticfile, storage in finder.list([]): dirname = os.path.dirname(staticfile) path = os.path.join(storage.base_location, dirname) if path not in existing and dirname: yield DjangoStaticResource( path, settings.STATIC_URL + '%s/' % dirname ) existing.append(path) # The rest is for compatibility with existing code based on the deprecated # classes below. try: DefaultDjangoStaticResource = DjangoStaticResource( settings.STATIC_ROOT, settings.STATIC_URL ) except AttributeError: raise AttributeError( "Please make sure you have assigned your STATIC_ROOT and STATIC_URL" " settings" ) try: from django.contrib import admin admin_media_path = os.path.join(admin.__path__[0], 'static/admin/') DjangoAdminStaticResource = DjangoStaticResource( admin_media_path, settings.STATIC_URL + 'admin/' ) except: raise
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,251
hendrix/hendrix
refs/heads/main
/hendrix/experience/hey_joe.py
import json import uuid from collections import defaultdict from itertools import chain from autobahn.twisted import WebSocketServerFactory from autobahn.twisted.websocket import WebSocketServerProtocol from twisted.internet import threads from twisted.logger import Logger from hendrix.contrib.concurrency.signals import USE_DJANGO_SIGNALS class _ParticipantRegistry(object): """ A basic registry for our PubSub pattern - tracks topics and the participants who wish to receive messages for them. """ log = Logger() def __init__(self): self._participants_by_topic = defaultdict(set) def _send(self, payload, participant): return participant.sendMessage(json.dumps(payload).encode()) def _send_to_multiple_participants(self, payload, participants): # TODO: Optionally do this concurrently? for participant in participants: self._send(payload, participant) def send_to_topic(self, payload, topic): if type(topic) == list: recipients = chain(self._participants_by_topic[rec] for rec in topic) else: recipients = self._participants_by_topic[topic] payload_with_topic = (topic, payload) if not recipients: self.log.info("Nobody is subscribed to {}.".format(topic)) else: return self._send_to_multiple_participants(payload_with_topic, recipients) def send_to_participant(self, payload, participant): payload_for_you = ("YOU", payload) self._send(payload_for_you, participant) def subscribe(self, transport, topic): if topic in ("YOU", "BROADCAST", "SUBSCRIBED", "UNSUBSCRIBED"): raise ValueError( """Can't subscribe to ("YOU", "BROADCAST", "SUBSCRIBED", "UNSUBSCRIBED") - these are reserved names.""") try: # Typically, the protocol is wrapped (as with TLS) participant = transport.wrappedProtocol except AttributeError: participant = transport.protocol # It's also possible to use a naked protocol. self._participants_by_topic[topic].add(participant) return participant def broadcast(self, payload): payload = ("BROADCAST", payload) self._send_to_multiple_participants(payload, self._all_participants()) def _all_participants(self): return chain(*self._participants_by_topic.values()) def remove(self, participant): """ Unsubscribe this participant from all topic to which it is subscribed. """ for topic, participants in list(self._participants_by_topic.items()): self.unsubscribe(participant, topic) # It's possible that we just nixe the last subscriber. if not participants: # IE, nobody is still listening at this topic. del self._participants_by_topic[topic] def unsubscribe(self, participant, topic): return self._participants_by_topic[topic].discard(participant) class _WayDownSouth(WebSocketServerProtocol): guid = None subscription_followups = {} def __init__(self, allow_free_redirect=False, subscription_message=None, registry=None, *args, **kwargs): self.subscription_message = subscription_message or "hx_subscribe" self.allow_free_redirect = allow_free_redirect self._registry = registry or _internal_registry super(_WayDownSouth, self).__init__(*args, **kwargs) def onMessage(self, payload_as_json, isBinary): # Extract json data payload = json.loads(payload_as_json.decode()) # Signal Django if USE_DJANGO_SIGNALS: from ..contrib.concurrency.resources import send_django_signal threads.deferToThread(send_django_signal, None, payload) subscription_topic = payload.get(self.subscription_message) if subscription_topic: try: subscriber = self._registry.subscribe(self.transport, subscription_topic) except ValueError as e: # They tried to subscribe to a reserved word. return else: self.follow_up_subcription(subscription_topic, subscriber) if self.allow_free_redirect: if 'address' in payload: address = payload['address'] else: address = self.guid self._registry.send(address, payload) def onOpen(self): self.guid = str(uuid.uuid1()) def onClose(self, wasClean, code, reason): super(_WayDownSouth, self).onClose(wasClean, code, reason) self._registry.remove(self.transport) def follow_up_subcription(self, topic, participant): try: followup = self.subscription_followups[topic] followup(participant) except KeyError: # Default follow-up - just confirm their subscription. self.sendMessage("Subscribed to {}".format(topic).encode()) class WebSocketService(WebSocketServerFactory): prefix = "ws" def __init__(self, host_address, port, *args, **kwargs): # Note: You can pass a test reactor here a as a kwarg; the parent objects will respect it. self._hey_joe_addr = "{}://{}:{}".format(self.prefix, host_address, port) super(WebSocketService, self).__init__(self._hey_joe_addr, *args, **kwargs) self.protocol = _WayDownSouth self.server = "hendrix/Twisted/" + self.server def register_followup(self, topic, followup): self.protocol.subscription_followups[topic] = followup class WSSWebSocketService(WebSocketService): """ Websocket service that uses the Autobahn TLS behavior to create a WSS service. """ prefix = "wss" def __init__(self, host_address, port, allowedOrigins, *args, **kwargs): super(WSSWebSocketService, self).__init__(host_address, port, *args, **kwargs) self.setProtocolOptions(allowedOrigins=allowedOrigins) # The main singleton instance to use with the subsequent classes here. # (omg, did we just make a stateful HTTP service? Nobody tell IETF.) _internal_registry = _ParticipantRegistry() def send(payload, topic=None, transport=None): if (topic is None and transport is None) or (topic and transport): raise ValueError("You must specify either a topic or a transport; not both.") if topic is not None: return _internal_registry.send_to_topic(payload, topic) elif transport is not None: return _internal_registry.send_to_transport(payload, transport) assert False def broadcast(payload): return _internal_registry.broadcast(payload)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,252
hendrix/hendrix
refs/heads/main
/hendrix/facilities/gather.py
import importlib def get_additional_services(settings_module): """ if HENDRIX_SERVICES is specified in settings_module, it should be a list twisted internet services example: HENDRIX_SERVICES = ( ('myServiceName', 'apps.offload.services.TimeService'), ) """ additional_services = [] if hasattr(settings_module, 'HENDRIX_SERVICES'): for name, module_path in settings_module.HENDRIX_SERVICES: path_to_module, service_name = module_path.rsplit('.', 1) resource_module = importlib.import_module(path_to_module) additional_services.append( (name, getattr(resource_module, service_name)) ) return additional_services def get_additional_resources(settings_module): """ if HENDRIX_CHILD_RESOURCES is specified in settings_module, it should be a list resources subclassed from hendrix.contrib.NamedResource example: HENDRIX_CHILD_RESOURCES = ( 'apps.offload.resources.LongRunningProcessResource', 'apps.chat.resources.ChatResource', ) """ additional_resources = [] if hasattr(settings_module, 'HENDRIX_CHILD_RESOURCES'): for module_path in settings_module.HENDRIX_CHILD_RESOURCES: path_to_module, resource_name = module_path.rsplit('.', 1) resource_module = importlib.import_module(path_to_module) additional_resources.append( getattr(resource_module, resource_name) ) return additional_resources
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,253
hendrix/hendrix
refs/heads/main
/hendrix/contrib/cache/resource.py
try: import cStringIO except ImportError: from io import BytesIO as cStringIO try: import urlparse except ImportError: from urllib.parse import urlparse from twisted.internet import reactor from twisted.web import proxy, client from twisted.web.server import NOT_DONE_YET from hendrix.utils import responseInColor from . import decompressBuffer from .backends.memory_cache import MemoryCacheBackend try: from urllib import quote as urlquote except ImportError: from urllib.parse import quote as urlquote class CacheClient(proxy.ProxyClient): """ SHOW ME THE CACHE BABY! """ def __init__(self, command, rest, version, headers, data, father, resource): proxy.ProxyClient.__init__( self, command, rest, version, headers, data, father ) self.resource = resource self.buffer = cStringIO.StringIO() self._response = None def handleHeader(self, key, value): "extends handleHeader to save headers to a local response object" key_lower = key.lower() if key_lower == 'location': value = self.modLocationPort(value) self._response.headers[key_lower] = value if key_lower != 'cache-control': # This causes us to not pass on the 'cache-control' parameter # to the browser # TODO: we should have a means of giving the user the option to # configure how they want to manage browser-side cache control proxy.ProxyClient.handleHeader(self, key, value) def handleStatus(self, version, code, message): "extends handleStatus to instantiate a local response object" proxy.ProxyClient.handleStatus(self, version, code, message) # client.Response is currently just a container for needed data self._response = client.Response(version, code, message, {}, None) def modLocationPort(self, location): """ Ensures that the location port is a the given port value Used in `handleHeader` """ components = urlparse.urlparse(location) reverse_proxy_port = self.father.getHost().port reverse_proxy_host = self.father.getHost().host # returns an ordered dict of urlparse.ParseResult components _components = components._asdict() _components['netloc'] = '%s:%d' % ( reverse_proxy_host, reverse_proxy_port ) return urlparse.urlunparse(_components.values()) def handleResponseEnd(self): """ Extends handleResponseEnd to not care about the user closing/refreshing their browser before the response is finished. Also calls cacheContent in a thread that we don't care when it finishes. """ try: if not self._finished: reactor.callInThread( self.resource.cacheContent, self.father, self._response, self.buffer ) proxy.ProxyClient.handleResponseEnd(self) except RuntimeError: # because we don't care if the user hits # refresh before the request is done pass def handleResponsePart(self, buffer): """ Sends the content to the browser and keeps a local copy of it. buffer is just a str of the content to be shown, father is the intial request. """ self.father.write(buffer) self.buffer.write(buffer) def compressBuffer(self, buffer): """ Note that this code compresses into a buffer held in memory, rather than a disk file. This is done through the use of cStringIO.StringIO(). """ # http://jython.xhaus.com/http-compression-in-python-and-jython/ zbuf = cStringIO.StringIO() zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=9) zfile.write(buffer) zfile.close() return zbuf.getvalue() class CacheClientFactory(proxy.ProxyClientFactory): protocol = CacheClient def __init__(self, command, rest, version, headers, data, father, resource): self.command = command self.rest = rest self.version = version self.headers = headers self.data = data self.father = father self.resource = resource def buildProtocol(self, addr): return self.protocol( self.command, self.rest, self.version, self.headers, self.data, self.father, self.resource ) class CacheProxyResource(proxy.ReverseProxyResource, MemoryCacheBackend): """ This is a state persistent subclass of the built-in ReverseProxyResource. """ def __init__(self, host, to_port, path, reactor=reactor): """ The 'to_port' arg points to the port of the server that we are sending a request to """ proxy.ReverseProxyResource.__init__( self, host, to_port, path, reactor=reactor ) self.proxyClientFactoryClass = CacheClientFactory def getChild(self, path, request): """ This is necessary because the parent class would call proxy.ReverseProxyResource instead of CacheProxyResource """ return CacheProxyResource( self.host, self.port, self.path + '/' + urlquote(path, safe=""), self.reactor ) def getChildWithDefault(self, path, request): """ Retrieve a static or dynamically generated child resource from me. """ cached_resource = self.getCachedResource(request) if cached_resource: reactor.callInThread( responseInColor, request, '200 OK', cached_resource, 'Cached', 'underscore' ) return cached_resource # original logic if path in self.children: return self.children[path] return self.getChild(path, request) def render(self, request): """ Render a request by forwarding it to the proxied server. """ # set up and evaluate a connection to the target server if self.port == 80: host = self.host else: host = "%s:%d" % (self.host, self.port) request.requestHeaders.addRawHeader('host', host) request.content.seek(0, 0) qs = urlparse.urlparse(request.uri)[4] if qs: rest = self.path + '?' + qs else: rest = self.path global_self = self.getGlobalSelf() clientFactory = self.proxyClientFactoryClass( request.method, rest, request.clientproto, request.getAllHeaders(), request.content.read(), request, global_self # this is new ) self.reactor.connectTCP(self.host, self.port, clientFactory) return NOT_DONE_YET def decompressContent(self): self.content = decompressBuffer(self.content) def getGlobalSelf(self): """ This searches the reactor for the original instance of CacheProxyResource. This is necessary because with each call of getChild a new instance of CacheProxyResource is created. """ transports = self.reactor.getReaders() for transport in transports: try: resource = transport.factory.resource if isinstance(resource, self.__class__) and resource.port == self.port: return resource except AttributeError: pass return
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,254
hendrix/hendrix
refs/heads/main
/hendrix/management/commands/hx.py
from django.core.management.base import BaseCommand from hendrix.options import HX_OPTION_LIST from hendrix.ux import launch class Command(BaseCommand): option_list = HX_OPTION_LIST def handle(self, *args, **options): launch(*args, **options)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,255
hendrix/hendrix
refs/heads/main
/hendrix/contrib/cache/backends/__init__.py
""" Fuck YEAH. enthusiasm. """ try: import urlparse except ImportError: from urllib.parse import urlparse from hendrix.contrib.cache import compressBuffer, decompressBuffer PREFIX = "/CACHE" class CacheBackend(object): "The api to use when creating a cache backend" @property def cache(self): """ `cache` is the interface to be used in the addResource and resourceExists methods. """ raise NotImplementedError( 'You need to override the "cache" method before implementing' 'the cache backend' ) def addResource(self, content, uri, headers): """ Adds the a hendrix.contrib.cache.resource.CachedResource to the ReverseProxy cache connection """ raise NotImplementedError( 'You need to override the "addResource" method before implementing' 'the cache backend' ) def getResource(self, uri): """ Returns a hendrix.contrib.cache.resource.CachedResource from the ReverseProxy cache connection """ raise NotImplementedError( 'You need to override the "addResource" method before implementing' 'the cache backend' ) def resourceExists(self, uri): """ Returns a boolean indicating whether or not the resource is in the cache """ raise NotImplementedError( 'You need to override "resourceExists" to have your backend work..' ) def processURI(self, uri, prefix=''): """ helper function to return just the path (uri) and whether or not it's busted """ components = urlparse.urlparse(uri) query = dict(urlparse.parse_qsl(components.query)) bust = True bust &= bool(query) # bust the cache if the query has stuff in it # bust the cache if the query key 'cache' isn't true bust &= query.get('cache') != 'true' return prefix + components.path, bust def cacheContent(self, request, response, buffer): """ Checks if the response should be cached. Caches the content in a gzipped format given that a `cache_it` flag is True To be used CacheClient """ content = buffer.getvalue() code = int(response.code) cache_it = False uri, bust = self.processURI(request.uri, PREFIX) # Conditions for adding uri response to cache: # * if it was successful i.e. status of in the 200s # * requested using GET # * not busted if request.method == "GET" and code / 100 == 2 and not bust: cache_control = response.headers.get('cache-control') if cache_control: params = dict(urlparse.parse_qsl(cache_control)) if int(params.get('max-age', '0')) > 0: cache_it = True if cache_it: content = compressBuffer(content) self.addResource(content, uri, response.headers) buffer.close() def getCachedResource(self, request): """ """ # start caching logic is_secure = request.isSecure() # the prefix namespaces these resources uri, bust = self.processURI(request.uri, PREFIX) # Reasons not to bother looking in the Cache # * it's been busted # * it's a secure request # * it's not a GET request # * it's not actually in the cache if not is_secure and request.method == "GET" and not bust: if self.resourceExists(uri): child = self.getResource(uri) is_fresh = child.isFresh() if is_fresh: encodings = request.getHeader('accept-encoding') if encodings and 'gzip' in encodings: request.responseHeaders.addRawHeader( 'content-encoding', 'gzip' ) request.responseHeaders.addRawHeader( 'content-length', len(child.content) ) else: child = decompressBuffer(child.content) return child return None
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,256
hendrix/hendrix
refs/heads/main
/test/test_testing_utils.py
import pytest from hendrix.experience import crosstown_traffic from hendrix.utils.test_utils import AsyncTestMixin, crosstownTaskListDecoratorFactory def test_assert_num_tasks(): a_mixin = AsyncTestMixin() a_mixin.sub_setUp() a_mixin.assertNumCrosstownTasks(0) def some_task(): pass through_to_you = crosstown_traffic() through_to_you(some_task) a_mixin.assertNumCrosstownTasks(1) def test_next_task(): a_mixin = AsyncTestMixin() a_mixin.sub_setUp() a_mixin.assertNumCrosstownTasks(0) def some_task(): pass through_to_you = crosstown_traffic() through_to_you(some_task) assert some_task is a_mixin.next_task() def test_no_more_tasks(): a_mixin = AsyncTestMixin() a_mixin.sub_setUp() a_mixin.assertNumCrosstownTasks(0) def some_task(): pass through_to_you = crosstown_traffic() through_to_you(some_task) same_task = a_mixin.next_task() # That will be the only (and thus last) task. with pytest.raises(StopIteration): a_mixin.next_task() def test_record_task_to_list(): task_list = [] crosstown_traffic.decorator = crosstownTaskListDecoratorFactory(task_list) assert len(task_list) == 0 @crosstown_traffic() def add_to_task_list(): pass assert len(task_list) == 1
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,257
hendrix/hendrix
refs/heads/main
/hendrix/facilities/protocols.py
import sys if sys.platform == 'win32': from twisted.internet.iocpreactor.tcp import Server else: from twisted.internet.unix import Server class DeployServerProtocol(Server): """ A process protocol for interprocess communication between HendrixDeploy and its workers. """ def __init__(self, args): self.args = args def connectionMade(self): self.transport.write(self.args) self.transport.closeStdin()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,258
hendrix/hendrix
refs/heads/main
/hendrix/mechanics/concurrency/decorators.py
import threading from twisted.internet import reactor from twisted.internet.threads import deferToThreadPool from twisted.logger import Logger from hendrix.mechanics.concurrency import get_response_for_thread from hendrix.mechanics.concurrency.exceptions import ThreadHasNoResponse class _ThroughToYou(object): log = Logger() def __init__(self, threadpool=None, reactor=reactor, same_thread=False, no_go_status_codes=['5xx', '4xx'], fail_without_response=False, block_without_response=True, always_spawn_worker=False, ): self.threadpool = threadpool self.reactor = reactor self.same_thread = same_thread self.no_go_status_codes = no_go_status_codes or ['5xx', '4xx'] self.fail_without_response = fail_without_response self.block_without_response = block_without_response self.always_spawn_worker = always_spawn_worker self.no_go = False self.status_code = None self.crosstown_task = None def __call__(self, crosstown_task=None): self.crosstown_task = crosstown_task try: self.response = get_response_for_thread() self.log.info("Adding '%s' to crosstown_traffic for %s" % (str(crosstown_task), self.response)) if not self.no_go: self.response.crosstown_tasks.append(self) except ThreadHasNoResponse: self.responseless_fallback(crosstown_task) return self.run def responseless_fallback(self, crosstown_task=None): self.crosstown_task = crosstown_task or self.crosstown_task if self.fail_without_response: raise ThreadHasNoResponse( "This crosstown decorator cannot proceed without a response. To run the crosstown_task at this time, set fail_without_response = False.") else: self.log.info( "thread %s has no response; running crosstown task now. To supress this behavior, set fail_without_response == True." % threading.current_thread()) # Since we have no response, we now want to run on the same thread if block_without_response is True. self.same_thread = self.block_without_response self.run() def run(self, threadpool=None): if self.no_go: return if self.same_thread: self.crosstown_task() else: if not threadpool: threadpool = self.threadpool or reactor.getThreadPool() if self.always_spawn_worker: threadpool.startAWorker() deferToThreadPool(reactor, threadpool, self.crosstown_task) # if self.always_spawn_worker: # threadpool.stopAWorker() def populate_no_go_status_code_list(self): self.no_go_status_code_list = [] for no_go_code in self.no_go_status_codes: if type(no_go_code) == str: if "xx" in no_go_code: class_number = int(no_go_code[0]) begin = class_number * 100 end = begin + 100 elif '-' in no_go_code: begin, end = no_go_code.split('-') else: self.no_go_status_code_list.extend(int(no_go_code)) continue self.no_go_status_code_list.extend(range(begin, end)) else: self.no_go_status_code_list.append(no_go_code) self.log.debug("no_go_status_codes are %s" % self.no_go_status_code_list) def check_status_code_against_no_go_list(self): if self.no_go_status_codes: if not self.status_code: self.status_code = int(self.response.status.split(None, 1)[0]) self.populate_no_go_status_code_list() if self.status_code in self.no_go_status_code_list: self.log.info("Flagging no-go becasue status code is %s" % self.status_code) self.no_go = True
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,259
hendrix/hendrix
refs/heads/main
/examples/django_nyc_demo/run.py
from twisted.conch.telnet import TelnetTransport, TelnetProtocol from twisted.internet.protocol import ServerFactory from hendrix.deploy.base import HendrixDeploy from hendrix.experience import hey_joe class TelnetToWebsocket(TelnetProtocol): def dataReceived(self, data): hey_joe.send('noodly_messages', data) deployer = HendrixDeploy(options={'wsgi': 'hendrix_demo.wsgi.application', 'http_port': 7575}) websocket_service = hey_joe.WebSocketService("127.0.0.1", 9000) deployer.add_non_tls_websocket_service(websocket_service) telnet_server_factory = ServerFactory() telnet_server_factory.protocol = lambda: TelnetTransport(TelnetToWebsocket) deployer.reactor.listenTCP(6565, telnet_server_factory) deployer.run()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,260
hendrix/hendrix
refs/heads/main
/hendrix/facilities/response.py
import threading from twisted.internet import reactor from twisted.logger import Logger from twisted.web.wsgi import _WSGIResponse from hendrix.utils import responseInColor class HendrixWSGIResponse(_WSGIResponse): log = Logger() def __init__(self, *args, **kwargs): self.crosstown_tasks = [] return super(HendrixWSGIResponse, self).__init__(*args, **kwargs) def run(self, *args, **kwargs): r = reactor self.thread = threading.current_thread() # thread_list.append(self.thread) # Debug # logger.debug("Assigning %s as the current response for thread %s" % (self, self.thread)) self.thread.response_object = self self.request.setHeader('server', 'hendrix/Twisted') ran = super(HendrixWSGIResponse, self).run(*args, **kwargs) self.follow_response_tasks() del self.thread.response_object return ran def follow_response_tasks(self): for task in self.crosstown_tasks: self.log.info("Processing crosstown task: '%s'" % task.crosstown_task) # Set no-go if status code is bad. task.check_status_code_against_no_go_list() task.run() class LoudWSGIResponse(HendrixWSGIResponse): def startResponse(self, status, headers, excInfo=None): """ extends startResponse to call speakerBox in a thread """ self.status = status self.headers = headers self.reactor.callInThread( responseInColor, self.request, status, headers ) return self.write
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,261
hendrix/hendrix
refs/heads/main
/hendrix/contrib/services/cache.py
from twisted.web import server from hendrix.contrib.cache.resource import CacheProxyResource from hendrix.facilities.services import HendrixTCPService class CacheService(HendrixTCPService): def __init__(self, host, from_port, to_port, path, *args, **kwargs): resource = CacheProxyResource(host, to_port, path) factory = server.Site(resource) HendrixTCPService.__init__(self, from_port, factory)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,262
hendrix/hendrix
refs/heads/main
/test/testproject/settings.py
DEBUG = True TEMPLATE_DEBUG = DEBUG DATABASES = { 'default': { 'ENGINE': 'django.db.backends.', 'NAME': '', 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', } } ALLOWED_HOSTS = [] TIME_ZONE = 'America/Chicago' LANGUAGE_CODE = 'en-us' USE_I18N = True USE_L10N = True USE_TZ = True STATIC_URL = '/static/' SECRET_KEY = 'NOTREALt@k0)scq$uuph3gjpbhjhd%ipe)04f5d^^1%)%my(%b6&pus_2NOTREAL' MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ) ROOT_URLCONF = 'urls' WSGI_APPLICATION = 'test.wsgi.application' INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', )
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,263
hendrix/hendrix
refs/heads/main
/test/test_hx_launcher.py
from hendrix.options import HendrixOptionParser from hendrix.ux import main def test_no_arguments_gives_help_text(mocker): class MockFile(object): @classmethod def write(cls, whatever): cls.things_written = whatever class MockStdOut(object): @classmethod def write(cls, whatever): HendrixOptionParser.print_help(MockFile) assert MockFile.things_written == whatever mocker.patch('sys.stdout', new=MockStdOut) main([])
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,264
hendrix/hendrix
refs/heads/main
/hendrix/contrib/cache/__init__.py
try: import cStringIO except ImportError: from io import BytesIO as cStringIO import gzip from datetime import datetime try: import urlparse except ImportError: from urllib.parse import urlparse from time import strptime from twisted.web.resource import Resource def compressBuffer(buffer): """ Note that this code compresses into a buffer held in memory, rather than a disk file. This is done through the use of cStringIO.StringIO(). """ # http://jython.xhaus.com/http-compression-in-python-and-jython/ zbuf = cStringIO.StringIO() zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=9) zfile.write(buffer) zfile.close() return zbuf.getvalue() def decompressBuffer(buffer): "complements the compressBuffer function in CacheClient" zbuf = cStringIO.StringIO(buffer) zfile = gzip.GzipFile(fileobj=zbuf) deflated = zfile.read() zfile.close() return deflated class CachedResource(Resource): isLeaf = True def __init__(self, content=None, headers=None): Resource.__init__(self) self.content = content self.headers = headers self.created = datetime.now() def render(self, request): return self.content def getMaxAge(self): "get the max-age in seconds from the saved headers data" max_age = 0 cache_control = self.headers.get('cache-control') if cache_control: params = dict(urlparse.parse_qsl(cache_control)) max_age = int(params.get('max-age', '0')) return max_age def convertTimeString(self, timestr): """ Returns a datetime instance from a str formatted as follows e.g. 'Mon, 03 Mar 2014 12:12:12 GMT' """ time_struc = strptime(timestr, '%a, %d %b %Y %H:%M:%S GMT') return datetime(*time_struc[:6]) def getLastModified(self): "returns the GMT last-modified datetime or None" last_modified = self.headers.get('last-modified') if last_modified: last_modified = self.convertTimeString(last_modified) return last_modified def getDate(self): "returns the GMT response datetime or None" date = self.headers.get('date') if date: date = self.convertTimeString(date) return date def isFresh(self): "returns True if cached object is still fresh" max_age = self.getMaxAge() date = self.getDate() is_fresh = False if max_age and date: delta_time = datetime.now() - date is_fresh = delta_time.total_seconds() < max_age return is_fresh
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,265
hendrix/hendrix
refs/heads/main
/hendrix/mechanics/concurrency/exceptions.py
class ThreadHasNoResponse(RuntimeError): pass class RedisException(AttributeError): """ Raised if a user tries to use redis-only features without redis available. """
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,266
hendrix/hendrix
refs/heads/main
/test/test_crosstown_traffic.py
import threading import pytest import pytest_twisted from six.moves.queue import Queue from twisted.internet import reactor from twisted.internet.address import IPv4Address from twisted.internet.threads import deferToThreadPool from twisted.logger import Logger from twisted.python.threadpool import ThreadPool from twisted.trial.unittest import TestCase from twisted.web.test.requesthelper import DummyRequest from hendrix.experience import crosstown_traffic from hendrix.facilities.resources import HendrixWSGIResource from hendrix.mechanics.concurrency.exceptions import ThreadHasNoResponse from test.resources import TestNameSpace, application as wsgi_application, \ nameSpace log = Logger() # Using module-scoped list to keep track of pass flags. When we drop support for Python 2, we can use nonlocal instead. pass_flags = [] class NoGoStatusCodes(TestCase): def __init__(self, *args, **kwargs): self.tp = ThreadPool(maxthreads=20) self.tp.start() self.resource = HendrixWSGIResource(reactor, self.tp, self.wsgi_thing) self.nameSpace = TestNameSpace() self.nameSpace.async_thing_complete = Queue() return super(NoGoStatusCodes, self).__init__(*args, **kwargs) def setUp(self, *args, **kwargs): self.addCleanup(self.tp.stop) super(NoGoStatusCodes, self).setUp(*args, **kwargs) def wsgi_thing(self, environ, start_response): start_response('404 NOT FOUND', [('Content-type', 'text/plain')]) @crosstown_traffic( no_go_status_codes=self.no_go_status_codes, same_thread=True ) def long_thing_on_same_thread(): self.nameSpace.async_task_was_run = True log.debug("No bad status codes; went ahead with async thing.") return [b"Nothing."] def test_bad_status_codes_cause_no_go_in_wsgi_response(self): self.no_go_status_codes = [404, '6xx'] request = DummyRequest([b'r1']) request.isSecure = lambda: False request.content = "llamas" request.client = IPv4Address("TCP", b"50.0.50.0", 5000) finished = request.notifyFinish() self.resource.render(request) # This must wait until the WSGI response is closed. finished.addCallback( lambda _: self.assertFalse( self.nameSpace.async_task_was_run ) ) return finished def test_bad_status_codes_cause_no_go_flag(self): through_to_you = crosstown_traffic( no_go_status_codes=[418] ) through_to_you.status_code = 418 through_to_you.check_status_code_against_no_go_list() self.assertTrue(through_to_you.no_go) def test_no_bad_status_codes_are_cool(self): through_to_you = crosstown_traffic( no_go_status_codes=[418] ) through_to_you.status_code = 404 through_to_you.check_status_code_against_no_go_list() self.assertFalse(through_to_you.no_go) class SameOrDifferentThread(TestCase): def setUp(self, *args, **kwargs): self.tp = ThreadPool() self.tp.start() self.addCleanup(self.tp.stop) super(SameOrDifferentThread, self).setUp(*args, **kwargs) def wsgi_thing(self, environ, start_response): start_response('200 OK', [('Content-type', 'text/plain')]) nameSpace.this_thread = threading.current_thread() @crosstown_traffic( same_thread=self.use_same_thread ) def long_thing_on_same_thread(): nameSpace.thread_that_is_supposed_to_be_the_same = threading.current_thread() log.debug("Finished async thing on same thread.") return [b"Nothing."] def assert_that_threads_are_the_same(self): self.assertEqual( nameSpace.this_thread, nameSpace.thread_that_is_supposed_to_be_the_same ) def assert_that_threads_are_different(self): self.assertNotEqual(nameSpace.this_thread, nameSpace.thread_that_is_supposed_to_be_different) def request_same_or_different_thread_thread(self): hr = HendrixWSGIResource(reactor, self.tp, self.wsgi_thing) request1 = DummyRequest([b'r1']) request1.isSecure = lambda: False request1.content = b"llamas" request1.client = IPv4Address("TCP", b"50.0.50.0", 5000) d = deferToThreadPool(reactor, self.tp, hr.render, request1) d.addCallback(lambda _: request1.notifyFinish()) return d @pytest_twisted.inlineCallbacks def test_that_threads_are_the_same(self): self.use_same_thread = True d = self.request_same_or_different_thread_thread() d.addCallback(lambda _: self.assert_that_threads_are_the_same) yield d @pytest_twisted.inlineCallbacks def test_that_threads_are_different(self): self.use_same_thread = False d = self.request_same_or_different_thread_thread() d.addCallback(lambda _: self.assert_that_threads_are_different) yield d @pytest.fixture def async_namespace(): nameSpace = TestNameSpace() yield try: del threading.current_thread().response_object except AttributeError: pass @pytest.mark.usefixtures("async_namespace") def test_typical_same_thread_operation(): success_string = "With a Response affixed to this thread, the task will run if the status code is not a 'no-go'." def run_me_to_pass(): pass_flags.append(success_string) class FakeResponse(object): crosstown_tasks = [] status = "200 OK" through_to_you = crosstown_traffic(same_thread=True) threading.current_thread().response_object = FakeResponse() through_to_you(run_me_to_pass) # threadpool doesn't matter because same_thread is True. # The function hasn't run yet. assert success_string not in pass_flags through_to_you.run(reactor.threadpool) assert not through_to_you.no_go # Since the no_go is False... assert success_string in pass_flags # Then run_me_to_pass will have run. @pytest.mark.usefixtures("async_namespace") def test_no_go_causes_task_not_to_fire(): some_task = lambda: None class FakeResponse(object): crosstown_tasks = [] status = "418 I'm a teapot. Seriously." threading.current_thread().response_object = FakeResponse() through_to_you = crosstown_traffic(same_thread=True) through_to_you.no_go = True # If no_go is True... through_to_you(some_task) # and we call it... assert not through_to_you.response.crosstown_tasks # We won't have added any tasks. through_to_you.no_go = False # However if no_go is False... through_to_you(some_task) # and we call it... # We will have added the function. assert through_to_you.response.crosstown_tasks[0].crosstown_task == some_task @pytest.mark.usefixtures("async_namespace") def test_with_no_request(): success_string = "Without a request in progress, the default behavior for crosstown_traffic is to run the task immediately." def append_me_to_pass(): pass_flags.append(success_string) through_to_you = crosstown_traffic(same_thread=True) assert success_string not in pass_flags through_to_you(append_me_to_pass) assert success_string in pass_flags @pytest.mark.usefixtures("async_namespace") def test_fail_without_response(): ''' Same test as above, but with fail_without_response, we get an error. ''' some_task = lambda: None through_to_you = crosstown_traffic(same_thread=True, fail_without_response=True) with pytest.raises(ThreadHasNoResponse): through_to_you(some_task) @pytest.mark.usefixtures("async_namespace") @pytest_twisted.inlineCallbacks def test_contemporaneous_requests(): ''' We're going to create two request-response cycles here: Cycle 1 will begin. Cycle 2 will begin. Cycle 2 will return. Cycle 1 will return. This way, we can prove that the crosstown_traffic created by cycle 1 is not resolved by the return of cycle 2. ''' tp = ThreadPool(maxthreads=20) tp.start() log.debug("\n\nStarting the two stream stuff.") request1 = DummyRequest([b'r1']) request1.isSecure = lambda: False request1.content = "Nothing really here." request1.requestHeaders.addRawHeader('llamas', 'dingo') request1.client = IPv4Address("TCP", b"50.0.50.0", 5000) hr = HendrixWSGIResource(reactor, tp, wsgi_application) yield deferToThreadPool(reactor, tp, hr.render, request1) request2 = DummyRequest([b'r2']) request2.isSecure = lambda: False request2.content = b"Nothing really here." request2.requestHeaders.addRawHeader('llamas', 'dingo') request2.client = IPv4Address("TCP", b"100.0.50.0", 5000) yield deferToThreadPool(reactor, tp, hr.render, request2) # def woah_stop(failure): # nameSpace.async_task_was_done.put_nowait(False) # nameSpace.second_cycle_complete.put_nowait(False) # nameSpace.ready_to_proceed_with_second_cycle.put_nowait(False) # # d1.addErrback(woah_stop) # d2.addErrback(woah_stop) # combo_deferred = gatherResults([d1, d2]) # yield d1 # yield d2 # combo_deferred = DeferredList([d1, d2]) def wait_for_queue_resolution(): nameSpace.async_task_was_done.get(True, 3) # combo_deferred.addCallback( # lambda _: # ) # yield deferToThreadPool(reactor, tp, wait_for_queue_resolution) # combo_deferred.addCallback( # lambda _: # ) assert nameSpace.async_task_was_run tp.stop() # return pytest_twisted.blockon(combo_deferred)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,267
hendrix/hendrix
refs/heads/main
/examples/tls_server/gen-ec.py
import datetime from cryptography import x509 from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import ec from cryptography.x509.oid import NameOID ec_key = ec.generate_private_key(ec.SECP256K1, default_backend()) subject = issuer = x509.Name([ x509.NameAttribute(NameOID.COMMON_NAME, u"hendrix-tls-example"), ]) cert = x509.CertificateBuilder().subject_name( subject ).issuer_name( issuer ).public_key( ec_key.public_key() ).serial_number( x509.random_serial_number() ).not_valid_before( datetime.datetime.utcnow() ).not_valid_after( datetime.datetime.utcnow() + datetime.timedelta(days=10) ).add_extension( x509.SubjectAlternativeName([x509.DNSName(u"localhost")]), critical=False, ).sign(ec_key, hashes.SHA256(), default_backend()) with open("ec-key.pem", "wb") as f: f.write(ec_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, encryption_algorithm=serialization.NoEncryption(), )) with open("ec-certificate.pem", "wb") as f: f.write(cert.public_bytes(serialization.Encoding.PEM))
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,268
hendrix/hendrix
refs/heads/main
/test/test_deploy.py
from .utils import HendrixTestCase try: from unittest.mock import patch except ImportError: from mock import patch from twisted.application import service from twisted.internet import tcp from twisted.logger import Logger log = Logger() class DeployTests(HendrixTestCase): "Tests HendrixDeploy" def test_settings_doesnt_break(self): """ A placeholder test to ensure that instantiating HendrixDeploy through the hx bash script or the manage.py path wont raise any errors """ self.settingsDeploy() def test_workers(self): "test the expected behaviour of workers and associated functions" num_workers = 2 deploy = self.settingsDeploy('start', {'workers': num_workers}) with patch.object(deploy.reactor, 'spawnProcess') as _spawnProcess: deploy.addServices() deploy.start() self.assertEqual(_spawnProcess.call_count, num_workers) def test_no_workers(self): deploy = self.settingsDeploy() with patch.object(deploy.reactor, 'spawnProcess') as _spawnProcess: deploy.addServices() deploy.start() self.assertEqual(_spawnProcess.call_count, 0) def test_addHendrix(self): "test that addHendrix returns a MulitService" deploy = self.settingsDeploy() deploy.addHendrix() self.assertIsInstance(deploy.hendrix, service.MultiService) def test_flask_deployment(self): deploy = self.wsgiDeploy(options={'wsgi': 'test.flasky.app'}) deploy.addServices() deploy.start() readers = deploy.reactor.getReaders() tcp_readers = [p for p in readers if isinstance(p, tcp.Port)] ports = [p.port for p in tcp_readers] self.assertTrue(8000 in ports)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,269
hendrix/hendrix
refs/heads/main
/hendrix/contrib/concurrency/resources.py
import json import uuid from twisted.internet import threads from twisted.internet.protocol import Protocol from hendrix.facilities.resources import NamedResource from .messaging import hxdispatcher def send_django_signal(transport, data): from .signals import message_signal message_signal.send(None, dispatcher=transport, data=data) class MessageHandlerProtocol(Protocol): """ A basic protocol for socket messaging using a hendrix messaging dispatcher to handle addressing messages to active sockets from different contexts """ dispatcher = hxdispatcher guid = None def dataReceived(self, data): """ Takes "data" which we assume is json encoded If data has a subject_id attribute, we pass that to the dispatcher as the subject_id so it will get carried through into any return communications and be identifiable to the client falls back to just passing the message along... """ try: address = self.guid data = json.loads(data) threads.deferToThread(send_signal, self.dispatcher, data) if 'hx_subscribe' in data: return self.dispatcher.subscribe(self.transport, data) if 'address' in data: address = data['address'] else: address = self.guid self.dispatcher.send(address, data) except Exception as e: raise self.dispatcher.send( self.guid, {'message': data, 'error': str(e)} ) def connectionMade(self): """ establish the address of this new connection and add it to the list of sockets managed by the dispatcher reply to the transport with a "setup_connection" notice containing the recipient's address for use by the client as a return address for future communications """ self.transport.uid = str(uuid.uuid1()) self.guid = self.dispatcher.add(self.transport) self.dispatcher.send(self.guid, {'setup_connection': self.guid}) def connectionLost(self, something): "clean up the no longer useful socket in the dispatcher" self.dispatcher.remove(self.transport) MessageResource = NamedResource('messages')
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,270
hendrix/hendrix
refs/heads/main
/examples/django_nyc_demo/noodles/views.py
import time from django.shortcuts import render from hendrix.experience import crosstown_traffic, hey_joe def my_noodles(request): llama = "Another noodle" @crosstown_traffic() def my_long_thing(): for i in range(5): print("another noodle on the python console") time.sleep(1) hey_joe.send(llama, topic="noodly_messages") hey_joe.broadcast("Notice to everybody: finished noodling.") if request.META.get("wsgi.url_scheme") == "https": websocket_prefix = "wss" websocket_port = 9443 else: websocket_prefix = "ws" websocket_port = 9000 return render(request, 'noodles.html', {"websocket_prefix": websocket_prefix, "websocket_port": websocket_port})
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,271
hendrix/hendrix
refs/heads/main
/examples/django_hx_chatserver/example_app/run.py
from hendrix.deploy.base import HendrixDeploy from hendrix.experience import hey_joe deployer = HendrixDeploy(options={'wsgi': 'example_app.wsgi.application', 'http_port': 7575}) websocket_service = hey_joe.WebSocketService("127.0.0.1", 9000) deployer.add_non_tls_websocket_service(websocket_service) deployer.run()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,272
hendrix/hendrix
refs/heads/main
/hendrix/deploy/hybrid.py
from .cache import HendrixDeployCache from .tls import HendrixDeployTLS class HendrixDeployHybrid(HendrixDeployTLS, HendrixDeployCache): pass
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,273
hendrix/hendrix
refs/heads/main
/performance-tools/simple_multi.py
import multiprocessing def thing(): print "yay!" multiprocessing.Process(target=thing).start()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,274
hendrix/hendrix
refs/heads/main
/examples/django_hx_chatserver/example_app/example_app/urls.py
from chat.views import home from django.conf import settings from django.conf.urls import url from django.conf.urls.static import static from django.contrib import admin urlpatterns = [ url(r'^(?P<chat_channel_name>\w+)$', home, name='home'), url(r'^$', home, name='home'), url(r'^admin/', admin.site.urls), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,275
hendrix/hendrix
refs/heads/main
/hendrix/contrib/cache/backends/memory_cache.py
""" local memory cache backend """ from hendrix.contrib.cache import CachedResource from . import CacheBackend class MemoryCacheBackend(CacheBackend): _cache = {} @property def cache(self): return self._cache def addResource(self, content, uri, headers): """ Adds the a hendrix.contrib.cache.resource.CachedResource to the ReverseProxy cache connection """ self.cache[uri] = CachedResource(content, headers) def resourceExists(self, uri): """ Returns a boolean indicating whether or not the resource is in the cache """ return uri in self.cache def getResource(self, uri): return self.cache[uri]
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,276
hendrix/hendrix
refs/heads/main
/performance-tools/perf_client1.py
import requests counter = 0 for counter in range(5000): r = requests.get('http://localhost:8000/fib/%s' % counter) print "%s - %s" % (counter, r)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,277
hendrix/hendrix
refs/heads/main
/hendrix/facilities/resources.py
import sys import chalk from twisted.logger import Logger from twisted.web import resource, static from twisted.web.server import NOT_DONE_YET from twisted.web.wsgi import WSGIResource from hendrix.facilities.response import HendrixWSGIResponse, LoudWSGIResponse class HendrixWSGIResource(WSGIResource): ResponseClass = HendrixWSGIResponse def render(self, request): response = self.ResponseClass( self._reactor, self._threadpool, self._application, request) response.start() return NOT_DONE_YET class DevWSGIResource(HendrixWSGIResource): ResponseClass = LoudWSGIResponse class HendrixResource(resource.Resource): """ HendrixResource initialises a WSGIResource and stores it as wsgi_resource. It also overrides its own getChild method so to only serve wsgi_resource. This means that only the WSGIResource is able to serve dynamic content from the root url "/". However it is still possible to extend the resource tree via putChild. This is due the fact that getChildFromRequest checks for children of the resource before handling the dynamic content (through getChild). The modified getChild resource on HendrixResource also restores the request.postpath list to its original state. This is essentially a hack to ensure that django always gets the full path. """ logger = Logger() def __init__(self, reactor, threads, application, loud=False): resource.Resource.__init__(self) if loud: self.wsgi_resource = DevWSGIResource(reactor, threads, application) else: self.wsgi_resource = HendrixWSGIResource(reactor, threads, application) def getChild(self, name, request): """ Postpath needs to contain all segments of the url, if it is incomplete then that incomplete url will be passed on to the child resource (in this case our wsgi application). """ path = name if isinstance(path, bytes): path = path.decode('utf-8') if path in self.children: return self.children[path] request.prepath = [] request.postpath.insert(0, name) # re-establishes request.postpath so to contain the entire path return self.wsgi_resource def putNamedChild(self, res): """ putNamedChild takes either an instance of hendrix.contrib.NamedResource or any resource.Resource with a "namespace" attribute as a means of allowing application level control of resource namespacing. if a child is already found at an existing path, resources with paths that are children of those physical paths will be added as children of those resources """ try: EmptyResource = resource.Resource namespace = res.namespace parts = namespace.strip(b'/').split(b'/') # initialise parent and children parent = self children = self.children # loop through all of the path parts except for the last one for name in parts[:-1]: child = children.get(name) if not child: # if the child does not exist then create an empty one # and associate it to the parent child = EmptyResource() parent.putChild(name, child) # update parent and children for the next iteration parent = child children = parent.children name = parts[-1] # get the path part that we care about if children.get(name): self.logger.warn( 'A resource already exists at this path. Check ' 'your resources list to ensure each path is ' 'unique. The previous resource will be overridden.' ) parent.putChild(name, res) except AttributeError: # raise an attribute error if the resource `res` doesn't contain # the attribute `namespace` msg = ( '%r improperly configured. additional_resources instances must' ' have a namespace attribute' ) % resource raise AttributeError(msg, None, sys.exc_info()[2]) class NamedResource(resource.Resource): """ A resource that can be used to namespace other resources. Expected usage of this resource in a django application is: ... in myproject.myapp.somemodule ... NamespacedRes = NamedResource('some-namespace') NamespacedRes.putChild('namex', SockJSResource(FactoryX...)) NamespacedRes.putChild('namey', SockJSResource(FactoryY...)) ... then in settings ... HENDRIX_CHILD_RESOURCES = ( 'myproject.myapp.somemodule.NamespacedRes', ..., ) """ def __init__(self, namespace): resource.Resource.__init__(self) self.namespace = namespace def getChild(self, path, request): """ By default this resource will yield a ForbiddenResource instance unless a request is made for a static child i.e. a child added using putChild """ # override this method if you want to serve dynamic child resources return resource.ForbiddenResource("This is a resource namespace.") class MediaResource(static.File): ''' A simple static service with directory listing disabled (gives the client a 403 instead of letting them browse a static directory). ''' def __init__(self, *args, namespace=None, **kwargs): self.namespace = namespace super().__init__(*args, **kwargs) def directoryListing(self): # Override to forbid directory listing return resource.ForbiddenResource() def DjangoStaticResource(path, rel_url='static'): """ takes an app level file dir to find the site root and servers static files from static Usage: [...in app.resource...] from hendrix.resources import DjangoStaticResource StaticResource = DjangoStaticResource('/abspath/to/static/folder') ... OR ... StaticResource = DjangoStaticResource( '/abspath/to/static/folder', 'custom-static-relative-url' ) [...in settings...] HENDRIX_CHILD_RESOURCES = ( ..., 'app.resource.StaticResource', ... ) """ rel_url = rel_url.strip('/') StaticFilesResource = MediaResource(path) StaticFilesResource.namespace = rel_url chalk.green( "Adding media resource for URL '%s' at path '%s'" % (rel_url, path) ) return StaticFilesResource
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,278
hendrix/hendrix
refs/heads/main
/setup.py
import errno import os import sys from setuptools import setup, find_packages from setuptools.command.install import install from hendrix import __version__ def file_name(rel_path): dir_path = os.path.dirname(__file__) return os.path.join(dir_path, rel_path) def read(rel_path): with open(file_name(rel_path)) as f: return f.read() def mkdir_p(path): "recreate mkdir -p functionality" try: os.makedirs(path) except OSError as exc: # Python >2.5 if exc.errno == errno.EEXIST and os.path.isdir(path): pass else: raise share_path = os.path.join( os.path.dirname(sys.executable), 'share/hendrix' ) mkdir_p(share_path) INSTALL_REQUIRES = [ 'twisted', 'cryptography>=2.3', 'watchdog', 'jinja2', 'pychalk', 'service-identity', 'six', 'autobahn' ] EXTRAS = { 'tests': [ 'pytest', 'pytest-cov', 'pytest-mock', 'pytest-twisted', 'django', 'flask', 'urllib3', 'requests', 'coverage' 'codecov', 'gunicorn' ] } class VerifyVersionCommand(install): """Custom command to verify that the git tag matches our version""" description = 'verify that the git tag matches our version' def run(self): tag = os.getenv('CIRCLE_TAG') if tag.startswith('v'): tag = tag[1:] version = __version__ if version.startswith('v'): version = version[1:] if tag != version: info = "Git tag: {0} does not match the version of this app: {1}".format( os.getenv('CIRCLE_TAG'), __version__ ) sys.exit(info) setup( name="hendrix", version=__version__, description="Pure python web server, based on Twisted, providing the One Obvious Way to do async and offbeat network traffic with django and other WSGI apps.", author="hendrix", author_email="justin@justinholmes.com", packages=find_packages(), url="https://github.com/hendrix/hendrix", download_url=( "https://github.com/hendrix/hendrix/tarball/" "v" + __version__ ), long_description=read('README.md'), long_description_content_type='text/markdown', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Framework :: Django', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: POSIX', 'Programming Language :: Python', 'Topic :: Internet', 'Topic :: Utilities', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: WSGI', 'Topic :: Internet :: WWW/HTTP :: WSGI :: Server', ], keywords=["django", "twisted", "async", "logging", "wsgi"], scripts=[ 'hendrix/utils/scripts/hx', 'hendrix/utils/scripts/hxw', 'hendrix/utils/scripts/install-hendrix-service' ], data_files=[ (share_path, ['hendrix/utils/templates/init.d.j2', ]), ], install_requires=INSTALL_REQUIRES, extras_require=EXTRAS, cmdclass={'verify': VerifyVersionCommand} )
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,279
hendrix/hendrix
refs/heads/main
/test/test_ux.py
import os import sys from hendrix import ux from hendrix.contrib import SettingsError from hendrix.deploy.base import HendrixDeploy from hendrix.options import options as hx_options from .utils import HendrixTestCase try: from unittest.mock import patch except ImportError: from mock import patch class TestMain(HendrixTestCase): def setUp(self): super(TestMain, self).setUp() self.DEFAULTS = hx_options() os.environ['DJANGO_SETTINGS_MODULE'] = '' self.devnull = open(os.devnull, 'w') self.args_list = ['hx', 'start'] self.patcher = patch('hendrix.ux.findSettingsModule') self.patcher.start() def tearDown(self): super(TestMain, self).tearDown() self.devnull.close() self.patcher.stop() def test_settings_from_system_variable(self): django_settings = 'django.inanity' with patch('hendrix.ux.findSettingsModule') as findSettingsMod: findSettingsMod.return_value = django_settings options = self.DEFAULTS self.assertEqual(options['settings'], '') options = ux.djangoVsWsgi(options) self.assertEqual(options['settings'], django_settings) def test_settings_wsgi_absense(self): with patch('hendrix.ux.findSettingsModule') as findSettingsMod: findSettingsMod.return_value = "" self.assertRaises(SettingsError, ux.djangoVsWsgi, self.DEFAULTS) def test_user_settings_overrides_system_variable(self): django_settings = 'django.inanity' with patch('hendrix.ux.findSettingsModule') as findSettingsMod: findSettingsMod.return_value = django_settings options = self.DEFAULTS user_settings = 'myproject.settings' options['settings'] = user_settings self.assertEqual(options['settings'], user_settings) options = ux.djangoVsWsgi(options) self.assertEqual(options['settings'], user_settings) def test_wsgi_correct_wsgi_path_works(self): wsgi_dot_path = 'test.wsgi' options = self.DEFAULTS options.update({'wsgi': wsgi_dot_path}) options = ux.djangoVsWsgi(options) self.assertEqual(options['wsgi'], wsgi_dot_path) def test_wsgi_wrong_path_raises(self): wsgi_dot_path = '_this.leads.nowhere.man' self.assertRaises(ImportError, HendrixDeploy.importWSGI, wsgi_dot_path) def test_cwd_exposure(self): cwd = os.getcwd() _path = sys.path sys.path = [p for p in _path if p != cwd] self.assertTrue(cwd not in sys.path) ux.exposeProject(self.DEFAULTS) self.assertTrue(cwd in sys.path) def test_pythonpath(self): options = self.DEFAULTS test_path = os.path.join( os.path.dirname(os.getcwd()), 'hendrix/test/testproject' ) options['pythonpath'] = test_path ux.exposeProject(options) self.assertTrue(test_path in sys.path) sys.path = [p for p in sys.path if p != test_path] def test_shitty_pythonpath(self): options = self.DEFAULTS test_path = '/if/u/have/this/path/you/suck' options['pythonpath'] = test_path self.assertRaises(IOError, ux.exposeProject, options) def test_dev_friendly_options(self): options = self.DEFAULTS options['dev'] = True self.assertFalse(options['reload']) self.assertFalse(options['loud']) options = ux.devFriendly(options) self.assertTrue(options['reload']) self.assertTrue(options['loud']) def test_noise_control_daemonize(self): options = self.DEFAULTS options['quiet'] = True options['daemonize'] = True stdout = sys.stdout stderr = sys.stderr redirect = ux.noiseControl(options) self.assertEqual(sys.stdout.name, stdout.name) self.assertEqual(sys.stderr.name, stderr.name) self.assertEqual(redirect, None) def test_noise_control_traceback(self): options = self.DEFAULTS options['quiet'] = True options['daemonize'] = True options['traceback'] = True stdout = sys.stdout stderr = sys.stderr redirect = ux.noiseControl(options) self.assertEqual(sys.stdout.name, stdout.name) self.assertEqual(sys.stderr.name, stderr.name) self.assertEqual(redirect, None) def test_options_structure(self): """ A test to ensure that HendrixDeploy.options also has the complete set of options available """ deploy = self.wsgiDeploy() expected_keys = self.DEFAULTS.keys() actual_keys = deploy.options.keys() self.assertEqual(expected_keys, actual_keys)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,280
hendrix/hendrix
refs/heads/main
/examples/tls_server/gen-rsa.py
import datetime from cryptography import x509 from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.x509.oid import NameOID rsa_key = rsa.generate_private_key( public_exponent=65537, key_size=2048, backend=default_backend() ) subject = issuer = x509.Name([ x509.NameAttribute(NameOID.COMMON_NAME, u"hendrix-tls-example"), ]) cert = x509.CertificateBuilder().subject_name( subject ).issuer_name( issuer ).public_key( rsa_key.public_key() ).serial_number( x509.random_serial_number() ).not_valid_before( datetime.datetime.utcnow() ).not_valid_after( datetime.datetime.utcnow() + datetime.timedelta(days=10) ).add_extension( x509.SubjectAlternativeName([x509.DNSName(u"localhost")]), critical=False, ).sign(rsa_key, hashes.SHA256(), default_backend()) with open("rsa-privkey.pem", "wb") as f: f.write(rsa_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, encryption_algorithm=serialization.NoEncryption(), )) with open("rsa-pubkey.pem", "wb") as f: f.write(rsa_key.public_key().public_bytes( encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo, )) with open("rsa-certificate.pem", "wb") as f: f.write(cert.public_bytes(serialization.Encoding.PEM))
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,281
hendrix/hendrix
refs/heads/main
/hendrix/utils/__init__.py
import os import sys import tempfile from importlib import import_module import chalk import six HENDRIX_DIR = os.path.dirname(os.path.abspath(__file__)) # Default PID Directory PID_DIR = tempfile.mkdtemp(prefix='hendrix-') SHARE_PATH = os.path.join( os.path.dirname(sys.executable), 'share/hendrix' ) def get_pid(options): """returns The default location of the pid file for process management""" namespace = options['settings'] if options['settings'] else options['wsgi'] return os.path.join('{}', '{}_{}.pid').format(PID_DIR, options['http_port'], namespace.replace('.', '_')) def responseInColor(request, status, headers, prefix='Response', opts=None): "Prints the response info in color" code, message = status.split(None, 1) message = '%s [%s] => Request %s %s %s on pid %d' % ( prefix, code, str(request.host), request.method, request.path, os.getpid() ) signal = int(code) / 100 if signal == 2: chalk.green(message, opts=opts) elif signal == 3: chalk.blue(message, opts=opts) else: chalk.red(message, opts=opts) def import_string(dotted_path): """ Import a dotted module path and return the attribute/class designated by the last name in the path. Raise ImportError if the import failed. """ try: module_path, class_name = dotted_path.rsplit('.', 1) except ValueError: msg = "%s doesn't look like a module path" % dotted_path six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) module = import_module(module_path) try: return getattr(module, class_name) except AttributeError: msg = 'Module "%s" does not define a "%s" attribute/class' % ( dotted_path, class_name ) six.reraise(ImportError, ImportError(msg), sys.exc_info()[2])
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,282
hendrix/hendrix
refs/heads/main
/hendrix/options.py
import os from optparse import make_option, OptionParser from hendrix import defaults def cleanOptions(options): """ Takes an options dict and returns a tuple containing the daemonize boolean, the reload boolean, and the parsed list of cleaned options as would be expected to be passed to hx """ _reload = options.pop('reload') dev = options.pop('dev') opts = [] store_true = [ '--nocache', '--global_cache', '--quiet', '--loud' ] store_false = [] for key, value in options.items(): key = '--' + key if (key in store_true and value) or (key in store_false and not value): opts += [key, ] elif value: opts += [key, str(value)] return _reload, opts HX_OPTION_LIST = ( make_option( '-v', '--verbosity', action='store', dest='verbosity', default='1', type='choice', choices=['0', '1', '2', '3'], help=( 'Verbosity level; 0=minimal output, 1=normal output, 2=verbose ' 'output, 3=very verbose output' ) ), make_option( '--settings', dest='settings', type=str, default='', help=( 'The Python path to a settings module, e.g. "myproj.settings.x".' ' If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment ' 'variable will be used.' ) ), make_option( '--log', dest='log', type=str, default=os.path.join(defaults.DEFAULT_LOG_PATH, 'hendrix.log'), help=( 'file path to where the log files should live ' '[default: $PYTHON_PATH/lib/.../hendrix/hendrix.log]' ) ), make_option( '--pythonpath', help=( 'A directory to add to the Python path, e.g. ' '"/home/djangoprojects/myproject".' ) ), make_option( '--reload', action='store_true', dest='reload', default=False, help=( "Flag that watchdog should restart the server when changes to the " "codebase occur. NOTE: Do NOT uset this flag with --daemonize " "because it will not daemonize." ) ), make_option( '-l', '--loud', action='store_true', dest='loud', default=False, help="Use the custom verbose WSGI handler that prints in color" ), make_option( '-q', '--quiet', action='store_true', dest='quiet', default=False, help="Supress all output." ), make_option( '--http_port', type=int, dest='http_port', default=defaults.HTTP_PORT, help='Enter a port number for the server to serve content.' ), make_option( '--https_port', type=int, dest='https_port', default=defaults.HTTPS_PORT, help='Enter an ssl port number for the server to serve secure content.' ), make_option( '--https_only', dest='https_only', default=False, help='Declare whether to run only an https (not http) server.' ), make_option( '--cache_port', type=int, dest='cache_port', default=defaults.CACHE_PORT, help='Enter an cache port number to serve cached content.' ), make_option( '-g', '--global_cache', dest='global_cache', action='store_true', default=False, help='Make it so that there is only one cache server' ), make_option( '-c', '--cache', dest='cache', action='store_true', default=False, help='Disable page cache' ), make_option( '-w', '--workers', type=int, dest='workers', default=0, help='Number of processes to run' ), make_option( '--key', type=str, dest='key', default=None, help='Absolute path to SSL private key' ), make_option( '--cert', type=str, dest='cert', default=None, help='Absolute path to SSL public certificate' ), make_option( '--fd', type=str, dest='fd', default=None, help='DO NOT SET THIS' ), make_option( '--dev', dest='dev', action='store_true', default=False, help=( 'Runs in development mode. Meaning it uses the development wsgi ' 'handler subclass' ) ), make_option( '--wsgi', dest='wsgi', type=str, default=None, help=( 'Overrides the use of django settings for use in testing. N.B. ' 'This option is not for use with hx or hx.py' ) ), make_option( '--client-max-body-size', dest='max_upload_bytes', type=int, default=None,#1024*1024, help=('equivalent to nginx client_max_body_size in integer bytes (1024==1k)') ) ) HendrixOptionParser = OptionParser( description=( 'hx is the interface to hendrix, use to start and stop your server' ), usage='hx start|stop [options]', option_list=HX_OPTION_LIST ) def options(argv=[]): """ A helper function that returns a dictionary of the default key-values pairs """ parser = HendrixOptionParser parsed_args = parser.parse_args(argv) return vars(parsed_args[0])
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,283
hendrix/hendrix
refs/heads/main
/hendrix/utils/test_utils/__init__.py
from hendrix.experience import crosstown_traffic from hendrix.mechanics.concurrency.decorators import _ThroughToYou def crosstownTaskListDecoratorFactory(list_to_populate): class TaskListThroughToYou(_ThroughToYou): def __init__(self, *args, **kwargs): self.crosstown_task_list = list_to_populate super(TaskListThroughToYou, self).__init__(*args, **kwargs) def responseless_fallback(self, crosstown_task): self.crosstown_task_list.append(crosstown_task) return TaskListThroughToYou class AsyncTestMixin(object): def setUp(self): self.sub_setUp() return super(AsyncTestMixin, self).setUp() def sub_setUp(self): self.recorded_tasks = [] crosstown_traffic.decorator = crosstownTaskListDecoratorFactory(self.recorded_tasks) crosstown_traffic() self.archived_tasks = [] def next_task(self): for task in self.recorded_tasks: if task not in self.archived_tasks: self.archived_tasks.append(task) return task raise StopIteration("No more tasks.") def assertNumCrosstownTasks(self, num_tasks): if not num_tasks == len(self.recorded_tasks): raise AssertionError( "There were not %s recorded tasks. The recorded tasks were: %s" % (num_tasks, self.recorded_tasks))
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,284
hendrix/hendrix
refs/heads/main
/hendrix/logger.py
import io from twisted.logger import ( ILogObserver, jsonFileLogObserver, FilteringLogObserver, LogLevelFilterPredicate, LogLevel ) from zope.interface import provider from .defaults import DEFAULT_LOG_FILE @provider(ILogObserver) def hendrixObserver(path=DEFAULT_LOG_FILE, log_level=LogLevel.warn): json_observer = jsonFileLogObserver( io.open(path, 'a') ) return FilteringLogObserver( json_observer, [LogLevelFilterPredicate(log_level), ] )
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,285
hendrix/hendrix
refs/heads/main
/examples/tls_server/run_server.py
# A sample server using TLS with either RSA or EC. # To use this, first run either gen-ec.py or gen-rsa.py (or both). import sys from hendrix.deploy.tls import HendrixDeployTLS from hendrix.experience import hey_joe sys.path.append("../django_nyc_demo") from hendrix_demo.wsgi import application as hendrix_demo_app PORT = 8443 # EC variant # deployer = HendrixDeployTLS("start", # {"wsgi": hendrix_demo_app, "https_port": PORT}, # key="ec-key.pem", # cert="ec-certificate.pem", # context_factory=SpecifiedCurveContextFactory, # context_factory_kwargs={"curve_name": "secp256k1"} # ) # RSA variant deployer = HendrixDeployTLS("start", {"wsgi": hendrix_demo_app, "https_port": PORT}, key="rsa-privkey.pem", cert="rsa-certificate.pem", ) wss_service = hey_joe.WSSWebSocketService("127.0.0.1", 9443, allowedOrigins=["https://localhost:{}".format(PORT)]) deployer.add_tls_websocket_service(wss_service) deployer.run()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,286
hendrix/hendrix
refs/heads/main
/test/test_request_behavior.py
import io import os import pytest_twisted import requests from twisted.internet import threads from hendrix.deploy.base import HendrixDeploy from hendrix.facilities.resources import MediaResource from .resources import application @pytest_twisted.inlineCallbacks def test_max_upload_bytes(): statics_path = 'path_on_disk/to/files' os.makedirs(statics_path, exist_ok=True) options = { 'wsgi': application, 'max_upload_bytes': 200, 'http_port': 9876, 'resources': [MediaResource(statics_path, namespace=b'statics')] } deployer = HendrixDeploy(options=options) deployer.addServices() deployer.start() def reject_large_uploads(): # uploading 50 bytes is fine. byte_count = 50 ok_data = io.BytesIO(os.urandom(byte_count)) response = requests.post( "http://localhost:9876/", files={'data': ok_data} ) assert 200 == response.status_code # upload more than our max bytes and we fail with a 413 byte_count = 201 too_big = io.BytesIO(os.urandom(byte_count)) response = requests.post( "http://localhost:9876/", files={'data': too_big} ) assert 413 == response.status_code assert response.reason == "Request Entity Too Large" def test_static_files(): js_file = 'showmethisfile.js' filepath = os.path.join(statics_path, js_file) open(filepath, 'w').write('//console.log("Hello World");') response = requests.get( f"http://localhost:9876/statics/{js_file}", ) assert response.status_code == 200 assert '//console.log("Hello World");' in response.text os.remove(filepath) os.removedirs(statics_path) response = requests.get( f"http://localhost:9876/statics/{js_file}", ) assert response.status_code == 404 yield threads.deferToThread(reject_large_uploads) yield threads.deferToThread(test_static_files)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,287
hendrix/hendrix
refs/heads/main
/hendrix/experience/crosstown_traffic.py
import sys from twisted.internet import reactor from twisted.python.threadpool import ThreadPool class ModuleCaller(object): decorator = None def __init__(self, decorator=None): from hendrix.mechanics.concurrency.decorators import _ThroughToYou self.decorator = decorator or self.decorator or _ThroughToYou self.threadpool = ThreadPool(name="Crosstown Traffic") # The threadpool needs to start when the reactors starts... reactor.callWhenRunning(self.threadpool.start) # ...and stop when the reactor stops. reactor.addSystemEventTrigger('before', 'shutdown', self.threadpool.stop) super(ModuleCaller, self).__init__() def __call__(self, *args, **kwargs): try: threadpool = kwargs.pop('threadpool', self.threadpool) return self.decorator(threadpool=threadpool, *args, **kwargs) except TypeError as e: if e.args[0] == "__init__() got multiple values for keyword argument 'threadpool'": raise TypeError( "Did you forget the '()' when using the crosstown_traffic decorator? (ie, '@crosstown_traffic()'). Caught '%s'" % e.args[0]) else: raise sys.modules[__name__] = ModuleCaller()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,288
hendrix/hendrix
refs/heads/main
/hendrix/utils/conf.py
import os import jinja2 import yaml from . import SHARE_PATH def generateInitd(conf_file): """ Helper function to generate the text content needed to create an init.d executable """ allowed_opts = [ 'virtualenv', 'project_path', 'settings', 'processes', 'http_port', 'cache', 'cache_port', 'https_port', 'key', 'cert' ] base_opts = ['--daemonize', ] # always daemonize options = base_opts with open(conf_file, 'r') as cfg: conf = yaml.load(cfg) conf_specs = set(conf.keys()) if len(conf_specs - set(allowed_opts)): raise RuntimeError('Improperly configured.') try: virtualenv = conf.pop('virtualenv') project_path = conf.pop('project_path') except: raise RuntimeError('Improperly configured.') cache = False if 'cache' in conf: cache = conf.pop('cache') if not cache: options.append('--nocache') workers = 0 if 'processes' in conf: processes = conf.pop('processes') workers = int(processes) - 1 if workers > 0: options += ['--workers', str(workers)] for key, value in conf.iteritems(): options += ['--%s' % key, str(value)] with open(os.path.join(SHARE_PATH, 'init.d.j2'), 'r') as f: TEMPLATE_FILE = f.read() template = jinja2.Template(TEMPLATE_FILE) initd_content = template.render( { 'venv_path': virtualenv, 'project_path': project_path, 'hendrix_opts': ' '.join(options) } ) return initd_content
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,289
hendrix/hendrix
refs/heads/main
/hendrix/contrib/concurrency/signals.py
""" Signals for easy use in django projects """ try: from django import dispatch short_task = dispatch.Signal() long_task = dispatch.Signal() message_signal = dispatch.Signal() USE_DJANGO_SIGNALS = True except ImportError: USE_DJANGO_SIGNALS = False
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,290
hendrix/hendrix
refs/heads/main
/performance-tools/gunicorn_worker_test.py
from gunicorn.app.wsgiapp import WSGIApplication w = WSGIApplication() w.run()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,291
hendrix/hendrix
refs/heads/main
/test/test_hey_joe.py
from twisted.internet.testing import StringTransportWithDisconnection from hendrix.experience import hey_joe def test_websocket_mechanics(): """ Shows that we can put our protocol (hey_joe._WayDownSouth) and factory (hey_joe.WebSocketService) together, along with a transport, and properly open a websocket connection. """ transport = StringTransportWithDisconnection() service = hey_joe.WebSocketService("127.0.0.1", 9000) protocol = service.buildProtocol(service._hey_joe_addr) protocol.transport = transport transport.protocol = protocol protocol.connectionMade() data_to_send = b'GET / HTTP/1.1\r\nHost: somewhere_in_the_world:9000\r\nConnection: keep-alive, Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: F76ObkF/aCKX8WkmAgx2OQ==\r\n\r\n' protocol.dataReceived(data_to_send) assert transport.value().startswith(b'HTTP/1.1 101 Switching Protocols\r\nServer: hendrix')
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,292
hendrix/hendrix
refs/heads/main
/performance-tools/pyramid_with_crosstown_traffic.py
import os import sys import threading import time from multiprocessing import Pool import requests from pyramid.config import Configurator from pyramid.response import Response # begin chdir armor up = os.path.dirname(os.path.abspath(__file__)) testdir = os.path.dirname(up) hendrix_app_dir = os.path.dirname(testdir) hendrix_package_dir = os.path.dirname(hendrix_app_dir) sys.path.insert(0, hendrix_package_dir) # end chdir armor from hendrix.deploy.base import HendrixDeploy from zope.interface import provider from twisted.logger import ILogObserver, formatEvent @provider(ILogObserver) def simpleObserver(event): print(formatEvent(event)) # from twisted.logger import globalLogBeginner # globalLogBeginner.beginLoggingTo([simpleObserver], redirectStandardIO=False) def cpu_heavy(heft, label=None): count = 0 previous_count = 0 start = 1 previous = start one_before_that = 0 end = heft timer_start = time.time() while True: new = previous + one_before_that one_before_that = previous previous = new count += 1 if count == end / 2 and end % 2 == 0: print("%s halfway: %s" % (label, time.time() - timer_start)) time.sleep(0) if count == end: print("%s done: %s" % (label, time.time() - timer_start)) return global total_requests global avg_duration total_requests = 0 avg_duration = 0 def long(): global total_requests global avg_duration previous_duration = (total_requests * avg_duration) total_requests += 1 timer_start = time.time() thread = threading.current_thread() print("Starting stream %s on %s" % (total_requests, thread.name)) # cpu_heavy(100000, label) r = requests.get('http://localhost:8010/.25') duration = time.time() - timer_start print("Finished stream %s after %s" % (total_requests, duration)) avg_duration = float(previous_duration + duration) / float(total_requests) print("Average duration after %s: %s" % (total_requests, avg_duration)) class PerformanceTest(object): pool = Pool(20) def view(self, request): # option 1 # @crosstown_traffic() # def wait(): # long() # option 2 self.pool.apply_async(long) return Response() config = Configurator() config.add_route('test_view', '/') config.add_view(PerformanceTest().view, route_name='test_view') app = config.make_wsgi_app() if __name__ == '__main__': deployer = HendrixDeploy(options={'wsgi': app}) deployer.run()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,293
hendrix/hendrix
refs/heads/main
/test/resources.py
from multiprocessing import Queue from twisted.logger import Logger from hendrix.experience import crosstown_traffic from hendrix.mechanics.concurrency import get_response_for_thread, get_tasks_to_follow_current_response log = Logger() class TestNameSpace(object): async_task_was_done = Queue() async_task_was_run = False ready_to_proceed_with_second_cycle = Queue() second_cycle_complete = Queue() nameSpace = TestNameSpace() def application(environ, start_response): start_response('200 OK', [('Content-type', 'text/plain')]) if 'test_crosstown_traffic' in environ['QUERY_STRING'] or environ['PATH_INFO'] == '/r1': log.debug('Starting first cycle...') @crosstown_traffic() def delayed_callable(): TestNameSpace.async_task_was_run = True # This is the end of the test logic. TestNameSpace.async_task_was_done.put(None) # Save this response as the "first response" so that we can check later nameSpace.first_response = get_response_for_thread() tasks = nameSpace.first_response.crosstown_tasks # We have one task to run after the response. assert len(tasks) == 1 # The async task flag is still false (ie, the task hasn't run.) assert not nameSpace.async_task_was_run # Clear second cycle to begin. nameSpace.ready_to_proceed_with_second_cycle.put(True) # OK! Hold here until the second cycle completes. nameSpace.second_cycle_complete.get(True, 3) # Second cycle has completed, yet it didn't steal our crosstown_traffic assert len(tasks) == 1 # ...and again, the async task still hasn't been run yet. assert not nameSpace.async_task_was_run return [b'The first sync response'] if environ['PATH_INFO'] == '/r2': nameSpace.ready_to_proceed_with_second_cycle.get(True, 3) second_response_tasks = get_tasks_to_follow_current_response() # We didn't set any tasks during the second response. assert not second_response_tasks # However, the single task assigned during the first response is still # milling about. first_response_tasks = nameSpace.first_response.crosstown_tasks # And The async task flag is *still* false (ie, the task still has not # run, but it will once the first request finishes.) assert not nameSpace.async_task_was_run assert len(first_response_tasks) == 1 # ...and it's the one defined above. assert first_response_tasks[0].crosstown_task.__name__ == 'delayed_callable' nameSpace.second_cycle_complete.put(True) return [b'The second sync request.'] other_inane_thing = False return [b"Finished."]
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,294
hendrix/hendrix
refs/heads/main
/test/test_tls_requests.py
import datetime import os from ipaddress import IPv4Address import pytest_twisted import requests from OpenSSL.SSL import TLSv1_2_METHOD from OpenSSL.crypto import X509 as openssl_X509 from cryptography import x509 from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric import ec from cryptography.x509.oid import NameOID from twisted.internet import threads from hendrix.deploy.tls import HendrixDeployTLS from hendrix.facilities.resources import MediaResource from hendrix.facilities.services import ExistingKeyTLSContextFactory from .resources import application def get_certificate(): private_key = ec.generate_private_key(ec.SECP384R1, default_backend()) public_key = private_key.public_key() host = '127.0.0.1' now = datetime.datetime.utcnow() fields = [ x509.NameAttribute(NameOID.COMMON_NAME, host), ] subject = issuer = x509.Name(fields) cert = x509.CertificateBuilder().subject_name(subject) cert = cert.issuer_name(issuer) cert = cert.public_key(public_key) cert = cert.serial_number(x509.random_serial_number()) cert = cert.not_valid_before(now) cert = cert.not_valid_after(now + datetime.timedelta(days=1)) cert = cert.add_extension(x509.SubjectAlternativeName([x509.IPAddress(IPv4Address(host))]), critical=False) cert = cert.sign(private_key, hashes.SHA512(), default_backend()) return cert, private_key def test_get_certificate(): get_certificate() @pytest_twisted.inlineCallbacks def test_ssl_request(): port = 9252 pem_path = 'public.pem' statics_path = 'path_on_disk/to/files' os.makedirs(statics_path, exist_ok=True) cert, pk = get_certificate() options = { 'wsgi': application, 'max_upload_bytes': 200, 'https_port': port, 'resources': [MediaResource(statics_path, namespace=b'statics')], } deployer = HendrixDeployTLS( key=pk, cert=openssl_X509.from_cryptography(cert), context_factory=ExistingKeyTLSContextFactory, context_factory_kwargs={ "curve_name": ec.SECP384R1.name, "sslmethod": TLSv1_2_METHOD }, options=options ) deployer.addServices() deployer.start() def test_ssl_static_files(): js_file = 'showmethisfile.js' filepath = os.path.join(statics_path, js_file) with open(pem_path, "w") as pub_file: pub_file.write(cert.public_bytes(serialization.Encoding.PEM).decode('utf-8')) with open(filepath, 'w') as js_write: js_write.write('//console.log("Hello World");') response = requests.get( f"https://127.0.0.1:{port}/statics/{js_file}", verify=pem_path ) assert response.status_code == 200 assert '//console.log("Hello World");' in response.text os.remove(filepath) os.removedirs(statics_path) os.remove(pem_path) d = threads.deferToThread(test_ssl_static_files) yield d
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,295
hendrix/hendrix
refs/heads/main
/test/utils.py
import io import unittest from twisted.internet import reactor from twisted.logger import eventsFromJSONLogFile from hendrix.contrib import SettingsError from hendrix.defaults import * from hendrix.deploy.base import HendrixDeploy from hendrix.utils import get_pid TEST_SETTINGS = 'test.testproject.settings' def iter_test_logs(): log_file = io.open(DEFAULT_LOG_FILE) for event in eventsFromJSONLogFile(log_file): if event.get('log_namespace').startswith('test'): yield event class HendrixTestCase(unittest.TestCase): """ This is where we collect our helper functions to test hendrix """ def setUp(self): self.reactor = reactor def deploy(self, action, options): return HendrixDeploy(action, options, reactor=self.reactor) def tearDown(self): """ cleans up the reactor after running startService on a twisted.application.service """ test_pid_file = get_pid( {'settings': TEST_SETTINGS, 'http_port': HTTP_PORT} ) if os.path.exists(test_pid_file): os.remove(test_pid_file) self.reactor.disconnectAll() return self.reactor.removeAll() def wsgiDeploy(self, action='start', options={}): """ Overrides the deploy functionality to test hendrix outside of the whole django LazySettings.configure() thing. HOWEVER, as the plugin does rely on `from djanog.conf import settings` we should test that flow path also... """ if options.get('settings'): raise SettingsError("uh uh uh... Don't use settings here.") if not options.get('wsgi'): options.update({'wsgi': 'test.wsgi'}) return self.deploy(action, options) def settingsDeploy(self, action='start', options={}): "Use the hendrix test project to test the bash deployment flow path" os.environ['DJANGO_SETTINGS_MODULE'] = TEST_SETTINGS options.update({'settings': TEST_SETTINGS}) return self.deploy(action, options)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,296
hendrix/hendrix
refs/heads/main
/performance-tools/simple_delay_server.py
import os import sys import time from pyramid.config import Configurator from pyramid.response import Response from twisted.internet import reactor from twisted.python.threadpool import ThreadPool tp = reactor.suggestThreadPoolSize(1000) # begin chdir armor up = os.path.dirname(os.path.abspath(__file__)) testdir = os.path.dirname(up) hendrix_app_dir = os.path.dirname(testdir) hendrix_package_dir = os.path.dirname(hendrix_app_dir) sys.path.insert(0, hendrix_package_dir) # end chdir armor from hendrix.deploy.base import HendrixDeploy import threading def delay(request): delay_time = float(request.matchdict['seconds']) print "Thread %s sleeping for %s seconds" % (threading.current_thread(), delay_time) time.sleep(delay_time) return Response('') if __name__ == '__main__': config = Configurator() config.add_route('delay', '/{seconds}') config.add_view(delay, route_name='delay') app = config.make_wsgi_app() tp = ThreadPool(name="Big and Slow.", maxthreads=1000) deployer = HendrixDeploy(options={'wsgi': app, 'http_port': 8010}, threadpool=tp) deployer.run()
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,059,297
hendrix/hendrix
refs/heads/main
/examples/tls_server/run_client.py
# This shows that your tls server is running and properly serving. To test the TLS websocket via WSS, load the URL # in a browser and allow a temporary verification exemption for the cert. import requests response = requests.get("https://localhost:8443/my_noodles", verify="rsa-certificate.pem") assert response.status_code == 200 print(response.content)
{"/hendrix/facilities/services.py": ["/hendrix/facilities/resources.py"], "/examples/django_hx_chatserver/example_app/chat/views.py": ["/examples/django_hx_chatserver/example_app/chat/models.py"], "/test/debug_test_application.py": ["/hendrix/deploy/base.py"], "/hendrix/mechanics/concurrency/__init__.py": ["/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_hx_chatserver/example_app/chat/models.py": ["/hendrix/contrib/concurrency/signals.py"], "/hendrix/ux.py": ["/hendrix/contrib/__init__.py", "/hendrix/logger.py", "/hendrix/mechanics/concurrency/exceptions.py", "/hendrix/options.py"], "/hendrix/deploy/base.py": ["/hendrix/__init__.py", "/hendrix/facilities/gather.py", "/hendrix/facilities/protocols.py", "/hendrix/facilities/services.py", "/hendrix/options.py", "/hendrix/utils/__init__.py"], "/hendrix/deploy/tls.py": ["/hendrix/facilities/services.py", "/hendrix/deploy/base.py"], "/test/test_resources.py": ["/hendrix/facilities/resources.py"], "/hendrix/deploy/cache.py": ["/hendrix/contrib/services/cache.py", "/hendrix/deploy/base.py"], "/hendrix/contrib/resources/static.py": ["/hendrix/facilities/resources.py"], "/hendrix/experience/hey_joe.py": ["/hendrix/contrib/concurrency/signals.py", "/hendrix/contrib/concurrency/resources.py"], "/hendrix/contrib/cache/resource.py": ["/hendrix/utils/__init__.py", "/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/memory_cache.py"], "/hendrix/management/commands/hx.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/hendrix/contrib/cache/backends/__init__.py": ["/hendrix/contrib/cache/__init__.py"], "/test/test_testing_utils.py": ["/hendrix/utils/test_utils/__init__.py"], "/hendrix/mechanics/concurrency/decorators.py": ["/hendrix/mechanics/concurrency/__init__.py", "/hendrix/mechanics/concurrency/exceptions.py"], "/examples/django_nyc_demo/run.py": ["/hendrix/deploy/base.py"], "/hendrix/facilities/response.py": ["/hendrix/utils/__init__.py"], "/hendrix/contrib/services/cache.py": ["/hendrix/contrib/cache/resource.py", "/hendrix/facilities/services.py"], "/test/test_hx_launcher.py": ["/hendrix/options.py", "/hendrix/ux.py"], "/test/test_crosstown_traffic.py": ["/hendrix/facilities/resources.py", "/hendrix/mechanics/concurrency/exceptions.py", "/test/resources.py"], "/test/test_deploy.py": ["/test/utils.py"], "/hendrix/contrib/concurrency/resources.py": ["/hendrix/facilities/resources.py", "/hendrix/contrib/concurrency/messaging.py", "/hendrix/contrib/concurrency/signals.py"], "/examples/django_hx_chatserver/example_app/run.py": ["/hendrix/deploy/base.py"], "/hendrix/deploy/hybrid.py": ["/hendrix/deploy/cache.py", "/hendrix/deploy/tls.py"], "/hendrix/contrib/cache/backends/memory_cache.py": ["/hendrix/contrib/cache/__init__.py", "/hendrix/contrib/cache/backends/__init__.py"], "/hendrix/facilities/resources.py": ["/hendrix/facilities/response.py"], "/setup.py": ["/hendrix/__init__.py"], "/test/test_ux.py": ["/hendrix/__init__.py", "/hendrix/contrib/__init__.py", "/hendrix/deploy/base.py", "/hendrix/options.py", "/test/utils.py"], "/hendrix/options.py": ["/hendrix/__init__.py"], "/hendrix/utils/test_utils/__init__.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/logger.py": ["/hendrix/defaults.py"], "/examples/tls_server/run_server.py": ["/hendrix/deploy/tls.py"], "/test/test_request_behavior.py": ["/hendrix/deploy/base.py", "/hendrix/facilities/resources.py", "/test/resources.py"], "/hendrix/experience/crosstown_traffic.py": ["/hendrix/mechanics/concurrency/decorators.py"], "/hendrix/utils/conf.py": ["/hendrix/utils/__init__.py"], "/performance-tools/pyramid_with_crosstown_traffic.py": ["/hendrix/deploy/base.py"], "/test/resources.py": ["/hendrix/mechanics/concurrency/__init__.py"], "/test/test_tls_requests.py": ["/hendrix/deploy/tls.py", "/hendrix/facilities/resources.py", "/hendrix/facilities/services.py", "/test/resources.py"], "/test/utils.py": ["/hendrix/contrib/__init__.py", "/hendrix/defaults.py", "/hendrix/deploy/base.py", "/hendrix/utils/__init__.py"], "/performance-tools/simple_delay_server.py": ["/hendrix/deploy/base.py"]}
35,122,911
sumeet-with-2e/n-chess
refs/heads/main
/venv1/lib/python3.10/site-packages/openai/version.py
VERSION = "0.27.4"
{"/playchess.py": ["/driver.py", "/board_functions.py"], "/driver.py": ["/board_functions.py"]}
35,122,912
sumeet-with-2e/n-chess
refs/heads/main
/board_functions.py
import chess as ch import chess.svg as svg def make_board(): board = ch.Board() boardgui = svg.board(board=board) return board def show_board(board): boardgui = svg.board(board=board) return boardgui def is_valid(board): if (board.is_valid() and not board.is_checkmate() and not board.is_stalemate() and not board.is_insufficient_material() and not board.is_seventyfive_moves() and not board.is_fivefold_repetition()): return True def board_update(board, move): todo = ch.Move.from_uci(move) board.push(todo) return board def board_reset(board): board.reset() def board_undo(board): board.pop()
{"/playchess.py": ["/driver.py", "/board_functions.py"], "/driver.py": ["/board_functions.py"]}
35,122,913
sumeet-with-2e/n-chess
refs/heads/main
/playchess.py
from flask import Flask, redirect, url_for, request, render_template from svglib.svglib import svg2rlg import driver as dr import board_functions as bf app = Flask(__name__) @app.route('/') def home(): #boardgui = svg2rlg('board.svg') return render_template('base.html') @app.route('/pvp') def pvp(): svgboard = dr.player_vs_player(bf.make_board()) return render_template('pvp.html', content = svgboard) @app.route('/pvc') def pvc(): svgboard = dr.player_vs_computer(dr.board) return render_template('pvp.html', content = svgboard) @app.route('/cvc') def cvc(): svgboard = dr.computer_vs_computer(dr.board) return render_template('pvp.html', content = svgboard) if __name__ == '__main__': app.run(debug=True)
{"/playchess.py": ["/driver.py", "/board_functions.py"], "/driver.py": ["/board_functions.py"]}
35,122,914
sumeet-with-2e/n-chess
refs/heads/main
/driver.py
import board_functions as bf #import engine def player_vs_player(board): bf.board_reset(board) return bf.show_board(board) while bf.is_valid(board): print(''' Enter Move: ''') move = input() board = bf.board_update(board, move) # print svg board svgboard = bf.show_board(board) return svgboard def player_vs_computer(): pass def computer_vs_computer(): pass def main(): board = bf.make_board() #engine.make_engine() print(''' Enter Game Type: 1. Player vs Player 2. Player vs Computer 3. Computer vs Computer ''') game_type = input() if game_type == '1': player_vs_player(board) elif game_type == '2': player_vs_computer(board) elif game_type == '3': computer_vs_computer(board)
{"/playchess.py": ["/driver.py", "/board_functions.py"], "/driver.py": ["/board_functions.py"]}
35,122,915
sumeet-with-2e/n-chess
refs/heads/main
/engine.py
import chess.engine engine = chess.engine.SimpleEngine.popen_uci("stockfish-mv")
{"/playchess.py": ["/driver.py", "/board_functions.py"], "/driver.py": ["/board_functions.py"]}
35,174,485
joicodes/Skybot
refs/heads/master
/test/test_app.py
import unittest import requests import random # import app import xml.etree.ElementTree as ET from twilio.rest import Client rand_num = str(random.randint(100000000000, 111111111111)) class AppTests(unittest.TestCase): ''' def test_new_user(self): req = requests.post('https://cuskybot.herokuapp.com/sms', data = {'To': '+16674014282', 'From': rand_num, 'Body': 'me'}) root = ET.fromstring(str(req.text)) for child in root: message = child.text break self.assertEqual(message, "Welcome to Skybot! What's your UNI?") def test_uni_login(self): req = requests.post('https://cuskybot.herokuapp.com/sms', data = {'To': '+16674014282', 'From': rand_num, 'Body': 'mj2729'}) root = ET.fromstring(str(req.text)) for child in root; message = child.text break self.assertEqual(message, "Check your email for a verification email and text us the code") def test_verfication(self) user = session.query(Users).filter(User.uni == mj2729).first() user_verification = user.verification_code req = requests.post('https://cuskybot.herokuapp.com/sms', data = {'To': '+16674014282', 'From': rand_num, 'Body': user_verification}) root = ET.fromstring(str(req.text)) for child in root; message = child.text break self.assertEqual(message, str(Thanks for verifying! Let's start flight information. Please answer the following, separated by commas: 1. JFK/LGA/EWR 2. Date (MM/DD/YYYY) 3. Flight Time (XX:XX AM/PM) 4. Maximum Number of Additional Passengers)) ''' if __name__ == '__main__': unittest.main()
{"/test/test_database.py": ["/database.py"], "/app.py": ["/database.py"], "/database.py": ["/app.py"], "/match.py": ["/app.py"]}
35,174,486
joicodes/Skybot
refs/heads/master
/database.py
import datetime from flask import Flask from flask_sqlalchemy import SQLAlchemy import sqlalchemy from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String, ForeignKey from sqlalchemy.orm import sessionmaker, relationship from app import db class User(db.Model): """ SQLAlchemy Users Model """ __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) uni = db.Column(db.String(80)) max_passengers = db.Column(db.Integer) phone_number = db.Column(db.String(50), unique=True) flights = relationship("Flight", backref="passenger") verification_code = Column(Integer) verified = Column(String(10), default='NONE') def __init__(self, uni, max_passengers, phone_number, flights, verification_code, verified): self.uni = uni self.max_passengers = max_passengers self.phone_number = phone_number self.flights = flights self.verification_code = verification_code self.verified = verified def __repr__(self): return '<id {}>'.format(self.id) class Flight(db.Model): """ SQLAlchemy Flights Model """ __tablename__ = 'flights' id = db.Column(db.Integer, primary_key=True) airport = db.Column(db.String(3)) flight_date = db.Column(db.Integer) departure_time = db.Column(db.Integer) passenger_id = db.Column(db.Integer, db.ForeignKey('users.id')) match_id = db.Column(db.Integer, db.ForeignKey('matches.id')) def __init__(self, airport, flight_date, departure_time, passenger_id, match_id): self.airport = airport self.flight_date = flight_date self.departure_time = departure_time self.passenger_id = passenger_id self.match_id = match_id def __repr__(self): return '<id {}>'.format(self.id) class Match(db.Model): __tablename__ = 'matches' id = db.Column(db.Integer, primary_key=True) airport = db.Column(db.String(3)) ride_date = db.Column(db.Integer) ride_departureTime = db.Column(db.Integer) available_seats = db.Column(db.Integer) # can be done by querying the match id riders = relationship("Flight", backref="ride") def __init__(self, airport, ride_date, ride_departureTime, available_seats, riders): self.airport = airport self.ride_date = ride_date self.ride_departureTime = ride_departureTime self.available_seats = available_seats self.riders = riders def __repr__(self): return '<id {}>'.format(self.id)
{"/test/test_database.py": ["/database.py"], "/app.py": ["/database.py"], "/database.py": ["/app.py"], "/match.py": ["/app.py"]}
35,174,487
joicodes/Skybot
refs/heads/master
/cost.py
import json import requests def get_cost(location, num_passengers): """ Provides Skybot with Lyft cost from Columbia to needed airport Args: location (str): JFK, LGA, or EWR num_passengers (int): number of passengers Return: cost (str): cost of the lyft ride """ # Gets the cost of a Lyft from Columbia to JFK Airport jfk = requests.get('https://api.lyft.com/v1/cost?start_lat=40.8075&start_lng=-73.9626&end_lat=40.6413&end_lng=-73.7781') jfk_json = json.loads(jfk.text) # Gets the cost of a Lyft from Columbia to La Guardia Airport (LGA) lga = requests.get('https://api.lyft.com/v1/cost?start_lat=40.8075&start_lng=-73.9626&end_lat=40.7769&end_lng=-73.8740') lga_json = json.loads(lga.text) # Gets cost of a Lyft from Columbia to Newark International Airport (EWR) ewr = requests.get('https://api.lyft.com/v1/cost?start_lat=40.8075&start_lng=-73.9626&end_lat=40.6895&end_lng=-74.1745') ewr_json = json.loads(ewr.text) # Returns the cost of the ride based on the passed airport location if location.upper() == "JFK": jfk_cost = '%.2f' % ((jfk_json['cost_estimates'][1]['estimated_cost_cents_max']/100) / num_passengers) cost = '$'+str(jfk_cost) if location.upper() == "LGA": lga_cost = '%.2f' % ((lga_json['cost_estimates'][1]['estimated_cost_cents_max']/100) / num_passengers) cost = '$'+str(lga_cost) if location.upper() == "EWR": ewr_cost = '%.2f' % ((ewr_json['cost_estimates'][1]['estimated_cost_cents_max']/100) / num_passengers) cost = '$'+str(ewr_cost) return cost
{"/test/test_database.py": ["/database.py"], "/app.py": ["/database.py"], "/database.py": ["/app.py"], "/match.py": ["/app.py"]}
35,174,488
joicodes/Skybot
refs/heads/master
/test/test_database.py
from database import * from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker import unittest import sqlalchemy import sys sys.path.append('Skybot/') engine = create_engine('postgres://ehepwtnqjcfntn:04461d661ce43b16602000fb490e32ece1f3558bddac8f4c6059886544f7c7cd@ec2-107-21-125-209.compute-1.amazonaws.com:5432/d6uqqsindhtp99') Session = sessionmaker(autoflush=True, autocommit=False, bind=engine) conn = engine.connect() session = Session(bind=conn) db.drop_all() db.create_all() # Creates test database instances test_user1 = User(uni='test100', max_passengers=2, phone_number="100000001", flights=[], verification_code=123, verified="isVerified") test_user2 = User(uni='test101', max_passengers=1, phone_number="100000002", flights=[], verification_code=456, verified="isVerified") test_user3 = User(uni='test102', max_passengers=2, phone_number="100000003", flights=[], verification_code=789, verified="isVerified") test_user4 = User(uni='test103', max_passengers=2, phone_number="100000004", flights=[], verification_code=101, verified="isVerified") test_user5 = User(uni='test105', max_passengers=2, phone_number="100000005", flights=[], verification_code=129, verified="isVerified") test_flight1 = Flight(airport='JFK', flight_date=10312018, departure_time=1028, passenger_id=test_user1.id, match_id=None) test_flight2 = Flight(airport='JFK', flight_date=10312018, departure_time=1230, passenger_id=test_user2.id, match_id=None) test_flight3 = Flight(airport='LGA', flight_date=12252018, departure_time=1245, passenger_id=test_user3.id, match_id=None) test_flight4 = Flight(airport='LGA', flight_date=12252018, departure_time=900, passenger_id=test_user4.id, match_id=None) test_flight5 = Flight(airport='LGA', flight_date=12252018, departure_time=1100, passenger_id=test_user1.id, match_id=None) test_flight6 = Flight(airport='JFK', flight_date=10312018, departure_time=928, passenger_id=test_user5.id, match_id=None) class TestDatabase(unittest.TestCase): # Testing for schema def test_UserSchema(self): result = str(User) self.assertEqual(result, "<class 'database.User'>") def test_FlightSchema(self): result = str(Flight) self.assertEqual(result, "<class 'database.Flight'>") def test_MatchSchema(self): result = str(Match) self.assertEqual(result, "<class 'database.Match'>") # Test querying data def test_AddingUsers(self): db.session.add(test_user1) db.session.add(test_user2) db.session.add(test_user3) db.session.add(test_user4) db.session.commit() result = str(User.query.all()) self.assertEqual(result, "[<id 1>, <id 2>, <id 3>, <id 4>]") def test_AddingFlight(self): db.session.add(test_flight1) db.session.add(test_flight2) db.session.add(test_flight3) db.session.add(test_flight4) db.session.add(test_flight5) db.session.commit() result = str(Flight.query.all()) self.assertEqual(result, "[<id 1>, <id 2>, <id 3>, <id 4>, <id 5>]") def test_UserQuery(self): # Checks whether existing user's phone number can be found in the db pnumber = '100000001' check_num = db.session.query(User).filter(User.phone_number == pnumber) result = db.session.query(check_num.exists()).scalar() self.assertEqual(result, True) def test_ReturnUserInfo(self): # Query a user's max passengers and phone number based on uni test_uni = 'test101' user = db.session.query(User).filter(User.uni == test_uni).first() phone = user.phone_number maxpass = user.max_passengers result = (phone, maxpass) self.assertEqual(result, ('100000002', 1)) def test_ReturnFlightInfo(self): # Query flight times and airports based on date test_date = 10312018 matching_flights = db.session.query(Flight).filter(Flight.flight_date == test_date).all() flight_info = [] for i in range(0, len(matching_flights)): flight_info.append((matching_flights[i].airport, matching_flights[i].departure_time)) result = flight_info self.assertEqual(result, [('JFK', 1028), ('JFK', 1230)]) def test_Delete(self): # Deletes test cases from database Flight.query.filter_by(id=test_flight3.id).delete() results = str(Flight.query.all()) self.assertEqual(results, "[<id 1>, <id 2>, <id 4>, <id 5>]") def test_RepeatedUni(self): error = "false" try: test_user6 = User(uni='test100', max_passengers=2, phone_number="100000001") db.session.add(test_user6) db.session.commit() except: db.session.rollback() error = "User is already in database" self.assertEqual(error, "User is already in database")
{"/test/test_database.py": ["/database.py"], "/app.py": ["/database.py"], "/database.py": ["/app.py"], "/match.py": ["/app.py"]}
35,174,489
joicodes/Skybot
refs/heads/master
/app.py
import datetime import os import random import re import unittest from datetime import datetime import requests import json import sendgrid import sqlalchemy from flask import Flask from flask import redirect from flask import request from flask_sqlalchemy import SQLAlchemy from sendgrid.helpers.mail import * from sqlalchemy import create_engine from sqlalchemy import exists from sqlalchemy.orm import sessionmaker from twilio.rest import Client from twilio.twiml.messaging_response import MessagingResponse app = Flask(__name__) app.config.from_object(['APP_SETTINGS']) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres://ehepwtnqjcfntn:04461d661ce43b16602000fb490e32ece1f3558bddac8f4c6059886544f7c7cd@ec2-107-21-125-209.compute-1.amazonaws.com:5432/d6uqqsindhtp99' db = SQLAlchemy(app) from database import * # airport options airports = ["JFK", "LGA", "EWR"] def get_cost(location, num_passengers): """ Provides Skybot with Lyft cost from Columbia to needed airport Args: location (str): JFK, LGA, or EWR num_passengers (int): number of passengers Return: cost (str): cost of the lyft ride """ # Returns the cost of the ride based on the passed airport location if location.upper() == "JFK": jfk = requests.get('https://api.lyft.com/v1/cost?start_lat=40.8075&start_lng=-73.9626&end_lat=40.6413&end_lng=-73.7781') jfk_cost = '%.2f' % ((json.loads(jfk.text)['cost_estimates'][1]['estimated_cost_cents_max']/100) / num_passengers) return '$'+str(jfk_cost) elif location.upper() == "LGA": lga = requests.get('https://api.lyft.com/v1/cost?start_lat=40.8075&start_lng=-73.9626&end_lat=40.7769&end_lng=-73.8740') lga_json = json.loads(lga.text) lga_cost = '%.2f' % ((json.loads(lga.text)['cost_estimates'][1]['estimated_cost_cents_max']/100) / num_passengers) return '$'+str(lga_cost) elif location.upper() == "EWR": ewr = requests.get('https://api.lyft.com/v1/cost?start_lat=40.8075&start_lng=-73.9626&end_lat=40.6895&end_lng=-74.1745') ewr_cost = '%.2f' % ((json.loads(ewr.text)['cost_estimates'][1]['estimated_cost_cents_max']/100) / num_passengers) return '$'+str(ewr_cost) else: return "Cost could not be calculated" def notify_user(phone_number, unis, cost): """ Notifies user of their match results Args: phone_number (str): user's phone number unis (list): list of UNIs user is matched to """ # create twilio client client = Client(os.getenv('TWILIO_KEY'), os.getenv('TWILIO_TOKEN')) # send actual text message to user message = client.messages.create( to=phone_number, from_=os.getenv('SKYBOT_TWILIO_NUM'), body="Your matches are " + unis + " with an estimated cost of " + cost ) def send_matches(match_unis, match_nums): """ Handles returning matching unis to user Args: match_unis (list): list of unis that are matched match_nums (list): list of matched phone numbers Returns: TwiML: Twilio formated to send text message """ resp = MessagingResponse() unis = "" # string to send match results # when a user has no matches if len(match_unis) == 0: resp.message( """No matches for you right now, but we'll send you an update if there's a match!""", ) else: # iterates through UNIs list to create string for text message for x in range(0, len(match_unis)-2): # appends to uni string for eventual message unis = unis + str(match_unis[x]) + " " # retrieve cost of ride cost = get_cost(match_unis[-1], len(match_nums)) # iterates through list of matches and notifies the user of match for num in match_nums[:-1]: notify_user(num, unis, cost) # texts text message to current user (we might not need this) reply = "Your matches are " + unis + " with an estimated cost of " + cost resp.message(reply) return resp def parse_date(date_entry): """ Handles checking valid date entry Args: date_entry (str): date entry from user's text message Returns: bool: whether input is valid str: date string for matching """ cur_date = datetime.datetime.now() flt_date = str(date_entry) if re.match(r"[0-9]*-[0-9]*-[0-9]*", flt_date) is not None: date_str = flt_date.replace('-', '') else: return False, "" entry_date = datetime.datetime( int(date_str[4:8]), int(date_str[0:2]), int(date_str[2:4]), ) if ( len(date_str) > 8 or len(date_str) < 1 or int(date_str[0:2].lstrip("0")) < 0 or int(date_str[0:2].lstrip("0")) > 12 or int(date_str[2:4].lstrip("0")) < 1 or int(date_str[2:4].lstrip("0")) > 31 or entry_date < cur_date ): return False, "" else: return True, date_str def parse_time(body): """ Checks checking whether date entry is valid Returns: bool: whether input is valid str: date string for matching """ print("Body: " + str(body)) time_ent = body if re.search('[a-zA-Z]', time_ent) is not None: return False, "" elif( len(time_ent) != 6 or int(time_ent[0:2].lstrip("0")) > 24 or int(time_ent[0:2].lstrip("0")) < 1 or int(time_ent[2:4].lstrip("0")) < 1 or int(time_ent[2:4].lstrip("0")) > 60 or int(time_ent[4:6].lstrip("0")) < 1 or int(time_ent[4:6].lstrip("0")) > 60 ): return False, "" else: return True, time_ent def parse_max(body): """ Handles checking valid time entry Args: body (str): text message containing max number of passengers Returns: bool: whether max number is 1 or 2 int: number of user's max passengers """ if re.search('[a-zA-Z]', body) is not None: return False, "" elif int(body) > 2 or int(body) < 1: return False, "" else: return True, int(body) def verify(pnumber, body): """ Handles initial info collection for flight Function is triggered whenever they send in a correct verification code. Args: pnumber (str): current user's phone number body (str): current user's text message Returns: TwiML: Twilio text message to send to user """ resp = MessagingResponse() # filters database for current user entry row = db.session.query(User).filter(User.phone_number == pnumber).first() # once a user is verified, send the text thanking & prompting for airport if str(row.verified) == "VERIFIED": resp.message("""Thanks for verifying! Let's get started with your flight information. Please enter the Airport: (1)JFK (2)LGA (3)EWR""") row.verified = "AIRPORT_IN" # switch to next state db.session.commit() # error checking for airport elif str(row.verified) == "AIRPORT_IN": # tells user that they need to submit a number instead of letters if re.search('[a-zA-Z]', body) is not None: resp.message("""No letters. Please enter 1 for JFK, 2 for LGA or 3 for EWR""") # tells user that they have the incorrect format elif int(body) < 1 or int(body) > 3: resp.message("""Incorrect Format. Please enter 1 for JFK, 2 for LGA or 3 for EWR""") else: # once we have the airport, we prompt for the date info resp.message("""Please enter Date of Flight Departure in following format MM-DD-YYYY""") cur_airport = str(airports[int(body) - 1]) # once the airport is input, we create an initial flight instance new_flight(cur_airport, row.id) # switch to next state row.verified = "DATE_INFO" db.session.commit() # add airport to user's flight db entry -- might not need this? flight = db.session.query(Flight).order_by(Flight.id.desc()).filter(Flight.passenger_id == row.id).first() flight.airport = cur_airport db.session.commit() # once a user has input the airport, we retrieve the date elif str(row.verified) == "DATE_INFO": valid, str_date = parse_date(body) # if the date format is correct if valid is True: cur_fltDate = int(str_date) resp.message("""Please enter flight time in following Military time format HHMMSS""") row.verified = "FLIGHT_TIM" # update to next state db.session.commit() # update the flight db entry flight = db.session.query(Flight).order_by(Flight.id.desc()).filter(Flight.passenger_id == row.id).first() flight.flight_date = int(cur_fltDate) db.session.commit() else: # if incorrect format, let them know resp.message("""Incorrect Format. Please enter in following format MM-DD-YYYY""") elif str(row.verified) == "FLIGHT_TIM": valid, str_time = parse_time(body) if valid is True: resp.message("""Last thing, please enter the max number of passengers you're willing to ride with as a number. Ex. 2""") cur_fltTime = int(str_time) row.verified = "FINISHED" db.session.commit() flight = db.session.query(Flight).order_by(Flight.id.desc()).filter(Flight.passenger_id == row.id).first() flight.departure_time = int(cur_fltTime) db.session.commit() else: resp.message( """Incorrect Format. Please enter in milliary format HHMMSS""", ) elif str(row.verified) == "FINISHED": valid, int_max = parse_max(body) flight = db.session.query(Flight).order_by(Flight.id.desc()).filter(Flight.passenger_id == row.id).first() if valid is True: cur_max = int_max matches, match_nums = matchFound(row, flight, cur_max) resp = send_matches(matches, match_nums) else: resp.message( """Error, you can only enter between 1-2 passengers""", ) return str(resp) def send_verify_email(uni, email, pnumber): """ Sends user verification email Keyword arguments: email -- user's email address Returns: TwiML: text message to send to user """ if check_uni(uni) is True: pass else: return str(error("Invalid uni: Send it again.")) sg = sendgrid.SendGridAPIClient(os.getenv('SENDGRID_TOKEN')) user_uni = uni from_email = Email("CUSkyBot@gmail.com") to_email = Email(str(email)) subject = "Verify Email with SkyBot" random_num = random.randint(100000, 111111) row = db.session.query(User).filter(User.phone_number == pnumber).first() row.verification_code = random_num row.uni = user_uni db.session.commit() content = Content("text/plain", "Verifcation Code: " + str(random_num)) mail = Mail(from_email, subject, to_email, content) response = sg.client.mail.send.post(request_body=mail.get()) resp = MessagingResponse() resp.message( """Check your email for a verification email and text us the code""", ) # update email verified row.verified = "EMAIL_SENT" db.session.commit() return str(resp) def reverify_uni(): """ Handles the case when wrong verification_code given Returns: TwiML: text message to send to user """ resp = MessagingResponse() resp.message( "The verification code does not match. Please enter your UNI again", ) return str(resp) def error(message): """ Sends error text message Args: message (str): error type to send as a text Returns: TwiML: text message to send to user """ resp = MessagingResponse() error_message = "Error: " + str(message) resp.message(error_message) return str(resp) def check_valid_code(pnumber, body): """ Handles checking valid code Args: pnumber (str): user's phone number body (str): user's input code Returns: bool: whether the verification code is correct or not """ curr_user = db.session.query(User).filter_by( phone_number=pnumber, ).first() if re.search('[a-zA-Z]', body) is None: pass else: return False if int(body) == curr_user.verification_code is False: return False else: return True def exist_user(phone_number, body): """ Handles communication with existing Skybot users Args: phone_number (str): user's phone number body (str): user's text message Returns: TwiML: text message to send to user """ curr_user = db.session.query(User).filter_by( phone_number=phone_number, ).first() # if verify state is NONE, call send email function if curr_user.verified == 'NONE': # email is not verified message = send_verify_email(body, body + "@columbia.edu", phone_number) elif curr_user.verified == "EMAIL_SENT" and check_valid_code(phone_number, body) == True: # update verified state to "VERIFIED" curr_user.verified = "VERIFIED" db.session.commit() message = verify(phone_number, body) elif curr_user.verified == "EMAIL_SENT" and check_valid_code(phone_number, body) == False: # update verified so new email is sent curr_user.verified = "NONE" db.session.commit() # sends text message asking for UNI again message = error("Sorry the code doesn't match. Please input uni again so we can send a new code") elif str(curr_user.verified) in ["VERIFIED", "AIRPORT_IN", "FLIGHT_TIM", "DATE_INFO", "FINISHED"]: message = verify(phone_number, body) else: # error condition if all else feels message = error("Something unexpected happened, please try later") return message def new_user(phone_number): """ Handles communication with new Skybot users Args: phone_number (str): user's phone number Returns: TwiML: text message to send to user """ # create & insert new user into database new_user = User( phone_number=phone_number, verified="NONE", verification_code=0, uni="NONE", max_passengers=0, flights=[], ) db.session.add(new_user) db.session.commit() # send confirmation message & ask for UNI resp = MessagingResponse() resp.message("Welcome to Skybot! What's your UNI?") return str(resp) def new_flight(current_airport, user_id): """ inserts a new flight into database Args: current_airport (str): user's airport user_id (str): user's id """ # create & insert new user into database new_flight = Flight( airport=current_airport, flight_date=-1, departure_time=-1, passenger_id=user_id, match_id=None, ) db.session.add(new_flight) db.session.commit() def check_uni(body): """ Handles checking if uni is valid or not Args: body (str): user's text message Returns: bool: whether UNI is valid or not """ valid_uni = True # checks letter portion of UNI uni_chars = re.sub("[0-9]", '', body) if len(uni_chars) < 2 or len(uni_chars) > 3: valid_uni = False # checks numbers of UNI uni_int = re.sub("[a-zA-Z]", "", body) if len(uni_int) != 4: valid_uni = False return valid_uni @app.route("/sms", methods=['GET', 'POST']) def sms_reply(): """ Handles text communication with users Returns: TwiML to send to user """ # gets phone number of user pnumber = request.values.get('From', None) # checks db for existing user check_num = db.session.query(User).filter(User.phone_number == pnumber) if db.session.query(check_num.exists()).scalar() is False: out_message = new_user(pnumber) else: body = request.values.get('Body', None) out_message = exist_user(pnumber, body) return str(out_message) def matchFound(cur_user, flight, cur_max): """ Matches users together to take a cab together Args: cur_user (User): current user row flight (Flight): current user's flight row cur_max (int): number of max passengers Returns: match_unis (list): UNIs for each matched user match_nums (list): phone numbers for each matched user """ # If their max passengers is 1, it queries fligths that are 1 # hours within the flight depature that that were not matched. if cur_max == 1: matched_flight = db.session.query(Flight).filter( Flight.flight_date == flight.flight_date, Flight.passenger_id != cur_user.id, Flight.departure_time.between( (flight.departure_time - 100), (flight.departure_time + 100), ), Flight.airport == flight.airport, (Flight.match_id == None), ).first() # getting all flights with the same departure date # If their max passengers is 2, it queries fligths that are 1 # hours within the flight depature that that were not matched if cur_max == 2: matched_flight = db.session.query(Flight).filter( Flight.flight_date == flight.flight_date, Flight.passenger_id != cur_user.id, Flight.departure_time.between( (flight.departure_time-100), (flight.departure_time + 100), ), Flight.airport == flight.airport, (Flight.match_id == None), ).first() # If there were no rides, that fit that criteria then # it queries flights that were matched but have space # that have the same flight depature or up to one hour later if matched_flight == None: available_rides = [] previously_matched_flights = db.session.query(Flight).filter( Flight.flight_date == flight.flight_date, Flight.departure_time.between( (flight.departure_time), (flight.departure_time + 100), ), Flight.airport == flight.airport, (Flight.match_id != None), ) for x in previously_matched_flights: match_instance = db.session.query(Match).filter( Match.id == x.match_id, ).first() if (match_instance.available_seats == 1): matched_flight = x break # If there were no matches, the user's flight is # added to the db and an empty list is returned if matched_flight == None: return [], [] # Otherwise else: # If the user was matched to a flight that was not previously matched if matched_flight.match_id == None: match_airport = flight.airport match_date = flight.flight_date matched_passenger_id = matched_flight.passenger_id # Calculates whether there will be an available seats # based on the preferences of the two users matched_user = db.session.query(User).filter( User.id == matched_passenger_id, ).first() match_availableSeats = ( min(int(cur_max), int(matched_user.max_passengers)) ) - 1 # Finds the rider with the earliest departure time and subtracts two hours match_departTime = (min( int(flight.departure_time), int( matched_flight.departure_time, ), )) - 200 # Creates new match instance and adds to DB new_match = Match( airport=match_airport, ride_date=match_date, ride_departureTime=match_departTime, available_seats=match_availableSeats, riders=[], ) db.session.add(new_match) db.session.commit() # Updates the match ID for the user and matching flight flight.ride = new_match matched_flight.ride = new_match # Creates a list of the riders' UNIs match_unis = [] match_nums = [] for riderss in new_match.riders: match_unis.append(str(riderss.passenger.uni)) match_nums.append(str(riderss.passenger.phone_number)) # At the end of the array, it appends the ride depature time match_unis.append(match_departTime) match_unis.append(match_airport) # returns list of UNIs in ride return match_unis, match_nums # If user was matched to a previously matched flight else: # Updates the users ride to be the matched flight's ride flight.ride = matched_flight.ride # Updates the number of available seats in the match shared_match_id = matched_flight.match_id shared_match = db.session.query(Match).filter( Match.id == shared_match_id, ).first() shared_match.available_seats = (shared_match.available_seats - 1) # Creates a list of the riders' UNIs and phone numbers match_unis = [] match_nums = [] for riderss in shared_match.riders: match_unis.append(str(riderss.passenger.uni)) match_nums.append(str(riderss.passenger.phone_number)) # Query the flights with the match ID earliest_flight = db.session.query(Flight).filter( Match.id == shared_match_id, ).order_by(Flight.departure_time).first() ride_departure = earliest_flight.departure_time - 200 match_unis.append(ride_departure) match_unis.append(flight.airport) # returns list of UNIs in ride return match_unis, match_nums if __name__ == "__main__": app.run(debug=True)
{"/test/test_database.py": ["/database.py"], "/app.py": ["/database.py"], "/database.py": ["/app.py"], "/match.py": ["/app.py"]}
35,174,490
joicodes/Skybot
refs/heads/master
/match.py
import unittest from datetime import datetime import sqlalchemy from sqlalchemy import create_engine from sqlalchemy import exists from sqlalchemy.orm import sessionmaker from app import * ''' engine = create_engine( 'postgres://ehepwtnqjcfntn:04461d661ce43b16602000fb490e32ece1f3558bddac8f4c6059886544f7c7cd@ec2-107-21-125-209.compute-1.amazonaws.com:5432/d6uqqsindhtp99', ) Session = sessionmaker(autoflush=True, autocommit=False, bind=engine) conn = engine.connect() session = Session(bind=conn) ''' def matchFound(cur_user, cur_fltDate, cur_fltTime, cur_airport, cur_maxPass): # Stores the user, their flight time, date, airport, # and prefered max number of additional passengers current_user = cur_user current_fltDate = cur_fltDate current_fltTime = cur_fltTime current_airport = cur_airport current_maxPass = cur_maxPass # If their max passengers is 1, it queries fligths that are 1 # hours within the flight depature that that were not matched. if current_maxPass == 1: matched_flight = db.session.query(Flight).filter( Flight.flight_date == current_fltDate, Flight.departure_time.between( (current_fltTime - 100), (current_fltTime + 100), ), Flight.airport == current_airport, (Flight.match_id == None), ).first() # getting all flights with the same departure date # If their max passengers is 2, it queries fligths that are 1 # hours within the flight depature that that were not matched if current_maxPass == 2: matched_flight = db.session.query(Flight).filter( Flight.flight_date == current_fltDate, Flight.departure_time.between( (current_fltTime-100), (current_fltTime + 100), ), Flight.airport == current_airport, (Flight.match_id == None) ).first() # If there were no rides, that fit that criteria then # it queries flights that were matched but have space # that have the same flight depature or up to one hour later if matched_flight == None: available_rides = [] previously_matched_flights = db.session.query(Flight).filter( Flight.flight_date == current_fltDate, Flight.departure_time.between( (current_fltTime), (current_fltTime + 100), ), Flight.airport == current_airport, (Flight.match_id != None) ) for x in previously_matched_flights: match_instance = db.session.query(Match).filter( Match.id == x.match_id, ).first() if (match_instance.available_seats == 1): matched_flight = x break # If there were no matches, the user's flight is # added to the db and an empty list is returned if matched_flight == None: user_flight_data = Flight( airport=current_airport, flight_date=current_fltDate, departure_time=current_fltTime, passenger_id=current_user.id, match_id=None, ) db.session.add(user_flight_data) db.session.commit() return [] # Otherwise else: # First user flight data is added to DB user_flight_data = Flight( airport=current_airport, flight_date=current_fltDate, departure_time=current_fltTime, passenger_id=current_user.id, match_id=None, ) db.session.add(user_flight_data) db.session.commit() # If the user was matched to a flight that was not previously matched if matched_flight.match_id == None: match_airport = current_airport match_date = current_fltDate matched_passenger_id = matched_flight.passenger_id # Calculates whether there will be an available seats # based on the preferences of the two users matched_user = db.session.query(User).filter( User.id == matched_passenger_id, ).first() match_availableSeats = ( min(int(current_maxPass), int(matched_user.max_passengers)) ) - 1 # Finds the rider with the earliest departure time and subtracts two hours match_departTime = (min( int(current_fltTime), int( matched_flight.departure_time, ), )) - 200 # Creates new match instance and adds to DB new_match = Match( airport=match_airport, ride_date=match_date, ride_departureTime=match_departTime, available_seats=match_availableSeats, riders=[], ) db.session.add(new_match) db.session.commit() # Updates the match ID for the user and matching flight user_flight_data.ride = new_match matched_flight.ride = new_match # Creates a list of the riders' UNIs match_list = [] for riderss in new_match.riders: match_list.append(str(riderss.passenger.uni)) # At the end of the array, it appends the ride depature time match_list.append(match_departTime) match_list.append(match_airport) # returns list of UNIs in ride return match_list # If user was matched to a previously matched flight else: # Updates the users ride to be the matched flight's ride user_flight_data.ride = matched_flight.ride # Updates the number of available seats in the match shared_match_id = matched_flight.match_id shared_match = db.session.query(Match).filter( Match.id == shared_match_id, ).first() shared_match.available_seats = (shared_match.available_seats - 1) # Creates a list of the riders' UNIs match_list = [] for riderss in shared_match.riders: match_list.append(str(riderss.passenger.uni)) # Query the flights with the match ID earliest_flight = db.session.query(Flight).filter( Match.id == shared_match_id, ).order_by(Flight.departure_time).first() ride_departure = earliest_flight.departure_time - 200 match_list.append(ride_departure) match_list.append(user_flight_data.airport) # returns list of UNIs in ride return match_list # Notes for app.py: # What is returned: # Either an empty list, meaning that the User was not matched to anyone # OR, an array with the list of UNIs in the match, their depature time, and the airport # For ride cost calculations, find the length of the array minus 2 # (which accounts for the 2 spaces in the array taken by the departure time and airport)
{"/test/test_database.py": ["/database.py"], "/app.py": ["/database.py"], "/database.py": ["/app.py"], "/match.py": ["/app.py"]}
35,241,380
Aryan-Naveen/dronePoseEstimation
refs/heads/master
/visualize.py
import matplotlib.pyplot as plt import numpy as np fusion_techniques = ["bayesian", "ellipsoidal", "covariance intersection", "inverse covariance intersection", "probablistic consistent"] def visualize(error, time, covariances, technique): home_dir_png = "results/images/" home_dir_pdf = "results/" directions = ["x", "y", "z"] for i in range(3): fig = plt.figure() plt.plot(time, error[i], color='blue', linewidth=0.5) plt.plot(time, covariances[i], color='red', linewidth=0.5) plt.plot(time, -1*covariances[i], color='red', linewidth=0.5) plt.xlabel("Time (s)") plt.ylabel("Positional Error "+ directions[i] +" (meters)") fig.set_figwidth(14) fig.tight_layout() plt.savefig(home_dir_png + technique +"_error("+ directions[i] +").png") plt.savefig(home_dir_pdf + technique +"_error("+ directions[i] +").pdf") plt.show() if __name__ == '__main__': plt.cla() plt.clf() ax = plt.axes() for tech in fusion_techniques: errors = np.genfromtxt("results/errorCsv/"+tech+".csv",delimiter=',') mse = np.sum(np.square(errors), axis = 0) x = [ i for i in range(mse.size)] print(tech, np.average(mse)) ax.plot(x, mse, label=tech) ax.legend() plt.show()
{"/computations.py": ["/utils.py"], "/main.py": ["/data_input.py", "/computations.py", "/visualize.py"]}
35,241,381
Aryan-Naveen/dronePoseEstimation
refs/heads/master
/main.py
from data_input import DataLoader from data_structure import Data from computations import * import numpy as np from tqdm import tqdm import matplotlib.pyplot as plt from visualize import visualize from data_fusion import Data_fusion def pinv(H, y): return np.linalg.inv(H.T @ H) @ H.T @ y fusion_techniques = ["bayesian", "ellipsoidal", "covariance intersection", "inverse covariance intersection", "probablistic consistent"] if __name__ == '__main__': loader = DataLoader('data/data.csv') technique = int(input("Which fusion technique to use? (0 - bayesian, 1 - ei, 2 - ci, 3 - ici, 4 - pc)")) fusion = Data_fusion(technique) estimations = np.zeros((6, loader.get_number_time_stamps())) for t in tqdm(range(loader.get_number_time_stamps())): data = loader.get_next_timestep() info_mat, info_vec = getInitialInformationMatrix(data) while not data.completed(): info_mat, info_vec = add_satellite(data, info_mat, info_vec, fusion) pred = ((inv(info_mat) @ info_vec)/ data.getDeltaTime())[:3].reshape(3,) # pred = ((inv(info_mat) @ info_vec))[:3].reshape(3,) # print(pred) # print((inv(info_mat) @ info_vec)) # print(data.getDeltaTime()) covs = np.sqrt(np.diag(inv(info_mat)))[:3].reshape(3,) estimations[:3,t] = pred estimations[3:,t] = covs truth = loader.get_truth("truth.csv") error = estimations[:3] - truth[:3] P_inv = info_mat[:3, :3] print("ANEES:",np.average(error.T @ P_inv @ error)) time = truth[3] covariances = estimations[3:] visualize(error, time, covariances, fusion_techniques[technique]) np.savetxt("results/errorCsv/"+str(fusion_techniques[technique])+".csv", error, delimiter=",") np.savetxt("results/errorCsv/"+str(fusion_techniques[technique])+"_std_dev.csv", covariances, delimiter=",")
{"/computations.py": ["/utils.py"], "/main.py": ["/data_input.py", "/computations.py", "/visualize.py"]}
35,249,239
rikardg/whathappened
refs/heads/master
/app/character/tftl/mechanics.py
import os from ..core import CharacterMechanics from ..schema import validate CHARACTER_SCHEMA = os.path.join( os.path.dirname(__file__), '../schema/tftl.json') class TftlMechanics(CharacterMechanics): def validate(self): return validate(self.parent.body, CHARACTER_SCHEMA) def version(self): return '0.0.1' @property def name(self): return self.parent.body['personalia']['name'] @property def age(self): return self.parent.body['personalia']['age'] @property def description(self): return self.parent.body['personalia']['type'] def portrait(self): return self.parent.body['personalia'].get('portrait', None) def skill(self, *args, **kwargs): return "Nope" def relationships(self, who: str): return self.parent.body['relationships'][who] def items(self): return self.parent.body['items'] def set_portrait(self, data): self.parent.body['personalia']['portrait'] = data return self.portrait
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,240
rikardg/whathappened
refs/heads/master
/app/auth/models.py
import logging from time import time import jwt from flask_login import UserMixin from flask import current_app from sqlalchemy.orm import relationship from sqlalchemy.sql.schema import Column, ForeignKey from sqlalchemy.sql.sqltypes import Integer, String from werkzeug.security import check_password_hash, generate_password_hash from app.database import Base, session logger = logging.getLogger(__name__) class User(UserMixin, Base): __tablename__ = "user_account" id = Column(Integer, primary_key=True) username = Column(String(64), index=True, unique=True) email = Column(String(128), index=True, unique=True) password_hash = Column(String(128)) profile = relationship('UserProfile', uselist=False, back_populates="user") roles = relationship('Role', secondary='user_roles') def __repr__(self): return '<User {}>'.format(self.username) def set_password(self, password: str): self.password_hash = generate_password_hash(password) def check_password(self, password: str): return check_password_hash(self.password_hash, password) def get_reset_password_token(self, expires_in: int = 600): return jwt.encode( {'reset_password': self.id, 'exp': time() + expires_in}, current_app.config['SECRET_KEY'], algorithm='HS256') \ .decode('utf-8') @staticmethod def verify_reset_password_token(token: str): try: id = jwt.decode(token, current_app.config['SECRET_KEY'], algorithms=['HS256'])['reset_password'] except Exception: logger.error("Exception occurent while trying to reset password.", exc_info=True) return return User.query.get(id) def has_role(self, role: str): for r in self.roles: if r.name == role: return True return False class Role(Base): __tablename__ = 'roles' id = Column(Integer(), primary_key=True) name = Column(String(50), unique=True) class UserRoles(Base): __tablename__ = 'user_roles' id = Column(Integer(), primary_key=True) user_id = Column(Integer(), ForeignKey('user_account.id', ondelete='CASCADE')) role_id = Column(Integer(), ForeignKey('roles.id', ondelete='CASCADE')) def create_core_roles(*args, **kwargs): session.add(Role(name='admin')) session.commit() # This does not work after converting, but since the roles # have not actually been in use, and are not created on # other instances either, this should be looked over. # TODO # listen(Role.__table__, 'after_create', create_core_roles) def add_first_admin(*args, **kwargs): session.add(UserRoles(user_id=1, role_id=1)) session.commit() # See above comment. # listen(UserRoles.__table__, 'after_create', add_first_admin)
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,241
rikardg/whathappened
refs/heads/master
/app/character/__init__.py
from flask import Blueprint from flask_assets import Environment bp = Blueprint('character', __name__, template_folder="templates", static_folder="static") api = Blueprint('characterapi', __name__, template_folder="templates") from . import routes # noqa: E402, F401 isort:skip @bp.app_template_filter('datetimeformat') def datetimeformat(value, format: str = "%Y-%m-%d %H:%M:%S"): return value.strftime(format) def register_assets(assets: Environment): assets.register('scss_character', 'character/scss/character.scss', filters='pyscss', output='css/character.css') assets.register('scss_character_coc7e', 'character/scss/character_coc7e.scss', filters='pyscss', output='css/character_coc7e.css') assets.register('scss_character_tftl', 'character/scss/character_tftl.scss', filters='pyscss', output='css/character_tftl.css')
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,242
rikardg/whathappened
refs/heads/master
/app/profile.py
from app.content.models import Folder import logging from flask import ( Blueprint, render_template ) from flask_login import login_required, current_user from app.database import session bp = Blueprint('profile', __name__, template_folder='templates') # from app.character.models import Character # noqa F401 from .models import UserProfile # noqa F401 logger = logging.getLogger(__name__) @bp.route('/') @login_required def index(): user_profile = UserProfile.query.get(current_user.id) if user_profile is None: user_profile = UserProfile(user_id=current_user.id) session.add(user_profile) session.commit() logger.info(f"Showing profile {user_profile.id}") characters = user_profile.characters folders = user_profile.folders # .filter(Folder.parent_id.__eq__(None)) return render_template('profile/profile.html.jinja', profile=user_profile, characters=characters, folders=folders)
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,243
rikardg/whathappened
refs/heads/master
/migrations/versions/f047bb8f937f_add_handout_status.py
"""Add handout status Revision ID: f047bb8f937f Revises: fae26f355099 Create Date: 2020-10-11 09:18:37.215880 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = 'f047bb8f937f' down_revision = 'fae26f355099' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('campaign_handout', sa.Column('status', sa.Enum('draft', 'deleted', 'hidden', 'visible', name='handoutstatus'), nullable=True)) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_column('campaign_handout', 'status') # ### end Alembic commands ###
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,244
rikardg/whathappened
refs/heads/master
/app/campaign/views.py
from typing import Text, Union from flask import render_template, request, redirect, url_for from flask_login import current_user from flask.views import View from flask_login.utils import login_required from werkzeug.exceptions import abort from werkzeug.wrappers import Response import logging import markdown2 from . import bp from .models import Campaign, Handout, HandoutGroup from .forms import HandoutForm, DeleteHandoutForm, HandoutGroupForm from app.userassets.forms import AssetSelectForm from app.database import session logger = logging.getLogger(__name__) @bp.app_template_filter('markdown') def markdown(value: str): return markdown2.markdown(value, extras=["tables", "fenced-code-blocks"]) class HandoutView(View): def dispatch_request(self, campaign_id: int, handout_id: int = None) -> Union[Text, Response]: logger.debug(f"dispatch_request({campaign_id}, {handout_id})") if request.method == 'GET' and handout_id is None: return self.list_view(campaign_id) if request.method == 'POST' and handout_id is None: return self.create(campaign_id) if request.method == 'POST': if handout_id is not None: return self.update(campaign_id, handout_id) return self.view(campaign_id, handout_id) def create(self, campaign_id: int): logger.debug("Posting handout") handoutform = HandoutForm(prefix="handout") groupform = HandoutGroupForm(prefix="group") if handoutform.submit.data and handoutform.validate_on_submit(): logger.debug("Store handout") handout = Handout() handoutform.populate_obj(handout) if not handout.group_id: handout.group_id = None session.add(handout) session.commit() elif groupform.submit.data and groupform.validate_on_submit(): logger.debug("Create handout group") group = HandoutGroup() groupform.populate_obj(group) session.add(group) session.commit() else: logger.debug("Form did not validate") for error, message in handoutform.errors.items(): logger.debug(f"Field: {error}, " f"value: {handoutform[error].data}, " f"errors: {', '.join(message)}") return redirect(url_for('campaign.handout_view', campaign_id=campaign_id)) def update(self, campaign_id: int, handout_id: int): logger.debug("Put to handout") handout = Handout.query.get(handout_id) form = HandoutForm(prefix="handout") form.group_id.choices = [('', '(none)'), ] \ + [(g.id, g.name) for g in handout.campaign.handout_groups] if form.submit.data and form.validate_on_submit(): logger.debug("Form is valid") form.populate_obj(handout) if not handout.group_id: handout.group_id = None session.commit() else: logger.debug("Form did not validate") for error, message in form.errors.items(): logger.debug(f"Field: {error}, " f"value: {form[error].data}, " f"errors: {', '.join(message)}") return redirect(url_for('campaign.handout_view', campaign_id=campaign_id, handout_id=handout.id)) def view(self, campaign_id: int, handout_id: int = None) -> Text: logger.debug(f"view({campaign_id}, {handout_id})") handout: Handout = Handout.query.get(handout_id) if not handout: abort(404) if current_user.is_authenticated \ and current_user.profile not in handout.players \ and current_user.profile != handout.campaign.user: abort(403) editable = False if current_user.is_authenticated \ and current_user.profile.id == handout.campaign.user_id: editable = True if not editable: return render_template('campaign/handout_view.html.jinja', handout=handout) logger.debug(handout.title) logger.debug(handout.status) form = HandoutForm(obj=handout, prefix="handout") form.group_id.choices = [('', '(none)'), ] \ + [(g.id, g.name) for g in handout.campaign.handout_groups] assetsform = AssetSelectForm(prefix="assetselect") return render_template('campaign/handout.html.jinja', handout=handout, form=form, assetsform=assetsform, editable=editable) @login_required def list_view(self, campaign_id: int) -> Text: campaign = Campaign.query.get(campaign_id) is_owner = current_user and current_user.profile.id == campaign.user_id handouts = campaign.handouts.filter(~Handout.group.has()) \ .filter(is_owner or Handout.players.contains(current_user.profile)) groups = {group.name: list(group.handouts.filter( is_owner or Handout.players.contains(current_user.profile))) for group in campaign.handout_groups} handoutform = HandoutForm(prefix="handout") handoutform.campaign_id.data = campaign.id groupform = HandoutGroupForm(prefix="group") groupform.campaign_id.data = campaign.id return render_template('campaign/handouts.html.jinja', editable=is_owner, campaign=campaign, groups=groups, handouts=handouts, handoutform=handoutform, groupform=groupform) handout_view = HandoutView.as_view('handout_view') bp.add_url_rule('/<int:campaign_id>/handouts/', defaults={'handout_id': None}, view_func=handout_view, methods=['GET', ]) bp.add_url_rule('/<int:campaign_id>/handouts/', view_func=handout_view, methods=['POST', ]) bp.add_url_rule('/<int:campaign_id>/handouts/<int:handout_id>/', view_func=handout_view, methods=['GET', 'PUT', 'DELETE', 'POST']) @bp.route('/<int:campaign_id>/handouts/<int:handout_id>/delete', methods=('GET', 'POST')) def handout_delete(campaign_id: int, handout_id: int): """Delete a handout.""" handout = Handout.query.get(handout_id) if current_user.profile.id != handout.campaign.user_id: abort(404) form = DeleteHandoutForm() if form.validate_on_submit(): session.delete(handout) session.commit() return redirect(url_for('campaign.handout_view', campaign_id=handout.campaign.id)) form.campaign_id.data = handout.campaign.id form.id.data = handout.id return render_template('campaign/delete_handout.html.jinja', form=form, handout=handout)
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,245
rikardg/whathappened
refs/heads/master
/config.py
"""App default config.""" import os from dotenv import load_dotenv BASEDIR = os.path.abspath(os.path.dirname(__file__)) load_dotenv(os.path.join(BASEDIR, '.env')) class Config(): """Settings to be overridden with env variables.""" SECRET_KEY = os.environ.get('SECRET_KEY') or 'development' SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ 'sqlite:///' + os.path.join(BASEDIR, 'instance', 'whathappened.sqlite') SQLALCHEMY_TRACK_MODIFICATIONS = False MAIL_SERVER = os.environ.get('MAIL_SERVER') or "localhost" MAIL_PORT = int(os.environ.get('MAIL_PORT') or 8025) ADMINS = [os.environ.get('ADMIN_EMAIL') or 'your-email@example.com'] ASSETS_DEBUG = False ASSETS_AUTO_BUILD = False if os.environ.get('FLASK_ENV') != 'development' \ else True MAX_CONTENT_LENGTH = 1024 * 1024 # Max upload size UPLOAD_EXTENSIONS = ['.jpg', '.png', '.jpeg', '.gif'] UPLOAD_PATH = 'uploads' WTF_CSRF_TIME_LIMIT = None WEBPACKEXT_MANIFEST_PATH = 'manifest.json'
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,246
rikardg/whathappened
refs/heads/master
/app/character/forms.py
import logging from flask_wtf import FlaskForm from wtforms import StringField, BooleanField, HiddenField from wtforms import ValidationError, SubmitField from wtforms.fields.core import Field from wtforms.validators import DataRequired import json from app.forms.fields import JsonField logger = logging.getLogger(__name__) class JsonString(object): def __init__(self, message: str = None): if not message: message = u'Field must be a valid JSON string' self.message = message def __call__(self, form: FlaskForm, field: Field): try: _ = json.loads(field.data) except Exception: logger.error("Could not verify JSON data", exc_info=True) raise ValidationError(self.message) class ImportForm(FlaskForm): title = StringField('Title', validators=[DataRequired()]) body = JsonField('Body', validators=[DataRequired()]) conversion = BooleanField('Convert') migration = BooleanField('Migrate') submit = SubmitField('Import') class CreateForm(FlaskForm): title = StringField('Title', validators=[DataRequired()]) system = HiddenField('System', validators=[DataRequired()]) submit = SubmitField('Create') class SkillForm(FlaskForm): name = StringField('Name', validators=[DataRequired()]) # value = IntegerField('Value', validators=[DataRequired()]) submit = SubmitField('Add') class SubskillForm(FlaskForm): name = StringField('Name', validators=[DataRequired()]) parent = HiddenField('Parent', validators=[DataRequired()]) submit = SubmitField('Add') class DeleteForm(FlaskForm): character_id = HiddenField('CharacterId', validators=[DataRequired()]) submit = SubmitField('Delete')
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,247
rikardg/whathappened
refs/heads/master
/app/campaign/__init__.py
from flask import Blueprint from flask_assets import Environment bp = Blueprint('campaign', __name__, template_folder='templates', static_folder='static') apibp = Blueprint('campaignapi', __name__, template_folder='templates') from . import routes # noqa: F401,E402 isort:skip from . import views # noqa: F401, E402 isort:skip from . import api # noqa: F401, E402 isort:skip from .models import Campaign # noqa: F401, E402 isort:skip def register_assets(assets: Environment): assets.register('scss_campaign', 'campaign/scss/campaign.scss', filters='pyscss', output='css/campaign.css') assets.register('scss_handout', 'campaign/scss/handout.scss', filters='pyscss', output='css/handout.css')
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,248
rikardg/whathappened
refs/heads/master
/app/character/coc7e/utils.py
import math from .. import bp @bp.app_template_filter('half') def half(value): if not value: return 0 if type(value) == str: try: value = int(value, 10) except ValueError: return 0 return math.floor(value / 2) @bp.app_template_filter('fifth') def fifth(value): if not value: return 0 if type(value) == str: try: value = int(value, 10) except ValueError: return 0 return math.floor(value / 5)
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,249
rikardg/whathappened
refs/heads/master
/app/userassets/models.py
import os import uuid import logging from flask import url_for, current_app from sqlalchemy import event from sqlalchemy.orm import backref, relationship from sqlalchemy.sql.schema import Column, ForeignKey from sqlalchemy.sql.sqltypes import Integer, String from app.database import Base from app.models import GUID from werkzeug.utils import secure_filename logger = logging.getLogger(__name__) class Asset(Base): ASSET_ORDER = '[Asset.folder_id, Asset.filename]' __tablename__ = "asset" id = Column(GUID(), primary_key=True, default=uuid.uuid4) filename = Column(String(128)) owner_id = Column(Integer, ForeignKey('user_profile.id')) owner = relationship('UserProfile', backref=backref('assets', lazy='dynamic', order_by=ASSET_ORDER)) folder_id = Column(GUID(), ForeignKey('asset_folder.id')) folder = relationship('AssetFolder', back_populates='files') def __init__(self, *args, **kwargs): super(Asset, self).__init__(*args, **kwargs) self.loaded = False self.data = None @property def path(self): return os.path.join(self.folder.get_path(), self.filename) @property def url(self): return url_for('userassets.view', fileid=self.id, filename=self.filename) @property def system_path(self): return os.path.join(self.folder.system_path, secure_filename(self.filename)) @event.listens_for(Asset, 'before_delete') def before_asset_delete(mapper, connection, target): logger.debug("Asset is being deleted") logger.debug(target.filename) system_folder = current_app.config['UPLOAD_PATH'] filepath = target.folder.get_path() assetname = secure_filename(target.filename) logger.debug(f"Deleting file from {filepath}, {assetname}") full_dir = os.path.join(system_folder, filepath) full_file_path = os.path.join(full_dir, assetname) if os.path.isfile(full_file_path): logger.debug("Delete the actual file") os.unlink(full_file_path) class AssetFolder(Base): __tablename__ = 'asset_folder' id = Column(GUID(), primary_key=True, default=uuid.uuid4) owner_id = Column(Integer, ForeignKey('user_profile.id')) owner = relationship("UserProfile", backref=backref('assetfolders', lazy='dynamic')) parent_id = Column(GUID(), ForeignKey('asset_folder.id'), default=None) subfolders = relationship('AssetFolder', backref=backref('parent', remote_side=[id])) title = Column(String(128)) files = relationship("Asset", back_populates='folder') def get_path(self): if self.parent: parent = self.parent.get_path() return os.path.join(parent, secure_filename(self.title)) else: return os.path.join(str(self.id), secure_filename(self.title)) @property def path(self): if self.parent: parent = self.parent.path return os.path.join(parent, self.title) else: return self.title @property def system_path(self): return os.path.join(current_app.config['UPLOAD_PATH'], self.get_path())
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,250
rikardg/whathappened
refs/heads/master
/app/content/forms.py
from flask_login import current_user from wtforms.fields.simple import HiddenField, SubmitField from flask_wtf.form import FlaskForm from wtforms.fields.core import StringField from wtforms.validators import DataRequired, UUID, Optional from app.forms.fields.alchemy import QuerySelectField class NewFolderForm(FlaskForm): title = StringField('Title', validators=[DataRequired()]) owner_id = HiddenField(validators=[DataRequired()]) # parent_id = QuerySelectField('Parent') parent_id = HiddenField( validators=[Optional(), UUID()], default=None, filters=[lambda x: x or None]) add = SubmitField('Add') def available_folders(): return current_user.profile.folders class ChooseFolderForm(FlaskForm): folder_id = QuerySelectField( query_factory=available_folders, get_label=lambda x: x.title, allow_blank=True) choose = SubmitField('Choose')
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,251
rikardg/whathappened
refs/heads/master
/migrations/versions/a425da83bea3_add_messages_to_campaign.py
"""Add messages to campaign Revision ID: a425da83bea3 Revises: 27799ac97853 Create Date: 2021-01-31 16:20:15.256849 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = 'a425da83bea3' down_revision = '27799ac97853' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('campaign_message', sa.Column('id', sa.Integer(), nullable=False), sa.Column('campaign_id', sa.Integer(), nullable=False), sa.Column('to_id', sa.Integer(), nullable=True), sa.Column('from_id', sa.Integer(), nullable=False), sa.Column('message', sa.Text(), nullable=True), sa.Column('timestamp', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['campaign_id'], ['campaign.id'], name=op.f('fk_campaign_message_campaign_id_campaign')), sa.ForeignKeyConstraint(['from_id'], ['user_profile.id'], name=op.f('fk_campaign_message_from_id_user_profile')), sa.ForeignKeyConstraint(['to_id'], ['user_profile.id'], name=op.f('fk_campaign_message_to_id_user_profile')), sa.PrimaryKeyConstraint('id', name=op.f('pk_campaign_message')) ) with op.batch_alter_table('campaign_message', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_campaign_message_timestamp'), ['timestamp'], unique=False) with op.batch_alter_table('campaign', schema=None) as batch_op: batch_op.add_column(sa.Column('messages_enabled', sa.Boolean(), nullable=True)) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('campaign', schema=None) as batch_op: batch_op.drop_column('messages_enabled') with op.batch_alter_table('campaign_message', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_campaign_message_timestamp')) op.drop_table('campaign_message') # ### end Alembic commands ###
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,252
rikardg/whathappened
refs/heads/master
/app/campaign/models.py
import enum from flask import url_for from datetime import datetime from sqlalchemy.orm import backref, relationship from sqlalchemy.sql.schema import ForeignKey, Table, Column from sqlalchemy.sql.sqltypes import Boolean, DateTime from sqlalchemy.sql.sqltypes import Enum, Integer, String, Text from app.database import Base from app.content.mixins import BaseContent campaign_players = Table('campaign_players', Base.metadata, Column('player_id', Integer, ForeignKey('user_profile.id'), primary_key=True), Column('campaign_id', Integer, ForeignKey('campaign.id'), primary_key=True)) campaign_characters = Table('campaign_characters', Base.metadata, Column('character_id', Integer, ForeignKey('charactersheet.id'), primary_key=True), Column('campaign_id', Integer, ForeignKey('campaign.id'), primary_key=True)) class Campaign(Base, BaseContent): __tablename__ = "campaign" id = Column(Integer, primary_key=True) title = Column(String(256)) description = Column(Text) # Owner of the campaign (GM) user_id = Column(Integer, ForeignKey('user_profile.id')) user = relationship('UserProfile', backref=backref( 'campaigns', lazy='dynamic')) # The players in a campaign players = relationship('UserProfile', secondary=campaign_players, lazy='dynamic', backref=backref('campaigns_as_player', lazy=True)) # Characters added to the campaign characters = relationship('Character', secondary=campaign_characters, lazy='dynamic', backref=backref('campaigns', lazy=True)) # NPCs added to campaign NPCs = relationship( "NPC", back_populates='campaign', lazy='dynamic') # Handouts added to campaign handouts = relationship("Handout", back_populates='campaign', lazy='dynamic') # Handout groups for the campaign handout_groups = relationship("HandoutGroup", back_populates='campaign', lazy='dynamic') # Features used for campaign characters_enabled = Column(Boolean, default=True) npcs_enabled = Column(Boolean, default=False) handouts_enabled = Column(Boolean, default=False) messages_enabled = Column(Boolean, default=False) folder = relationship('Folder', backref='campaigns') @property def players_by_id(self): return dict((player.id, player) for player in self.players) def __repr__(self): return '<Campaign {}>'.format(self.title) player_handouts = Table('campaign_handouts_to_players', Base.metadata, Column('handout_id', Integer, ForeignKey('campaign_handout.id'), primary_key=True), Column('player_id', Integer, ForeignKey('user_profile.id'), primary_key=True)) class HandoutStatus(enum.Enum): draft = "Draft" deleted = "Deleted" hidden = "Hidden" visible = "Visible" class HandoutGroup(Base): __tablename__ = 'campaign_handout_group' id = Column(Integer, primary_key=True) name = Column(String(256)) campaign_id = Column(Integer, ForeignKey('campaign.id')) campaign = relationship("Campaign", back_populates='handout_groups') handouts = relationship('Handout', lazy='dynamic', back_populates='group') def __repr__(self): return f'<Handout Group {self.name}>' class Handout(Base): __tablename__ = 'campaign_handout' id = Column(Integer, primary_key=True) title = Column(String(256)) content = Column(Text) campaign_id = Column(Integer, ForeignKey('campaign.id')) campaign = relationship("Campaign", back_populates='handouts') status = Column('status', Enum(HandoutStatus), default=HandoutStatus.draft) players = relationship('UserProfile', secondary=player_handouts, lazy='dynamic', backref=backref('campaign_handouts', lazy=True)) group_id = Column(Integer, ForeignKey('campaign_handout_group.id')) group = relationship('HandoutGroup') def __repr__(self): return '<Handout {}>'.format(self.title) def to_dict(self): return { 'id': self.id, 'title': self.title, 'url': url_for('campaign.handout_view', campaign_id=self.campaign.id, handout_id=self.id) } class NPC(Base): __tablename__ = 'campaign_npc' id = Column(Integer, primary_key=True) campaign_id = Column(Integer, ForeignKey('campaign.id'), nullable=False) campaign = relationship('Campaign', back_populates='NPCs') character_id = Column(Integer, ForeignKey('charactersheet.id'), nullable=False) character = relationship('Character') visible = Column(Boolean, default=False) class Message(Base): __tablename__ = 'campaign_message' id = Column(Integer, primary_key=True) campaign_id = Column(Integer, ForeignKey('campaign.id'), nullable=False) campaign = relationship('Campaign', backref=backref('messages', lazy='dynamic')) to_id = Column(Integer, ForeignKey('user_profile.id'), nullable=True) to = relationship('UserProfile', foreign_keys=[to_id]) from_id = Column(Integer, ForeignKey('user_profile.id'), nullable=False) sender = relationship('UserProfile', foreign_keys=[from_id]) message = Column(Text) timestamp = Column(DateTime, index=True, default=datetime.utcnow) def to_dict(self): return { 'timestamp': self.timestamp.timestamp(), 'sender_name': self.sender_name, 'to_name': self.to_name, 'message': self.message, 'id': self.id } @property def sender_name(self): return self.sender.user.username @property def to_name(self): return self.to.user.username if self.to and self.to.user else "All"
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,253
rikardg/whathappened
refs/heads/master
/migrations/versions/186d10393f49_add_campaign_settings.py
"""Add campaign settings Revision ID: 186d10393f49 Revises: 8b29c4eb9589 Create Date: 2021-01-05 21:05:19.783990 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '186d10393f49' down_revision = '8b29c4eb9589' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('campaign', schema=None) as batch_op: batch_op.add_column(sa.Column('characters_enabled', sa.Boolean(), nullable=True)) batch_op.add_column(sa.Column('handouts_enabled', sa.Boolean(), nullable=True)) batch_op.add_column(sa.Column('npcs_enabled', sa.Boolean(), nullable=True)) op.execute("UPDATE campaign SET characters_enabled = true") op.execute("UPDATE campaign SET handouts_enabled = true") op.execute("UPDATE campaign SET npcs_enabled = true") # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('campaign', schema=None) as batch_op: batch_op.drop_column('npcs_enabled') batch_op.drop_column('handouts_enabled') batch_op.drop_column('characters_enabled') # ### end Alembic commands ###
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,254
rikardg/whathappened
refs/heads/master
/app/utils/schema.py
import copy from typing import Union from packaging.version import Version, LegacyVersion, parse SheetVersion = Union[Version, LegacyVersion] def up_or_down(from_version: SheetVersion, to_version: SheetVersion) -> int: if from_version > to_version: return -1 if to_version > from_version: return 1 return 0 def find_migration(version: SheetVersion, direction: int, migrations): for m in migrations: if direction > 0 and parse(m['from']) == version: return m if direction < 0 and parse(m['to']) == version: return m def find_version(data) -> str: version_string = None try: version_string = data['version'] return version_string except KeyError: pass try: version_string = data['meta']['Version'] return version_string except KeyError: pass return "0.0.0" def migrate(data, to_version, migrations=None): data = copy.deepcopy(data) from_version = parse(find_version(data)) direction = up_or_down(from_version, parse(to_version)) if direction == 0: return data migrator = find_migration(from_version, direction, migrations) if migrator is None: raise Exception("Migrator not found") if direction < 0: data = migrator['down'](data) if direction > 0: data = migrator['up'](data) return migrate(data, to_version=to_version, migrations=migrations)
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,255
rikardg/whathappened
refs/heads/master
/app/character/coc7e/forms.py
from wtforms import SelectField from ..forms import CreateForm from . import GameTypes class CreateForm(CreateForm): gametype = SelectField('Type', choices=GameTypes, )
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,256
rikardg/whathappened
refs/heads/master
/tests/coc7e/test_coc7e.py
"""Test functions specific to Call of Cthulhu.""" import os import json import pytest from app.auth.models import User # noqa from app.campaign.models import Campaign # noqa from app.character.coc7e import CoCMechanics from app.character.coc7e import new_character from app.character.coc7e import CHARACTER_SCHEMA from app.character.schema import validate from app.character.models import Character from app.character.coc7e.convert import fifth, half, convert_from_dholes from app.utils.schema import migrate from app.character.schema.coc7e import migrations, latest BASEDIR = os.path.abspath(os.path.dirname(__file__)) def test_fifth(): assert fifth("50") == 10 assert fifth(50) == 10 def test_half(): assert half("20") == 10 assert half(20) == 10 @pytest.fixture(name='dholes_sheet') def fixture_dholes_sheet() -> dict: """Load character sheet from JSON and convert to dict.""" sheet = None filename = os.path.join(BASEDIR, 'testchar_dholes.json') with open(filename, 'r') as input_file: sheet = json.load(input_file) return sheet @pytest.fixture(name='test_sheet') def fixture_test_sheet() -> dict: """Load character sheet from JSON and convert to dict.""" sheet = None with open(os.path.join(BASEDIR, 'testchar.json'), 'r') as input_file: sheet = json.load(input_file) return sheet @pytest.fixture(name="newly_created_character") def fixture_test_character() -> Character: nc = new_character("Test Character", "Classic (1920's)") c = Character(title="Test Character", body=nc, mechanics=CoCMechanics) return c def test_validate(test_sheet: dict): nc = new_character("Test Character", "Classic (1920's)") errors = validate(nc, CHARACTER_SCHEMA) assert len(errors) == 0 def test_convert_from_dholes(dholes_sheet: dict): """Test conversion from a character sheet generated at dholes house.""" assert dholes_sheet is not None converted = convert_from_dholes(dholes_sheet) errors = validate(converted, CHARACTER_SCHEMA) error_messages = errors assert len(errors) == 0, error_messages def test_personalia_and_attributes(newly_created_character: Character): assert newly_created_character.name == "Unknown" assert newly_created_character.age == "18" assert newly_created_character.description == "Unknown" assert newly_created_character.system == 'coc7e' assert newly_created_character.game[0] == "Call of Cthulhu TM" assert newly_created_character.game[1] == "Classic (1920's)" def test_skills(newly_created_character: Character): skill = newly_created_character.skill('Spot Hidden') assert skill is not None assert skill['value'] == 25 def test_skill(newly_created_character: Character): skill_name = "test skill" skill = newly_created_character.skill(skill_name) assert skill is None newly_created_character.add_skill(skillname=skill_name, value=13) skill = newly_created_character.skill(skill_name) assert skill is not None assert skill['value'] == 13 with pytest.raises(ValueError): newly_created_character.add_skill(skillname=skill_name, value=154) newly_created_character.set_attribute({'category': 'skill', 'field': skill_name, 'value': 21}) skill = newly_created_character.skill(skill_name) assert skill is not None assert skill['value'] == 21 def test_subskill(newly_created_character: Character): skill_name = "Science" subskill_name = "Biology" skill = newly_created_character.skill(skill_name) newly_created_character.add_subskill(subskill_name, skill_name) subskill = newly_created_character.skill(skill_name, subskill_name) assert subskill is not None assert subskill['value'] == skill['value'] with pytest.raises(ValueError): newly_created_character.add_subskill(subskill_name, skill_name) newly_created_character.set_attribute({'category': 'skill', 'field': skill_name, 'subfield': subskill_name, 'value': 21}) subskill = newly_created_character.skill(skill_name, subskill_name) assert subskill is not None assert subskill['value'] == 21 def test_validate_migration_up(test_sheet: dict): errors = validate(migrate(test_sheet, "0.0.4", migrations=migrations), CHARACTER_SCHEMA) assert len(errors) == 0, errors def test_validate_migration_latest(test_sheet: dict): errors = validate(migrate(test_sheet, latest, migrations=migrations), CHARACTER_SCHEMA) assert len(errors) == 0, errors def test_validate_migration_up_and_down(test_sheet: dict): migrated = migrate(test_sheet.copy(), "0.0.4", migrations=migrations) back_down = migrate(migrated, "0.0.1", migrations=migrations) assert test_sheet == back_down
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,257
rikardg/whathappened
refs/heads/master
/app/userassets/forms.py
from flask_login import current_user from flask import url_for from flask_wtf import FlaskForm from flask_wtf.file import FileField, FileRequired, FileAllowed from wtforms import SubmitField from wtforms.fields.core import StringField from wtforms.fields.simple import HiddenField from wtforms.validators import DataRequired from app.forms.fields import QuerySelectField from .models import Asset def available_folders(): return current_user.profile.assetfolders def available_assets(): return Asset.query.filter(Asset.owner == current_user.profile) \ .order_by(Asset.folder_id).order_by(Asset.filename) VALID_FILE_EXTENSIONS = ['jpg', 'png', 'jpeg', 'gif', 'svg', 'glb'] class UploadForm(FlaskForm): uploaded = FileField(validators=[FileRequired(), FileAllowed(VALID_FILE_EXTENSIONS, 'Certain images only')]) folder_id = HiddenField('FolderId', validators=[DataRequired()]) submit = SubmitField('Upload') class AssetSelectForm(FlaskForm): asset = QuerySelectField('Asset', query_factory=available_assets, get_label=lambda x: "/".join( x.path.split('/')[2:]), get_pk=lambda x: url_for('userassets.view', fileid=x.id, filename=x.filename)) add = SubmitField('Add') class NewFolderForm(FlaskForm): title = StringField('Title', validators=[DataRequired()]) parent_id = HiddenField('Parent', validators=[DataRequired()]) add = SubmitField('Create folder') class DeleteAssetForm(FlaskForm): id = HiddenField('Asset', validators=[DataRequired()]) delete = SubmitField('Delete') class DeleteAssetFolderForm(FlaskForm): id = HiddenField('AssetFolder', validators=[DataRequired()]) delete = SubmitField('Delete') class MoveAssetForm(FlaskForm): id = HiddenField('Asset', validators=[DataRequired()]) folder = QuerySelectField('Folder', query_factory=available_folders, get_label=lambda x: x.path) move = SubmitField('Move')
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,258
rikardg/whathappened
refs/heads/master
/tests/test_auth.py
from flask import session from app.auth.models import User def test_register(app, db): client = app.test_client() assert client.get('/auth/register').status_code == 200 response = client.post( '/auth/register', data={'username': 'a', 'email': 't@t.com', 'password': 'b', 'password2': 'b'} ) assert 'http://localhost/auth/login' == response.headers['Location'] user = User.query.get(1) assert user.username == 'a' assert user.email == 't@t.com' def test_logout(client, auth): auth.login() with client: auth.logout() assert 'user_id' not in session
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,259
rikardg/whathappened
refs/heads/master
/migrations/versions/b10c98640b7c_add_content_folders.py
"""Add content folders Revision ID: b10c98640b7c Revises: a425da83bea3 Create Date: 2021-04-27 22:42:23.571828 """ from alembic import op import sqlalchemy as sa from app.database.fields import GUID # revision identifiers, used by Alembic. revision = 'b10c98640b7c' down_revision = 'a425da83bea3' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('folder', sa.Column('id', GUID(), nullable=False), sa.Column('owner_id', sa.Integer(), nullable=True), sa.Column('parent_id', GUID(), nullable=True), sa.Column('title', sa.String(length=128), nullable=True), sa.ForeignKeyConstraint(['owner_id'], ['user_profile.id'], name=op.f( 'fk_folder_owner_id_user_profile')), sa.ForeignKeyConstraint(['parent_id'], ['folder.id'], name=op.f( 'fk_folder_parent_id_folder')), sa.PrimaryKeyConstraint('id', name=op.f('pk_folder')) ) with op.batch_alter_table('campaign', schema=None) as batch_op: batch_op.add_column(sa.Column('folder_id', GUID(), nullable=True)) batch_op.create_foreign_key(batch_op.f( 'fk_campaign_folder_id_folder'), 'folder', ['folder_id'], ['id']) with op.batch_alter_table('charactersheet', schema=None) as batch_op: batch_op.add_column(sa.Column('folder_id', GUID(), nullable=True)) batch_op.create_foreign_key(batch_op.f( 'fk_charactersheet_folder_id_folder'), 'folder', ['folder_id'], ['id']) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('charactersheet', schema=None) as batch_op: batch_op.drop_constraint(batch_op.f( 'fk_charactersheet_folder_id_folder'), type_='foreignkey') batch_op.drop_column('folder_id') with op.batch_alter_table('campaign', schema=None) as batch_op: batch_op.drop_constraint(batch_op.f( 'fk_campaign_folder_id_folder'), type_='foreignkey') batch_op.drop_column('folder_id') op.drop_table('folder') # ### end Alembic commands ###
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,260
rikardg/whathappened
refs/heads/master
/app/email.py
from threading import Thread from flask_mail import Message from flask import current_app, Flask from app import mail from typing import List def send_async_email(app: Flask, msg: str): with app.app_context(): mail.send(msg) def send_mail(subject: str, sender: str, recipients: List[str], text_body: str, html_body: str = None): msg = Message(subject, sender=sender, recipients=recipients) msg.body = text_body if html_body is not None: msg.html = html_body Thread(target=send_async_email, args=(current_app._get_current_object(), msg)).start()
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,261
rikardg/whathappened
refs/heads/master
/app/character/routes.py
import os from app.character import core from app.character.core import CHARACTER_SCHEMA_DIR, GameSystems from app.character.schema import load_schema, sub_schema import logging from flask import render_template, request from flask import redirect, url_for, jsonify from flask_login import login_required, current_user from werkzeug.exceptions import abort from . import bp, api from .models import Character from .forms import ImportForm, CreateForm from .forms import DeleteForm # Imports for registering games. from . import coc7e from . import tftl # noqa from app.models import LogEntry from app.utils.schema import migrate from app.models import Invite from app.character.schema.coc7e import migrations, latest from app.database import session, paginate from app.content.forms import ChooseFolderForm logger = logging.getLogger(__name__) def get_character(id: int, check_author: bool = True) -> Character: character = Character.query.get(id) if character is None: abort(404, "Character id {0} doesn't exist.".format(id)) if current_user.has_role('admin'): return character if character.campaigns: logger.debug("Checking if character is in same campaign as user") for campaign in character.campaigns: if current_user.profile in campaign.players \ or campaign in current_user.profile.campaigns: logger.debug(f"Character '{character.title}' " + f"is in '{campaign.title}' " + f"with '{current_user.username}''") return character if check_author and character.user_id != current_user.profile.id: abort(403) return character @bp.route('/') def index(): return redirect("/") @bp.route('/create/<string:chartype>/', methods=('GET', 'POST')) def create(chartype: str): character_module = globals()[chartype] if chartype in globals() else core form = getattr(character_module, 'CreateForm', CreateForm)() template = getattr(character_module, 'CREATE_TEMPLATE', 'character/create.html.jinja') if form.validate_on_submit(): logger.debug(f"Creating new character specified by {form.data}") char_data = character_module.new_character(**form.data) c = Character(title=form.title.data, body=char_data, user_id=current_user.profile.id) session.add(c) session.commit() return redirect(url_for('character.view', id=c.id)) form.system.data = chartype return render_template(template, form=form, type=type) @bp.route('/create/', methods=('GET', )) @login_required def system_select(chartype=None): return render_template('character/system_select.html.jinja', systems=GameSystems) @bp.route('/import/<string:type>', methods=('GET', 'POST')) @bp.route('/import/<int:id>', methods=('GET', 'POST')) @bp.route('/import/<uuid:code>', methods=('GET', 'POST')) @bp.route('/import', methods=('GET', 'POST')) @login_required def import_character(type=None, id: int = None, code: str = None): logger.debug(f"{type}, {code}, {id}") character = None if id: character = get_character(id, check_author=True) elif code is not None: invite = Invite.query.get(code) if invite is None or invite.table != Character.__tablename__: return "Invalid code" character = Character.query.get(invite.object_id) form = ImportForm(obj=character) if form.validate_on_submit(): c = Character(title=form.title.data, body=form.body.data, user_id=current_user.profile.id) session.add(c) session.commit() return redirect(url_for('character.view', id=c.id)) return render_template('character/import.html.jinja', form=form, type=None) @bp.route('/<int:id>/update', methods=('POST',)) @login_required def update(id: int): character = get_character(id, check_author=True) if request.method == "POST": update = request.get_json() for setting in update: character.set_attribute(setting) field = setting['field'] subfield = setting.get('subfield', '') value = setting['value'] type = setting.get('type', 'value') if type == 'portrait' and value is not None: value = "[image]" log_subfield = '' if subfield is not None and subfield != 'None': log_subfield = ' ' + subfield log_message = (f"set {type} on {field}{log_subfield}: {value}") logentry = LogEntry(character, log_message, user_id=current_user.id) session.add(logentry) character.store_data() session.commit() return "OK" @bp.route('/<uuid:code>', methods=('GET', )) def shared(code: str): invite = Invite.query.get(code) if invite is None or invite.table != Character.__tablename__: return "Invalid code" character = Character.query.get(invite.object_id) editable = False typeheader = "1920s Era Investigator" if character.game[1] == "Modern": typeheader = "Modern Era" return render_template('character/coc7e/sheet.html.jinja', code=code, character=character, typeheader=typeheader, editable=editable, skillform=None, subskillform=None) @bp.route('/<int:id>/', methods=('GET', 'POST')) @login_required def view(id: int): character = get_character(id, check_author=True) editable = False if (current_user.is_authenticated and current_user.profile.id == character.user_id): editable = True for campaign in character.campaigns: if campaign.user_id == current_user.profile.id: editable = True break if (character.system is None or character.validate()) and editable: return redirect(url_for('character.editjson', id=id)) character_module = (globals()[character.system] if character.system in globals() else core) system_view = getattr(character_module, 'view', None) if system_view is not None: return system_view(id, character, editable) system_template = getattr( character_module, 'CHARACTER_SHEET_TEMPLATE', None) if system_template: return render_template(character_module.CHARACTER_SHEET_TEMPLATE, character=character, editable=editable) character_schema = getattr( character_module, 'CHARACTER_SCHEMA', None) if character_schema is None: character_schema = os.path.join( CHARACTER_SCHEMA_DIR, character.system + '.yaml') return render_general_view(character_schema, character=character, editable=editable) def html_data_type(t: str) -> str: if t == 'integer': return 'number' return t def render_general_view(schema_file: str, character: Character, editable: bool): schema = load_schema(schema_file) return render_template('character/general_character.html.jinja', schema=schema, character=character, editable=editable, html_data_type=html_data_type, get_ref=sub_schema) @bp.route('/<int:id>/tokens/', methods=('GET', 'POST')) @login_required def tokens(id: int): character = get_character(id, check_author=False) return render_template('character/tokens.html.jinja', picture=character.portrait) @api.route('/<int:id>/', methods=('GET', )) def get(id: int): """API call to get all character data.""" data = get_character(id, check_author=True) return jsonify(data.to_dict()) @bp.route('/<int:id>/delete', methods=('GET', 'POST', )) @api.route('/<int:id>/delete', methods=('GET', 'POST', )) @login_required def delete(id: int): """Delete a character.""" character = get_character(id, check_author=True) if current_user.profile.id != character.user_id: abort(404) form = DeleteForm() if form.validate_on_submit(): session.delete(character) session.commit() return redirect(url_for('character.index')) form.character_id.data = character.id return render_template('character/delete_character.html.jinja', form=form, character=character) @api.route('/<int:id>/share', methods=('GET', )) @login_required def share(id: int): """Share a character.""" character = get_character(id, check_author=True) logger.debug("Finding previous invite") invite = Invite.query_for(character).first() logger.debug(f"Invites found {invite}") if not invite: logger.debug(f"Creating an invite for character {character.id}") invite = Invite(character) invite.owner_id = character.user_id session.add(invite) session.commit() share_url = url_for('character.shared', code=invite.id, _external=True) form = None html_response = render_template('character/api_share.html.jinja', form=form, url=share_url, code=invite.id) return jsonify({'url': share_url, 'html': html_response}) @bp.route('/<int:id>/export', methods=('GET', )) def export(id: int): """Exports charcter data to JSON.""" data = get_character(id, check_author=True) return jsonify(data.get_sheet()) @bp.route('/<int:id>/editjson', methods=('GET', 'POST')) def editjson(id: int): """Lets the user edit the raw json of the character.""" c = get_character(id, check_author=True) form = ImportForm(obj=c) if form.validate_on_submit(): c.title = form.title.data c.body = form.body.data if form.migration.data: logger.debug("Trying to migrate data") data = form.body.data c.body = migrate(data, latest, migrations=migrations) elif form.conversion.data: logger.debug("Conversion is checked") data = form.body.data c.body = coc7e.convert_from_dholes(data) logentry = LogEntry(c, "JSON edited", user_id=current_user.id) session.add(logentry) session.commit() return redirect(url_for('character.view', id=c.id)) form.submit.label.text = 'Save' validation_errors = c.validate() return render_template('character/import.html.jinja', title="Edit JSON", validation_errors=validation_errors, form=form, type=None) @bp.route('/<int:id>/eventlog', methods=('GET', )) @login_required def eventlog(id: int): page = request.args.get('page', 1, type=int) c = get_character(id, check_author=True) entries_page = paginate(LogEntry.query_for(c), page, 50) """ # TODO next_url = url_for('character.eventlog', id=id, page=entries_page.next_num) \ if entries_page.has_next else None prev_url = url_for('character.eventlog', id=id, page=entries_page.prev_num) \ if entries_page.has_prev else None """ next_url = None prev_url = None logger.debug(next_url) log_entries = entries_page.items return render_template('character/eventlog.html.jinja', character=c, entries=log_entries, next_url=next_url, prev_url=prev_url) @bp.route('/<int:id>/folder', methods=('GET', 'POST')) @login_required def folder(id: int): c = get_character(id, check_author=True) form = ChooseFolderForm() if form.validate_on_submit(): c.folder = form.folder_id.data session.commit() return render_template('character/move_to_folder.html.jinja', form=form, character=c)
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,262
rikardg/whathappened
refs/heads/master
/app/database/__init__.py
import math from sqlalchemy import create_engine, MetaData from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.ext.declarative import declarative_base Session = sessionmaker(autocommit=False, autoflush=True) session = scoped_session(Session) convention = { "ix": 'ix_%(column_0_label)s', "uq": "uq_%(table_name)s_%(column_0_name)s", "ck": "ck_%(table_name)s_%(column_0_name)s", "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", "pk": "pk_%(table_name)s" } sql_alchemy_metadata = MetaData(naming_convention=convention) Base = declarative_base(metadata=sql_alchemy_metadata) Base.query = session.query_property() def init_db(db_uri): engine = create_engine(db_uri, pool_recycle=3600) Session.configure(bind=engine) Base.metadata.bind = engine Base.metadata.create_all(bind=engine) class db(): @staticmethod def drop_all(): Base.metadata.drop_all(Base.metadata.bind) @staticmethod def create_all(): Base.metadata.create_all(Base.metadata.bind) session = session class Page(): def __init__(self, items, page: int, page_size: int, total: int): self.items = items self.prev_page = None self.next_page = None self.has_prev = page > 1 if self.has_prev: self.prev_page = page - 1 prev_items = (page - 1) * page_size self.has_next = prev_items + len(items) < total if self.has_next: self.next_page = page + 1 self.total = total self.pages = int(math.ceil(total / float(page_size))) def paginate(query, page: int, page_size: int = 25): if page <= 0: raise AttributeError('page must be >= 1') if page_size <= 0: raise AttributeError('page_size must be >= 1') items = query.limit(page_size).offset((page - 1) * page_size).all() total = query.order_by(None).count() return Page(items, page, page_size, total)
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,263
rikardg/whathappened
refs/heads/master
/app/character/coc7e/__init__.py
import logging import json import jinja2 import time from typing import Literal from .mechanics import CoCMechanics from .mechanics import CHARACTER_SCHEMA # noqa F401 from ..core import register_game logger = logging.getLogger(__name__) # This is not pretty GameType = Literal["Classic (1920's)", "Modern"] GameTypes = ["Classic (1920's)", "Modern"] from .forms import CreateForm # noqa F401 from .routes import view # noqa F401 CHARACTER_TEMPLATE = 'character/coc7e/blank_character.json.jinja' CREATE_TEMPLATE = 'character/coc7e/create.html.jinja' def new_character(title: str, gametype: GameType, **kwargs): templateloader = jinja2 \ .FileSystemLoader(searchpath="./app/character/templates/") templateenv = jinja2.Environment(loader=templateloader) template = templateenv.get_template(CHARACTER_TEMPLATE) gtype = gametype return json.loads(template.render(title=title, timestamp=time.time(), gametype=gtype)) register_game('coc7e', 'Call of Cthulhu TM', CoCMechanics)
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,264
rikardg/whathappened
refs/heads/master
/migrations/versions/71a3d1badc2e_add_campaigns.py
"""Add campaigns Revision ID: 71a3d1badc2e Revises: 15525e328d2d Create Date: 2020-10-04 14:11:35.762861 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '71a3d1badc2e' down_revision = '15525e328d2d' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('campaign', sa.Column('id', sa.Integer(), nullable=False), sa.Column('title', sa.String(length=256), nullable=True), sa.Column('description', sa.Text(), nullable=True), sa.Column('user_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['user_id'], ['user_profile.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('campaign_characters', sa.Column('character_id', sa.Integer(), nullable=False), sa.Column('campaign_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint(['campaign_id'], ['campaign.id'], ), sa.ForeignKeyConstraint(['character_id'], ['charactersheet.id'], ), sa.PrimaryKeyConstraint('character_id', 'campaign_id') ) op.create_table('campaign_players', sa.Column('player_id', sa.Integer(), nullable=False), sa.Column('campaign_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint(['campaign_id'], ['campaign.id'], ), sa.ForeignKeyConstraint(['player_id'], ['user_profile.id'], ), sa.PrimaryKeyConstraint('player_id', 'campaign_id') ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_table('campaign_players') op.drop_table('campaign_characters') op.drop_table('campaign') # ### end Alembic commands ###
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}
35,249,265
rikardg/whathappened
refs/heads/master
/migrations/versions/ac772b7261d0_add_metadata_naming_conventions.py
"""Add metadata naming conventions Revision ID: ac772b7261d0 Revises: c99e163f4457 Create Date: 2020-11-29 18:20:25.867829 """ from alembic import op import sqlalchemy as sa from alembic import context # revision identifiers, used by Alembic. revision = 'ac772b7261d0' down_revision = 'c99e163f4457' branch_labels = None depends_on = None def upgrade(): if context.get_impl().bind.dialect.name == "mysql": return # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('roles', schema=None) as batch_op: batch_op.create_unique_constraint(batch_op.f('uq_roles_name'), ['name']) # ### end Alembic commands ### def downgrade(): if context.get_impl().bind.dialect.name == "mysql": return # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('roles', schema=None) as batch_op: batch_op.drop_constraint(batch_op.f('uq_roles_name'), type_='unique') # ### end Alembic commands ###
{"/app/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/app/auth/models.py": ["/app/__init__.py", "/app/database/__init__.py"], "/tests/test_factory.py": ["/tests/conftest.py", "/app/__init__.py"], "/app/character/coc7e/__init__.py": ["/app/character/core.py", "/app/character/coc7e/mechanics.py", "/app/character/coc7e/forms.py", "/app/character/coc7e/routes.py"], "/app/__init__.py": ["/app/logging.py", "/config.py", "/app/database/__init__.py"], "/app/character/tftl/__init__.py": ["/app/character/core.py", "/app/character/tftl/mechanics.py", "/app/character/tftl/forms.py", "/app/character/tftl/routes.py", "/app/character/schema/__init__.py"], "/app/character/models.py": ["/app/__init__.py", "/app/character/core.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/campaign/models.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/content/mixins.py"], "/app/character/tftl/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/app/profile.py": ["/app/content/models.py", "/app/database/__init__.py", "/app/models.py"], "/app/campaign/views.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/campaign/forms.py", "/app/userassets/forms.py", "/app/database/__init__.py"], "/app/character/forms.py": ["/app/forms/fields/__init__.py"], "/app/campaign/__init__.py": ["/app/campaign/models.py"], "/app/character/coc7e/utils.py": ["/app/character/__init__.py"], "/app/userassets/models.py": ["/app/database/__init__.py", "/app/models.py"], "/app/content/forms.py": ["/app/forms/fields/alchemy.py"], "/app/character/coc7e/forms.py": ["/app/character/forms.py", "/app/character/coc7e/__init__.py"], "/tests/coc7e/test_coc7e.py": ["/app/auth/models.py", "/app/campaign/models.py", "/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/coc7e/convert.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py"], "/app/userassets/forms.py": ["/app/forms/fields/__init__.py", "/app/userassets/models.py"], "/tests/test_auth.py": ["/app/auth/models.py"], "/app/email.py": ["/app/__init__.py"], "/app/character/routes.py": ["/app/character/__init__.py", "/app/character/core.py", "/app/character/schema/__init__.py", "/app/character/models.py", "/app/character/forms.py", "/app/models.py", "/app/utils/schema.py", "/app/character/schema/coc7e.py", "/app/database/__init__.py", "/app/content/forms.py"], "/whathappened.py": ["/app/__init__.py", "/app/auth/models.py", "/app/profile.py", "/app/character/models.py"], "/tests/test_character.py": ["/app/character/models.py", "/app/character/forms.py"], "/app/character/coc7e/routes.py": ["/app/character/forms.py", "/app/models.py", "/app/database/__init__.py", "/app/character/coc7e/__init__.py"], "/app/character/core.py": ["/app/character/__init__.py", "/app/character/schema/__init__.py"], "/tests/coc7e/test_routes.py": ["/app/character/coc7e/utils.py"], "/app/content/__init__.py": ["/app/content/models.py"], "/app/main/routes.py": ["/app/models.py", "/app/database/__init__.py", "/app/main/__init__.py", "/app/main/forms.py"], "/app/character/coc7e/mechanics.py": ["/app/character/core.py", "/app/character/schema/__init__.py"], "/tests/conftest.py": ["/app/__init__.py", "/app/database/__init__.py", "/config.py"], "/app/content/routes.py": ["/app/database/__init__.py", "/app/character/models.py", "/app/campaign/__init__.py", "/app/content/__init__.py", "/app/content/forms.py", "/app/content/models.py"], "/tests/test_utils_schema.py": ["/app/utils/schema.py"], "/app/character/coc7e/convert.py": ["/app/character/coc7e/utils.py"], "/app/forms/fields/__init__.py": ["/app/forms/fields/alchemy.py"], "/app/campaign/forms.py": ["/app/models.py", "/app/forms/fields/__init__.py", "/app/campaign/models.py"], "/tests/tftl/test_tftl.py": ["/app/character/schema/__init__.py", "/app/character/tftl/__init__.py", "/app/character/models.py"], "/tests/test_campaign.py": ["/app/campaign/models.py"], "/app/campaign/api.py": ["/app/campaign/__init__.py", "/app/campaign/models.py", "/app/database/__init__.py"], "/app/content/models.py": ["/app/database/__init__.py"], "/app/character/tftl/forms.py": ["/app/character/forms.py"], "/app/campaign/routes.py": ["/app/main/forms.py", "/app/auth/models.py", "/app/campaign/__init__.py", "/app/campaign/models.py", "/app/character/models.py", "/app/models.py", "/app/campaign/forms.py", "/app/database/__init__.py", "/app/content/forms.py"], "/app/userassets/routes.py": ["/app/userassets/__init__.py", "/app/userassets/forms.py", "/app/userassets/models.py", "/app/database/__init__.py"], "/app/character/schema/coc7e.py": ["/app/character/coc7e/__init__.py", "/app/character/schema/__init__.py"], "/app/auth/__init__.py": ["/app/__init__.py", "/app/email.py", "/app/auth/models.py"], "/tests/test_user.py": ["/app/__init__.py", "/app/database/__init__.py", "/app/auth/models.py", "/tests/conftest.py"]}