aridity 81__tar.gz → 82__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aridity
3
- Version: 81
3
+ Version: 82
4
4
  Summary: DRY config and template system, easily extensible with Python
5
5
  Home-page: https://pypi.org/project/aridity/
6
6
  Author: foyono
@@ -148,7 +148,7 @@ class ConfigCtrl:
148
148
  s = self.scope()
149
149
  obj = _wrappathorstream(frompathorstream).processtemplate(s)
150
150
  if getattr(topathorstream, 'writable', lambda: False)():
151
- topathorstream.write(obj.cat())
151
+ topathorstream.write(obj.cat() if hasattr(topathorstream, 'encoding') else obj.binaryvalue)
152
152
  else:
153
153
  obj.writeout(topathorstream)
154
154
 
@@ -79,7 +79,7 @@ class GFactory:
79
79
  return Concat(t, self.monitor)
80
80
 
81
81
  def _bracketspa(self, s, l, t):
82
- return Concat(t[1:-1], self.monitor)
82
+ return Concat(t[1:-1] or [Text('')], self.monitor)
83
83
 
84
84
  def create(self, pa):
85
85
  def itercalls():
@@ -40,6 +40,28 @@ class Resolved(Resolvable):
40
40
 
41
41
  nullmonitor = lambda text: None
42
42
 
43
+ class NegBuffer:
44
+
45
+ def __init__(self):
46
+ self.text = ''
47
+
48
+ def insert(self, text):
49
+ self.text = text + self.text
50
+
51
+ def annihilate(self, obj):
52
+ if not self.text:
53
+ return obj
54
+ text = obj.cat()
55
+ if not text:
56
+ return obj
57
+ k = min(len(self.text), len(text))
58
+ assert self.text[:k] == text[:k]
59
+ self.text = self.text[k:]
60
+ return Text(text[k:])
61
+
62
+ def propagate(self, obj):
63
+ return Hole(obj, self.text) if self.text else obj
64
+
43
65
  class Concat(Resolvable):
44
66
 
45
67
  ignorable = False
@@ -59,27 +81,26 @@ class Concat(Resolvable):
59
81
  def resolve(self, scope, aslist = False):
60
82
  if aslist:
61
83
  return List([part.resolve(scope) for part in self.parts if not part.ignorable])
62
- buffer = []
63
- negbuffer = ''
84
+ result = Indeterminate
85
+ negbuffer = NegBuffer()
64
86
  for part in self.parts:
65
87
  obj = part.resolve(scope)
66
88
  try:
67
89
  negtext = obj.holevalue
68
90
  except AttributeError:
69
- text = obj.cat()
70
91
  negtext = ''
71
92
  else:
72
- text = obj.prefix.textvalue
73
- k = min(len(negbuffer), len(text))
74
- if k:
75
- assert negbuffer[:k] == text[:k]
76
- negbuffer = negbuffer[k:]
77
- text = text[k:]
78
- buffer.append(text)
79
- self.monitor(text)
80
- negbuffer = negtext + negbuffer
81
- buffer = Text(''.join(buffer))
82
- return Hole(buffer, negbuffer) if negbuffer else buffer
93
+ obj = obj.prefix
94
+ obj = negbuffer.annihilate(obj)
95
+ result = result.plus(obj)
96
+ try:
97
+ text = obj.cat()
98
+ except CatNotSupportedException:
99
+ pass
100
+ else:
101
+ self.monitor(text)
102
+ negbuffer.insert(negtext)
103
+ return negbuffer.propagate(result)
83
104
 
84
105
  def unparse(self):
85
106
  return ''.join(part.unparse() for part in self.parts)
@@ -118,6 +139,9 @@ class Blank(Cat, SimpleValue):
118
139
  ignorable = True
119
140
  boundary = False
120
141
 
142
+ def plus(self, that):
143
+ return Text(self.scalar + that.cat())
144
+
121
145
  class Boundary(SimpleValue):
122
146
 
123
147
  ignorable = True
@@ -149,6 +173,12 @@ class Text(Cat, BaseScalar):
149
173
  def scalar(self):
150
174
  return self.textvalue
151
175
 
176
+ @property
177
+ def binaryvalue(self):
178
+ if self.textvalue:
179
+ raise AttributeError('binaryvalue')
180
+ return b''
181
+
152
182
  def __init__(self, textvalue):
153
183
  self.textvalue = textvalue
154
184
 
@@ -172,6 +202,22 @@ class Text(Cat, BaseScalar):
172
202
  return o
173
203
  return Locator(s)
174
204
 
205
+ def plus(self, that):
206
+ return self._of(self.textvalue + that.cat())
207
+
208
+ class Indeterminate:
209
+
210
+ def cat(self):
211
+ return ''
212
+
213
+ def plus(self, that):
214
+ return that
215
+
216
+ def totext(self):
217
+ return Text('')
218
+
219
+ Indeterminate = Indeterminate()
220
+
175
221
  class Hole(BaseScalar):
176
222
 
177
223
  @property
@@ -261,6 +307,10 @@ class Resource(Resolved, Openable):
261
307
 
262
308
  class Binary(BaseScalar):
263
309
 
310
+ @classmethod
311
+ def _of(cls, *args):
312
+ return cls(*args)
313
+
264
314
  @property
265
315
  def scalar(self):
266
316
  return self.binaryvalue
@@ -272,6 +322,9 @@ class Binary(BaseScalar):
272
322
  with open(path, 'wb') as f:
273
323
  f.write(self.binaryvalue)
274
324
 
325
+ def plus(self, that):
326
+ return self._of(self.binaryvalue + that.binaryvalue)
327
+
275
328
  class Number(BaseScalar):
276
329
 
277
330
  @property
@@ -290,6 +343,9 @@ class Number(BaseScalar):
290
343
  def cat(self): # XXX: Should a parsed Number also be Text?
291
344
  return self.unparse()
292
345
 
346
+ def plus(self, that):
347
+ return Text(self.unparse() + that.cat())
348
+
293
349
  class Boolean(BaseScalar):
294
350
 
295
351
  @property
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aridity
3
- Version: 81
3
+ Version: 82
4
4
  Summary: DRY config and template system, easily extensible with Python
5
5
  Home-page: https://pypi.org/project/aridity/
6
6
  Author: foyono
@@ -49,7 +49,7 @@ class SourceInfo:
49
49
  sourceinfo = SourceInfo('.')
50
50
  setup(
51
51
  name = 'aridity',
52
- version = '81',
52
+ version = '82',
53
53
  description = 'DRY config and template system, easily extensible with Python',
54
54
  url = 'https://pypi.org/project/aridity/',
55
55
  author = 'foyono',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes