Skip to content

Commit 41bf875

Browse files
committed
passing Request to Dynamic?
1 parent 0c03219 commit 41bf875

17 files changed

+91
-54
lines changed

Mamlambo/Cache.py renamed to Mamlambo/Core/Cache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/python3.6
22
# -*- coding: utf-8 -*-
3-
from . import Session as session
4-
from . import Singleton
3+
from Mamlambo.Core import Singleton
54

65

76
@Singleton.singleton_object

Mamlambo/Configuration.py renamed to Mamlambo/Core/Configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
22
import yaml
33
from .MamlamboException import MamlamboException
4-
from . import Singleton
5-
from .Response import Response
4+
from Mamlambo.Core import Singleton
5+
from Mamlambo.Response import Response
66
import re
77
from urllib.parse import urlparse
88

Mamlambo/MamlamboException.py renamed to Mamlambo/Core/MamlamboException.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import sys
55
import Mamlambo
6-
from . import Response
7-
from . import Configuration
6+
from Mamlambo.Core import Configuration
7+
from Mamlambo import Response
88

99

1010
class MamlamboException:
File renamed without changes.

Mamlambo/Core/__init__.py

Whitespace-only changes.

Mamlambo/RendererDefault.py renamed to Mamlambo/Renderer/Default.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# -*- coding: utf-8 -*-
33

44
import os
5-
from .MamlamboException import MamlamboException
5+
from Mamlambo.Core.MamlamboException import MamlamboException
66

77

8-
class RendererDefault:
8+
class Default:
99

1010
def __init__(self, config, request, response):
1111

Mamlambo/RendererDynamic.py renamed to Mamlambo/Renderer/Dynamic.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import copy
99
import json
1010
from contextlib import redirect_stdout
11-
from .Configuration import Configuration
12-
from .MamlamboException import MamlamboException
11+
from Mamlambo.Core.Configuration import Configuration
12+
from Mamlambo.Core.MamlamboException import MamlamboException
1313

1414

15-
class RendererDynamic:
15+
class Dynamic:
1616
__page_raw = None
1717
__page_result = None
1818
__page_template = None
@@ -28,13 +28,14 @@ class RendererDynamic:
2828
__directive_attributes = None
2929

3030
__is_nested_call = None
31-
__verbose = True
31+
__verbose = False
3232

3333
def verbose(self, text):
3434
if self.__verbose:
3535
print(text)
3636

37-
def __init__(self, file_name, is_fragment=False, is_nested_call=0):
37+
def __init__(self, request, file_name, is_fragment=False, is_nested_call=0):
38+
self.__request = request
3839
self.__page_mime = "text/html"
3940
self.__http_code = 200
4041
self.__page_filename = file_name
@@ -313,7 +314,7 @@ def process_directive_page(self, matches):
313314
# print('-- using master page')
314315
page_master_file_name = Configuration().map_path(path_info=self.__page_master)
315316
self.verbose("!RendererDynamic('" + page_master_file_name + "')")
316-
masterpage = RendererDynamic(page_master_file_name, is_nested_call=1)
317+
masterpage = Dynamic(self.__request, page_master_file_name, is_nested_call=1)
317318
self.verbose("!After RendererDynamic of master:" + str(masterpage))
318319
# print('-- master info')
319320
# print("master_placeholderse: " + str(masterpage.master_placeholders))
@@ -403,9 +404,6 @@ def process_directive_page(self, matches):
403404
# if page_code include the code.py
404405
regex_doctype = r"<[^\!].*[\^>]*>" # tags not starting with <! like DOCTYPE
405406
matches = re.finditer(regex_doctype, self.__page_raw, re.MULTILINE)
406-
self.verbose('~~~~~~~~')
407-
self.verbose('self.__page_code_source: ' + str(self.__page_code_source))
408-
self.verbose('~~~~~~~~')
409407
found = False
410408
for matches_count, match in enumerate(matches, start=0):
411409
found = True
@@ -416,13 +414,26 @@ def process_directive_page(self, matches):
416414
else:
417415
include_master_page_source_code = ""
418416

417+
inject_request = """
418+
REQUEST = 'a'
419+
print(dir())
420+
globals()["REQUEST"] = 'b'
421+
print(dir(globals()))
422+
423+
\n"""
424+
419425
if self.__page_code_source:
420426
self.__page_raw = self.insert_str(
421427
self.__page_raw,
422-
"\n<?python:\n" + include_master_page_source_code + "\n" + self.__page_code_source + "\n?>",
428+
"\n<?python:\n" + inject_request + include_master_page_source_code + "\n" + self.__page_code_source + "\n?>",
423429
match.end())
424430
break
425431

432+
self.verbose('~~~~~~~~')
433+
self.verbose('self.__page_raw: ' + str(self.__page_raw))
434+
self.verbose('~~~~~~~~')
435+
436+
426437
if not found:
427438
try:
428439
with io.StringIO() as buf, redirect_stdout(buf):
@@ -526,7 +537,7 @@ class RendererMain:
526537
# def __init__(self, file_name, is_fragment=False):
527538
def __init__(self, request, response):
528539
file_name = Configuration().map_path(path_info=request.path_info)
529-
markdown = RendererDynamic(file_name, is_fragment=False, is_nested_call=0)
540+
markdown = Dynamic(request, file_name, is_fragment=False, is_nested_call=0)
530541
response.mime = markdown.page_mime
531542
response.content_str = markdown.page_result
532543
response.code = markdown.http_code

Mamlambo/RendererRoutes.py renamed to Mamlambo/Renderer/Routes.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# -*- coding: utf-8 -*-
33

44
import re
5-
import os
6-
from . import Configuration
7-
from . import Request
8-
from . import Response
95

106
from enum import Enum
117

@@ -15,7 +11,7 @@ class Mode(Enum):
1511
route = 'route'
1612

1713

18-
class RendererRoutes:
14+
class Routes:
1915

2016
# mode = 'redirection' adds header Location and response.end
2117
# mode = 'route' changes url

Mamlambo/RendererStatic.py renamed to Mamlambo/Renderer/Static.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# -*- coding: utf-8 -*-
33

44
import os
5-
from .MamlamboException import MamlamboException
5+
from Mamlambo.Core.MamlamboException import MamlamboException
66

77

8-
class RendererStatic:
8+
class Static:
99
def __init__(self, config, request, response):
1010
response.complete = False
1111

Mamlambo/Renderer/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)