Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

""" 

@file 

@brief Server with :epkg:`hypercorn`. 

""" 

from hypercorn.config import Config 

from hypercorn.run import run 

from hypercorn.utils import load_application 

 

 

class ServerHypercorn: 

""" 

Implements a server based on :epkg:`hypercorn`. 

""" 

 

def __init__(self, **kwargs): 

""" 

@param kwargs parameters 

""" 

self._run = run 

config = Config() 

app = load_application(kwargs['application_path']) 

if app is None: 

raise RuntimeError("Unable to load application '{0}'".format( 

kwargs["application_path"])) 

 

for k, v in kwargs.items(): 

if k in ('binds',): 

continue 

setattr(config, k, v) 

 

if len(kwargs['bind']) > 0: 

bind = kwargs['bind'] 

if not isinstance(bind, list): 

bind = [bind] 

config.bind = bind 

self.config = config 

 

def run(self, verbose=True): 

""" 

Starts the server. 

 

@param verbose display the host 

""" 

if verbose: 

scheme = "https" if self.config.ssl_enabled else "http" 

print("[mathenjeu] running on '{}' and {}".format(scheme, self.config.bind)) 

self._run(self.config)