MCPcopy Index your code
hub / github.com/rawpython/remi / _process_all

Method _process_all

remi/server.py:681–742  ·  view source on GitHub ↗
(self, func, **kwargs)

Source from the content-addressed store, hash-verified

679 return data
680
681 def _process_all(self, func, **kwargs):
682 self._log.debug('get: %s' % func)
683 static_file = self.re_static_file.match(func)
684 attr_call = self.re_attr_call.match(func)
685
686 if (func == '/') or (not func):
687 self.send_response(200)
688 self.send_header("Set-Cookie", "remi_session=%s; SameSite=Lax"%(self.session))
689 self.send_header('Content-type', 'text/html')
690 self.end_headers()
691
692 with self.update_lock:
693 # render the HTML
694 page_content = self.page.repr()
695
696 self.wfile.write(encode_text("<!DOCTYPE html>\n"))
697 self.wfile.write(encode_text(self._overload(page_content, filename="internal")))
698
699 elif static_file:
700 filename = self._get_static_file(static_file.groups()[0])
701 if not filename:
702 self.send_response(404)
703 return
704 mimetype, encoding = mimetypes.guess_type(filename)
705 self.send_response(200)
706 self.send_header('Content-type', mimetype if mimetype else 'application/octet-stream')
707 if self.server.enable_file_cache:
708 self.send_header('Cache-Control', 'public, max-age=86400')
709 self.end_headers()
710 with open(filename, 'rb') as f:
711 content = f.read()
712 self.wfile.write(self._overload(content, filename=filename))
713 elif attr_call:
714 with self.update_lock:
715 param_dict = parse_qs(urlparse(func).query)
716 # parse_qs returns patameters as list, here we take the first element
717 for k in param_dict:
718 param_dict[k] = param_dict[k][0]
719
720 widget, func = attr_call.group(1, 2)
721 try:
722 content, headers = get_method_by_name(get_method_by_id(widget), func)(**param_dict)
723 if content is None:
724 self.send_response(503)
725 return
726 self.send_response(200)
727 except IOError:
728 self._log.error('attr %s/%s call error' % (widget, func), exc_info=True)
729 self.send_response(404)
730 return
731 except (TypeError, AttributeError):
732 self._log.error('attr %s/%s not available' % (widget, func))
733 self.send_response(503)
734 return
735
736 for k in headers:
737 self.send_header(k, headers[k])
738 self.end_headers()

Callers 1

do_GETMethod · 0.95

Calls 6

_overloadMethod · 0.95
_get_static_fileMethod · 0.95
encode_textFunction · 0.85
get_method_by_nameFunction · 0.85
get_method_by_idFunction · 0.85
reprMethod · 0.45

Tested by

no test coverage detected