Skip to content

Commit 3198c54

Browse files
committed
Move utils functions to top level
1 parent 8d3a36f commit 3198c54

3 files changed

Lines changed: 394 additions & 342 deletions

File tree

README.rst

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Using Dpath
3030

3131
.. code-block:: python
3232
33-
import dpath.util
33+
import dpath
3434
3535
Separators
3636
==========
@@ -62,8 +62,8 @@ key '43' in the 'b' hash which is in the 'a' hash". That's easy.
6262

6363
.. code-block:: pycon
6464
65-
>>> help(dpath.util.get)
66-
Help on function get in module dpath.util:
65+
>>> help(dpath.get)
66+
Help on function get in module dpath:
6767
6868
get(obj, glob, separator='/')
6969
Given an object which contains only one possible match for the given glob,
@@ -72,16 +72,16 @@ key '43' in the 'b' hash which is in the 'a' hash". That's easy.
7272
If more than one leaf matches the glob, ValueError is raised. If the glob is
7373
not found, KeyError is raised.
7474
75-
>>> dpath.util.get(x, '/a/b/43')
75+
>>> dpath.get(x, '/a/b/43')
7676
30
7777
7878
Or you could say "Give me a new dictionary with the values of all
7979
elements in ``x['a']['b']`` where the key is equal to the glob ``'[cd]'``. Okay.
8080

8181
.. code-block:: pycon
8282
83-
>>> help(dpath.util.search)
84-
Help on function search in module dpath.util:
83+
>>> help(dpath.search)
84+
Help on function search in module dpath:
8585
8686
search(obj, glob, yielded=False)
8787
Given a path glob, return a dictionary containing all keys
@@ -95,7 +95,7 @@ elements in ``x['a']['b']`` where the key is equal to the glob ``'[cd]'``. Okay.
9595

