aridity 73__tar.gz → 74__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: 73
3
+ Version: 74
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
@@ -236,6 +236,16 @@ class Functions:
236
236
  def getfrom(scope, scoperesolvable, *resolvables):
237
237
  return scoperesolvable.resolve(scope).resolved(*(r.resolve(scope).cat() for r in resolvables))
238
238
 
239
+ def rmeol(scope, resolvable):
240
+ text = resolvable.resolve(scope).cat()
241
+ if text.endswith('\r\n'):
242
+ n = 2
243
+ elif text.endswith(('\r', '\n')):
244
+ n = 1
245
+ else:
246
+ raise NoSuchPathException('No line terminator to remove.')
247
+ return Text(text[:-n])
248
+
239
249
  def getimpl(scope, *resolvables):
240
250
  return scope.resolved(*(r.resolve(scope).cat() for r in resolvables))
241
251
 
@@ -2,7 +2,7 @@ from . import directives
2
2
  from .directives import Precedence
3
3
  from .functions import getfunctions, OpaqueKey
4
4
  from .model import CatNotSupportedException, Directive, Function, Resolvable, Scalar, star, Stream, Text
5
- from .search import Query, resolvedscopeornone, scopedepths, slices
5
+ from .search import Query, resolvedscopeornone, slices
6
6
  from .stacks import IndentStack, SimpleStack, ThreadLocalResolvable
7
7
  from .util import CycleException, NoSuchPathException, OrderedDict, solo, TreeNoSuchPathException, UnsupportedEntryException
8
8
  from itertools import chain
@@ -134,7 +134,7 @@ class AbstractScope(Resolvable): # TODO LATER: Some methods should probably be m
134
134
  # TODO: Review this algo.
135
135
  errors = []
136
136
  for words in slices(path):
137
- for s in (resolvedscopeornone(s, words) for s in chain.from_iterable(scopedepths(self))):
137
+ for s in (resolvedscopeornone(s, words) for s in chain.from_iterable(self.scopedepths())):
138
138
  if s is not None:
139
139
  try:
140
140
  return hit.resolvable.resolve(s, **kwargs)
@@ -147,12 +147,21 @@ class AbstractScope(Resolvable): # TODO LATER: Some methods should probably be m
147
147
  def resolvableornone(self, key):
148
148
  return self.resolvables.getornone(key)
149
149
 
150
+ def scopedepths(self):
151
+ scopes = [self]
152
+ while scopes:
153
+ nextscopes = []
154
+ for s in scopes:
155
+ nextscopes.extend(s.parents)
156
+ yield scopes
157
+ scopes = nextscopes
158
+
150
159
  def unravel(self):
151
160
  d = OrderedDict([k, o.unravel()] for k, o in self.resolveditems())
152
161
  return list(d) if self.islist or (d and all(OpaqueKey.isopaque(k) for k in d.keys())) else d
153
162
 
154
163
  def staticscope(self):
155
- for s in chain.from_iterable(scopedepths(self)):
164
+ for s in chain.from_iterable(self.scopedepths()):
156
165
  pass
157
166
  return s
158
167
 
@@ -3,15 +3,6 @@ from collections import namedtuple
3
3
  from itertools import islice
4
4
  import heapq
5
5
 
6
- def scopedepths(scope):
7
- scopes = [scope]
8
- while scopes:
9
- nextscopes = []
10
- for s in scopes:
11
- nextscopes.extend(s.parents)
12
- yield scopes
13
- scopes = nextscopes
14
-
15
6
  def resolvedscopeornone(s, path):
16
7
  for name in path:
17
8
  r = s.resolvableornone(name)
@@ -22,15 +13,15 @@ def resolvedscopeornone(s, path):
22
13
  return
23
14
  return s
24
15
 
25
- class Hit(namedtuple('BaseHit', 'revdepths scope resolvable')):
16
+ class Hit(namedtuple('BaseHit', 'depths scope resolvable')):
26
17
 
27
18
  def iterornone(self, word):
28
19
  contextscope = self.resolvable.resolve(self.scope) # XXX: Wise?
29
20
  if hasattr(contextscope, 'resolvableornone'):
30
- return Iterator(self.revdepths, contextscope, word)
21
+ return Iterator(self.depths, contextscope, word)
31
22
 
32
23
  def shortcut(self, zerocount):
33
- return all(not d for d in islice(self.revdepths, None, zerocount))
24
+ return all(not d for d in islice(self.depths, len(self.depths) - zerocount, None))
34
25
 
35
26
  class Iterable:
36
27
 
@@ -39,13 +30,13 @@ class Iterable:
39
30
 
40
31
  class Iterator(Iterable):
41
32
 
42
- def __init__(self, revdepths, contextscope, word):
33
+ def __init__(self, depths, contextscope, word):
43
34
  def g():
44
- for depth, scopes in enumerate(scopedepths(contextscope)):
35
+ for depth, scopes in enumerate(contextscope.scopedepths()):
45
36
  for scope in scopes:
46
37
  resolvable = scope.resolvableornone(word)
47
38
  if resolvable is not None:
48
- yield Hit([depth] + revdepths, scope, resolvable)
39
+ yield Hit(depths + [depth], scope, resolvable)
49
40
  self.iterator = g()
50
41
 
51
42
  def next(self):
@@ -65,6 +56,13 @@ class Merge(Iterable):
65
56
  def popiterator(self):
66
57
  return heapq.merge(*popattr(self, 'iterables'))
67
58
 
59
+ def _lt(*depthspair):
60
+ for d1, d2 in zip(*map(reversed, depthspair)):
61
+ if d1 < d2:
62
+ return True
63
+ if d1 > d2:
64
+ break
65
+
68
66
  class Sump:
69
67
 
70
68
  besthit = None
@@ -73,7 +71,7 @@ class Sump:
73
71
  pass
74
72
 
75
73
  def offer(self, hit):
76
- if self.besthit is None or hit.revdepths < self.besthit.revdepths:
74
+ if self.besthit is None or _lt(hit.depths, self.besthit.depths):
77
75
  self.besthit = hit
78
76
 
79
77
  def __iter__(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aridity
3
- Version: 73
3
+ Version: 74
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
@@ -6,7 +6,7 @@ def long_description():
6
6
 
7
7
  setup(
8
8
  name = 'aridity',
9
- version = '73',
9
+ version = '74',
10
10
  description = 'DRY config and template system, easily extensible with Python',
11
11
  long_description = long_description(),
12
12
  long_description_content_type = 'text/markdown',
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