langfun 0.1.2.dev202409180804__py3-none-any.whl → 0.1.2.dev202409200804__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
langfun/core/template.py CHANGED
@@ -231,6 +231,16 @@ class Template(
231
231
  """Returns the missing variable names."""
232
232
  return self.vars(closure=True, specified=False)
233
233
 
234
+ @classmethod
235
+ def raw_str(cls, text: str) -> str:
236
+ """Returns a template string that preserve the text as original."""
237
+ return '{% raw %}' + text + '{% endraw %}'
238
+
239
+ @classmethod
240
+ def from_raw_str(cls, text: str) -> 'Template':
241
+ """Returns a template that preserve the text as original."""
242
+ return cls(cls.raw_str(text), clean=False)
243
+
234
244
  def render(
235
245
  self,
236
246
  *,
@@ -98,6 +98,21 @@ class BasicTest(unittest.TestCase):
98
98
  self.assertEqual(d.z.render(), 'Bye, 1')
99
99
  self.assertEqual(d.p.render(), 'Again Hello, 1')
100
100
 
101
+ def test_raw_text(self):
102
+ self.assertEqual(
103
+ Template(
104
+ '{{a}}' + Template.raw_str('\n{{d}}, {%x%}\n') + '{{b}}',
105
+ a='hi', b=1
106
+ ).render().text,
107
+ 'hi\n{{d}}, {%x%}\n1'
108
+ )
109
+
110
+ def test_from_raw_str(self):
111
+ self.assertEqual(
112
+ Template.from_raw_str('\n{{d}}, {%x%}\n').render().text,
113
+ '\n{{d}}, {%x%}\n'
114
+ )
115
+
101
116
 
102
117
  class DefinitionTest(unittest.TestCase):
103
118
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langfun
3
- Version: 0.1.2.dev202409180804
3
+ Version: 0.1.2.dev202409200804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -25,8 +25,8 @@ langfun/core/sampling.py,sha256=vygWvgC8MFw0_AKNSmz-ywMXJYWf8cl0tI8QycvAmyI,5795
25
25
  langfun/core/sampling_test.py,sha256=U7PANpMsl9E_pa4_Y4FzesSjcwg-u-LKHGCWSgv-8FY,3663
26
26
  langfun/core/subscription.py,sha256=euawEuSZP-BHydaT-AQpfYFL0m5pWPGcW0upFhrojqc,10930
27
27
  langfun/core/subscription_test.py,sha256=Y4ZdbZEwm83YNZBxHff0QR4QUa4rdaNXA3_jfIcArBo,8717
28
- langfun/core/template.py,sha256=UhNNGUDJ4StUhPBKzHmjym36khxHOGWGr9MDxBwgxQA,22284
29
- langfun/core/template_test.py,sha256=cb005qM_3dvJikaPDB3rirfIrMAIIVRpoiXGREGJ43o,15468
28
+ langfun/core/template.py,sha256=AWHJwWjsPgf8r584_HOleBqgN90oKCpW8OMx-gdljuM,22635
29
+ langfun/core/template_test.py,sha256=YCBa9YMYtc_8X2gNSJvvQKpSovZy5A4YgIniCvm-1Ys,15843
30
30
  langfun/core/text_formatting.py,sha256=d7t9vaY6aCn1dkfkikpNYnBy5E_i93vHbfyDWFclGZU,5284
31
31
  langfun/core/text_formatting_test.py,sha256=ck0Xzdd4YF4CtCUj7VE0GybfbAyKQ8p3xkM1FBGrqIk,2096
32
32
  langfun/core/coding/__init__.py,sha256=5utju_fwEsImaiftx4oXKl9FAM8p281k8-Esdh_-m1w,835
@@ -119,8 +119,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
119
119
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
120
120
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
121
121
  langfun/core/templates/selfplay_test.py,sha256=rBW2Qr8yi-aWYwoTwRR-n1peKyMX9QXPZXURjLgoiRs,2264
122
- langfun-0.1.2.dev202409180804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
123
- langfun-0.1.2.dev202409180804.dist-info/METADATA,sha256=8r43i6FzNi9hKws1cufJ5ZdtRHDWuyRiDZ7UniEq8gE,8890
124
- langfun-0.1.2.dev202409180804.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
125
- langfun-0.1.2.dev202409180804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
126
- langfun-0.1.2.dev202409180804.dist-info/RECORD,,
122
+ langfun-0.1.2.dev202409200804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
123
+ langfun-0.1.2.dev202409200804.dist-info/METADATA,sha256=l1r-4ikUqpe5vgNi6CB4xUtKb6shY5r65AG05UB6dvw,8890
124
+ langfun-0.1.2.dev202409200804.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
125
+ langfun-0.1.2.dev202409200804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
126
+ langfun-0.1.2.dev202409200804.dist-info/RECORD,,