9696
.. code-block:: pycon
9797
98-
>>> result = dpath.util.search(x, "a/b/[cd]")
98+
>>> result = dpath.search(x, "a/b/[cd]")
9999
>>> print(json.dumps(result, indent=4, sort_keys=True))
100100
{
101101
"a": {
@@ -115,7 +115,7 @@ not get a merged view?
115115

116116
.. code-block:: pycon
117117
118-
>>> for x in dpath.util.search(x, "a/b/[cd]", yielded=True): print(x)
118+
>>> for x in dpath.search(x, "a/b/[cd]", yielded=True): print(x)
119119
...
120120
('a/b/c', [])
121121
('a/b/d', ['red', 'buggy', 'bumpers'])
@@ -125,16 +125,16 @@ don't care about the paths they were found at:
125125

126126
.. code-block:: pycon
127127
128-
>>> help(dpath.util.values)
129-
Help on function values in module dpath.util:
128+
>>> help(dpath.values)
129+
Help on function values in module dpath:
130130
131131
values(obj, glob, separator='/', afilter=None, dirs=True)
132132
Given an object and a path glob, return an array of all values which match
133133
the glob. The arguments to this function are identical to those of search(),
134134
and it is primarily a shorthand for a list comprehension over a yielded
135135
search call.
136136
137-
>>> dpath.util.values(x, '/a/b/d/*')
137+
>>> dpath.values(x, '/a/b/d/*')
138138
['red', 'buggy', 'bumpers']
139139
140140
Example: Setting existing keys
@@ -145,14 +145,14 @@ value 'Waffles'.
145145

146146
.. code-block:: pycon
147147
148-
>>> help(dpath.util.set)
149-
Help on function set in module dpath.util:
148+
>>> help(dpath.set)
149+
Help on function set in module dpath:
150150
151151
set(obj, glob, value)
152152
Given a path glob, set all existing elements in the document
153153
to the given value. Returns the number of elements changed.
154154
155-
>>> dpath.util.set(x, 'a/b/[cd]', 'Waffles')
155+
>>> dpath.set(x, 'a/b/[cd]', 'Waffles')
156156
2
157157
>>> print(json.dumps(x, indent=4, sort_keys=True))
158158
{
@@ -175,8 +175,8 @@ necessary to get to the terminus.
175175

176176
.. code-block:: pycon
177177
178-
>>> help(dpath.util.new)
179-
Help on function new in module dpath.util:
178+
>>> help(dpath.new)
179+
Help on function new in module dpath:
180180
181181
new(obj, path, value)
182182
Set the element at the terminus of path to value, and create
@@ -187,7 +187,7 @@ necessary to get to the terminus.
187187
characters in it, they will become part of the resulting
188188
keys
189189
190-
>>> dpath.util.new(x, 'a/b/e/f/g', "Roffle")
190+
>>> dpath.new(x, 'a/b/e/f/g', "Roffle")
191191
>>> print(json.dumps(x, indent=4, sort_keys=True))
192192
{
193193
"a": {
@@ -211,8 +211,8 @@ object with None entries in order to make it big enough:
211211

212212
.. code-block:: pycon
213213
214-
>>> dpath.util.new(x, 'a/b/e/f/h', [])
215-
>>> dpath.util.new(x, 'a/b/e/f/h/13', 'Wow this is a big array, it sure is lonely in here by myself')
214+
>>> dpath.new(x, 'a/b/e/f/h', [])
215+
>>> dpath.new(x, 'a/b/e/f/h/13', 'Wow this is a big array, it sure is lonely in here by myself')
216216
>>> print(json.dumps(x, indent=4, sort_keys=True))
217217
{
218218
"a": {
@@ -251,11 +251,11 @@ Handy!
251251
Example: Deleting Existing Keys
252252
===============================
253253

254-
To delete keys in an object, use dpath.util.delete, which accepts the same globbing syntax as the other methods.
254+
To delete keys in an object, use dpath.delete, which accepts the same globbing syntax as the other methods.
255255

256256
.. code-block:: pycon
257257
258-
>>> help(dpath.util.delete)
258+
>>> help(dpath.delete)
259259
260260
delete(obj, glob, separator='/', afilter=None):
261261
Given a path glob, delete all elements that match the glob.
@@ -266,14 +266,14 @@ To delete keys in an object, use dpath.util.delete, which accepts the same globb
266266
Example: Merging
267267
================
268268

269-
Also, check out dpath.util.merge. The python dict update() method is
269+
Also, check out dpath.merge. The python dict update() method is
270270
great and all but doesn't handle merging dictionaries deeply. This one
271271
does.
272272

273273
.. code-block:: pycon
274274
275-
>>> help(dpath.util.merge)
276-
Help on function merge in module dpath.util:
275+
>>> help(dpath.merge)
276+
Help on function merge in module dpath:
277277
278278
merge(dst, src, afilter=None, flags=4, _path='')
279279
Merge source into destination. Like dict.update() but performs
@@ -310,7 +310,7 @@ does.
310310
"c": "RoffleWaffles"
311311
}
312312
}
313-
>>> dpath.util.merge(x, y)
313+
>>> dpath.merge(x, y)
314314
>>> print(json.dumps(x, indent=4, sort_keys=True))
315315
{
316316
"a": {
@@ -390,7 +390,7 @@ them:
390390
... return True
391391
... return False
392392
...
393-
>>> result = dpath.util.search(x, '**', afilter=afilter)
393+
>>> result = dpath.search(x, '**', afilter=afilter)
394394
>>> print(json.dumps(result, indent=4, sort_keys=True))
395395
{
396396
"a": {
@@ -429,18 +429,18 @@ Separator got you down? Use lists as paths
429429

430430
The default behavior in dpath is to assume that the path given is a string, which must be tokenized by splitting at the separator to yield a distinct set of path components against which dictionary keys can be individually glob tested. However, this presents a problem when you want to use paths that have a separator in their name; the tokenizer cannot properly understand what you mean by '/a/b/c' if it is possible for '/' to exist as a valid character in a key name.
431431

432-
To get around this, you can sidestep the whole "filesystem path" style, and abandon the separator entirely, by using lists as paths. All of the methods in dpath.util.* support the use of a list instead of a string as a path. So for example:
432+
To get around this, you can sidestep the whole "filesystem path" style, and abandon the separator entirely, by using lists as paths. All of the methods in dpath.* support the use of a list instead of a string as a path. So for example:
433433

434434
.. code-block:: python
435435
436436
>>> x = { 'a': {'b/c': 0}}
437-
>>> dpath.util.get(['a', 'b/c'])
437+
>>> dpath.get(['a', 'b/c'])
438438
0
439439
440440
dpath.segments : The Low-Level Backend
441441
======================================
442442

443-
dpath.util is where you want to spend your time: this library has the friendly
443+
dpath is where you want to spend your time: this library has the friendly
444444
functions that will understand simple string globs, afilter functions, etc.
445445

446446
dpath.segments is the backend pathing library. It passes around tuples of path

0 commit comments

Comments
 (0)