Skip to content

Commit

Permalink
/persist edits
Browse files Browse the repository at this point in the history
  • Loading branch information
gvwilson committed Aug 7, 2023
1 parent 8882c33 commit 922a7d8
Show file tree
Hide file tree
Showing 30 changed files with 767 additions and 713 deletions.
File renamed without changes.
238 changes: 236 additions & 2 deletions docs/bonus/index.html

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions docs/contents/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ <h1>Appendix I: Index</h1>
<li>IP address: <a class="ix-ref" ix-ref="IP address" href="../ftp/">Transferring Files</a></li>
<li>Internet Protocol: <a class="ix-ref" ix-ref="Internet Protocol" href="../ftp/">Transferring Files</a></li>
<li>Iterator pattern: <a class="ix-ref" ix-ref="Iterator pattern" href="../protocols/">Protocols</a></li>
<li>JSON: <a class="ix-ref" ix-ref="JSON" href="../parse/">Parsing Text</a>, <a class="ix-ref" ix-ref="JSON" href="../interp/">An Interpreter</a>, <a class="ix-ref" ix-ref="JSON" href="../archive/">A File Archiver</a>, <a class="ix-ref" ix-ref="JSON" href="../check/">An HTML Validator</a>, <a class="ix-ref" ix-ref="JSON" href="../persist/">Object Persistence</a>, <a class="ix-ref" ix-ref="JSON" href="../build/">A Build Manager</a>, <a class="ix-ref" ix-ref="JSON" href="../pack/">A Package Manager</a></li>
<li>JSON: <a class="ix-ref" ix-ref="JSON" href="../parse/">Parsing Text</a>, <a class="ix-ref" ix-ref="JSON" href="../interp/">An Interpreter</a>, <a class="ix-ref" ix-ref="JSON" href="../archive/">A File Archiver</a>, <a class="ix-ref" ix-ref="JSON" href="../check/">An HTML Validator</a>, <a class="ix-ref" ix-ref="JSON" href="../build/">A Build Manager</a>, <a class="ix-ref" ix-ref="JSON" href="../pack/">A Package Manager</a></li>
<li>Java: <a class="ix-ref" ix-ref="Java" href="../build/">A Build Manager</a></li>
<li>Jekyll: <a class="ix-ref" ix-ref="Jekyll" href="../template/">A Template Expander</a></li>
<li>Liskov Substitution Principle: <a class="ix-ref" ix-ref="Liskov Substitution Principle" href="../layout/">Page Layout</a></li>
Expand All @@ -333,7 +333,7 @@ <h1>Appendix I: Index</h1>
<li>PHP: <a class="ix-ref" ix-ref="PHP" href="../template/">A Template Expander</a></li>
<li>Polge, Thibault: <a class="ix-ref" ix-ref="Polge, Thibault" href="../archive/">A File Archiver</a></li>
<li>Python standard library: <a class="ix-ref" ix-ref="Python standard library" href="../glob/">Matching Patterns</a>, <a class="ix-ref" ix-ref="Python standard library" href="../archive/">A File Archiver</a>, <a class="ix-ref" ix-ref="Python standard library" href="../lint/">A Code Linter</a>, <a class="ix-ref" ix-ref="Python standard library" href="../http/">Serving Web Pages</a></li>
<li>Pythonic: <a class="ix-ref" ix-ref="Pythonic" href="../persist/">Object Persistence</a></li>
<li>Pythonic: <a class="ix-ref" ix-ref="Pythonic" href="../bonus/">Bonus Material</a></li>
<li>R: <a class="ix-ref" ix-ref="R" href="../perf/">Performance Profiling</a></li>
<li>Recursive Enumeration pattern: <a class="ix-ref" ix-ref="Recursive Enumeration pattern" href="../pack/">A Package Manager</a></li>
<li>SHA-256 (hash function): <a class="ix-ref" ix-ref="SHA-256 (hash function)" href="../dup/">Finding Duplicate Files</a></li>
Expand Down Expand Up @@ -369,7 +369,7 @@ <h1>Appendix I: Index</h1>
<li>attention budget: <a class="ix-ref" ix-ref="attention budget" href="../bonus/">Bonus Material</a></li>
<li>attribute: <a class="ix-ref" ix-ref="attribute" href="../check/">An HTML Validator</a>, <a class="ix-ref" ix-ref="attribute" href="../template/">A Template Expander</a>, <a class="ix-ref" ix-ref="attribute" href="../layout/">Page Layout</a></li>
<li>backward-compatible: <a class="ix-ref" ix-ref="backward-compatible" href="../pack/">A Package Manager</a></li>
<li>base class: <a class="ix-ref" ix-ref="base class" href="../archive/">A File Archiver</a>, <a class="ix-ref" ix-ref="base class" href="../perf/">Performance Profiling</a>, <a class="ix-ref" ix-ref="base class" href="../persist/">Object Persistence</a></li>
<li>base class: <a class="ix-ref" ix-ref="base class" href="../archive/">A File Archiver</a>, <a class="ix-ref" ix-ref="base class" href="../perf/">Performance Profiling</a>, <a class="ix-ref" ix-ref="base class" href="../bonus/">Bonus Material</a></li>
<li>batch processing: <a class="ix-ref" ix-ref="batch processing" href="../perf/">Performance Profiling</a></li>
<li>benchmark: <a class="ix-ref" ix-ref="benchmark" href="../perf/">Performance Profiling</a></li>
<li>big endian: <a class="ix-ref" ix-ref="big endian" href="../binary/">Binary Data</a></li>
Expand Down Expand Up @@ -447,7 +447,7 @@ <h1>Appendix I: Index</h1>
<li>disassembler: <a class="ix-ref" ix-ref="disassembler" href="../vm/">A Virtual Machine</a></li>
<li>docstring: <a class="ix-ref" ix-ref="docstring" href="../perf/">Performance Profiling</a>, <a class="ix-ref" ix-ref="docstring" href="../bonus/">Bonus Material</a></li>
<li>dry run: <a class="ix-ref" ix-ref="dry run" href="../build/">A Build Manager</a></li>
<li>duck typing: <a class="ix-ref" ix-ref="duck typing" href="../persist/">Object Persistence</a></li>
<li>duck typing: <a class="ix-ref" ix-ref="duck typing" href="../bonus/">Bonus Material</a></li>
<li>dynamic dispatch: <a class="ix-ref" ix-ref="dynamic dispatch" href="../interp/">An Interpreter</a>, <a class="ix-ref" ix-ref="dynamic dispatch" href="../persist/">Object Persistence</a>, <a class="ix-ref" ix-ref="dynamic dispatch" href="../viewer/">A File Viewer</a></li>
<li>dynamic scoping: <a class="ix-ref" ix-ref="dynamic scoping" href="../func/">Functions and Closures</a></li>
<li>dynamic typing: <a class="ix-ref" ix-ref="dynamic typing" href="../test/">Running Tests</a></li>
Expand Down Expand Up @@ -481,7 +481,7 @@ <h1>Appendix I: Index</h1>
<li>header: <a class="ix-ref" ix-ref="header" href="../binary/">Binary Data</a></li>
<li>header (of HTTP request or response): <a class="ix-ref" ix-ref="header (of HTTP request or response)" href="../http/">Serving Web Pages</a></li>
<li>headless application: <a class="ix-ref" ix-ref="headless application" href="../undo/">Undo and Redo</a></li>
<li>helper class: <a class="ix-ref" ix-ref="helper class" href="../persist/">Object Persistence</a></li>
<li>helper class: <a class="ix-ref" ix-ref="helper class" href="../bonus/">Bonus Material</a></li>
<li>helper function: <a class="ix-ref" ix-ref="helper function" href="../archive/">A File Archiver</a>, <a class="ix-ref" ix-ref="helper function" href="../perf/">Performance Profiling</a>, <a class="ix-ref" ix-ref="helper function" href="../persist/">Object Persistence</a>, <a class="ix-ref" ix-ref="helper function" href="../undo/">Undo and Redo</a>, <a class="ix-ref" ix-ref="helper function" href="../debugger/">A Debugger</a></li>
<li>helper method: <a class="ix-ref" ix-ref="helper method" href="../glob/">Matching Patterns</a>, <a class="ix-ref" ix-ref="helper method" href="../db/">A Database</a></li>
<li>hexadecimal: <a class="ix-ref" ix-ref="hexadecimal" href="../dup/">Finding Duplicate Files</a>, <a class="ix-ref" ix-ref="hexadecimal" href="../test/">Running Tests</a>, <a class="ix-ref" ix-ref="hexadecimal" href="../archive/">A File Archiver</a>, <a class="ix-ref" ix-ref="hexadecimal" href="../binary/">Binary Data</a>, <a class="ix-ref" ix-ref="hexadecimal" href="../vm/">A Virtual Machine</a></li>
Expand All @@ -491,12 +491,12 @@ <h1>Appendix I: Index</h1>
<li>infinite recursion: <a class="ix-ref" ix-ref="infinite recursion" href="../protocols/">Protocols</a></li>
<li>infix notation: <a class="ix-ref" ix-ref="infix notation" href="../interp/">An Interpreter</a></li>
<li>inheritance: <a class="ix-ref" ix-ref="inheritance" href="../oop/">Objects and Classes</a>, <a class="ix-ref" ix-ref="inheritance" href="../glob/">Matching Patterns</a>, <a class="ix-ref" ix-ref="inheritance" href="../parse/">Parsing Text</a>, <a class="ix-ref" ix-ref="inheritance" href="../http/">Serving Web Pages</a>, <a class="ix-ref" ix-ref="inheritance" href="../viewer/">A File Viewer</a></li>
<li>instance: <a class="ix-ref" ix-ref="instance" href="../persist/">Object Persistence</a></li>
<li>instance: <a class="ix-ref" ix-ref="instance" href="../bonus/">Bonus Material</a></li>
<li>instruction pointer: <a class="ix-ref" ix-ref="instruction pointer" href="../vm/">A Virtual Machine</a></li>
<li>instruction set: <a class="ix-ref" ix-ref="instruction set" href="../vm/">A Virtual Machine</a></li>
<li>interpreter: <a class="ix-ref" ix-ref="interpreter" href="../interp/">An Interpreter</a>, <a class="ix-ref" ix-ref="interpreter" href="../func/">Functions and Closures</a>, <a class="ix-ref" ix-ref="interpreter" href="../protocols/">Protocols</a></li>
<li>intrinsic complexity: <a class="ix-ref" ix-ref="intrinsic complexity" href="../layout/">Page Layout</a></li>
<li>introspection: <a class="ix-ref" ix-ref="introspection" href="../test/">Running Tests</a>, <a class="ix-ref" ix-ref="introspection" href="../interp/">An Interpreter</a>, <a class="ix-ref" ix-ref="introspection" href="../persist/">Object Persistence</a>, <a class="ix-ref" ix-ref="introspection" href="../binary/">Binary Data</a></li>
<li>introspection: <a class="ix-ref" ix-ref="introspection" href="../test/">Running Tests</a>, <a class="ix-ref" ix-ref="introspection" href="../interp/">An Interpreter</a>, <a class="ix-ref" ix-ref="introspection" href="../binary/">Binary Data</a>, <a class="ix-ref" ix-ref="introspection" href="../bonus/">Bonus Material</a></li>
<li>iterator: <a class="ix-ref" ix-ref="iterator" href="../protocols/">Protocols</a></li>
<li>join: <a class="ix-ref" ix-ref="join" href="../perf/">Performance Profiling</a></li>
<li>join (tables): <a class="ix-ref" ix-ref="join (tables)" href="../perf/">Performance Profiling</a></li>
Expand Down Expand Up @@ -564,7 +564,7 @@ <h1>Appendix I: Index</h1>
<li>record: <a class="ix-ref" ix-ref="record" href="../db/">A Database</a></li>
<li>recursion: <a class="ix-ref" ix-ref="recursion" href="../oop/">Objects and Classes</a>, <a class="ix-ref" ix-ref="recursion" href="../interp/">An Interpreter</a>, <a class="ix-ref" ix-ref="recursion" href="../check/">An HTML Validator</a>, <a class="ix-ref" ix-ref="recursion" href="../template/">A Template Expander</a>, <a class="ix-ref" ix-ref="recursion" href="../lint/">A Code Linter</a>, <a class="ix-ref" ix-ref="recursion" href="../persist/">Object Persistence</a>, <a class="ix-ref" ix-ref="recursion" href="../pack/">A Package Manager</a></li>
<li>refactor: <a class="ix-ref" ix-ref="refactor" href="../glob/">Matching Patterns</a>, <a class="ix-ref" ix-ref="refactor" href="../archive/">A File Archiver</a>, <a class="ix-ref" ix-ref="refactor" href="../db/">A Database</a>, <a class="ix-ref" ix-ref="refactor" href="../build/">A Build Manager</a>, <a class="ix-ref" ix-ref="refactor" href="../ftp/">Transferring Files</a>, <a class="ix-ref" ix-ref="refactor" href="../viewer/">A File Viewer</a>, <a class="ix-ref" ix-ref="refactor" href="../debugger/">A Debugger</a></li>
<li>register (in code): <a class="ix-ref" ix-ref="register (in code)" href="../test/">Running Tests</a>, <a class="ix-ref" ix-ref="register (in code)" href="../persist/">Object Persistence</a>, <a class="ix-ref" ix-ref="register (in code)" href="../debugger/">A Debugger</a>, <a class="ix-ref" ix-ref="register (in code)" href="../bonus/">Bonus Material</a></li>
<li>register (in code): <a class="ix-ref" ix-ref="register (in code)" href="../test/">Running Tests</a>, <a class="ix-ref" ix-ref="register (in code)" href="../debugger/">A Debugger</a>, <a class="ix-ref" ix-ref="register (in code)" href="../bonus/">Bonus Material</a></li>
<li>register (in hardware): <a class="ix-ref" ix-ref="register (in hardware)" href="../vm/">A Virtual Machine</a></li>
<li>regular expression: <a class="ix-ref" ix-ref="regular expression" href="../glob/">Matching Patterns</a></li>
<li>relative error: <a class="ix-ref" ix-ref="relative error" href="../bonus/">Bonus Material</a></li>
Expand Down
32 changes: 16 additions & 16 deletions docs/persist/aliasing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ def save(self, thing):

self.seen.add(thing_id)
typename = type(thing).__name__
method = f"_{typename}"
method = f"save_{typename}"
assert hasattr(self, method), \
f"Unknown object type {typename}"
getattr(self, method)(thing)
# [/save]

def _bool(self, thing):
def save_bool(self, thing):
self._write("bool", id(thing), thing)

def _float(self, thing):
def save_float(self, thing):
self._write("float", id(thing), thing)

def _int(self, thing):
def save_int(self, thing):
self._write("int", id(thing), thing)

def _list(self, thing):
def save_list(self, thing):
self._write("list", id(thing), len(thing))
for item in thing:
self.save(item)

def _set(self, thing):
def save_set(self, thing):
self._write("set", id(thing), len(thing))
for item in thing:
self.save(item)

def _str(self, thing):
def save_str(self, thing):
lines = thing.split("\n")
self._write("str", id(thing), len(lines))
for line in lines:
print(line, file=self.writer)

def _dict(self, thing):
def save_dict(self, thing):
self._write("dict", id(thing), len(thing))
for (key, value) in thing.items():
self.save(key)
Expand All @@ -69,39 +69,39 @@ def load(self):
assert ident in self.seen
return self.seen[ident]

method = f"_{key}"
method = f"load_{key}"
assert hasattr(self, method), f"Unknown object type {key}"
return getattr(self, method)(ident, value)

def _bool(self, ident, value):
def load_bool(self, ident, value):
return super()._bool(value)

def _float(self, ident, value):
def load_float(self, ident, value):
return super()._float(value)

def _int(self, ident, value):
def load_int(self, ident, value):
return super()._int(value)

def _str(self, ident, value):
def load_str(self, ident, value):
return super()._str(value)

# [load_list]
def _list(self, ident, value):
def load_list(self, ident, value):
result = []
self.seen[ident] = result
for _ in range(int(value)):
result.append(self.load())
return result
# [/load_list]

def _set(self, ident, value):
def load_set(self, ident, value):
result = set()
self.seen[ident] = result
for _ in range(int(value)):
result.add(self.load())
return result

def _dict(self, ident, value):
def load_dict(self, ident, value):
result = {}
self.seen[ident] = result
for _ in range(int(value)):
Expand Down
2 changes: 1 addition & 1 deletion docs/persist/aliasing_wrong.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def load(self):
assert ident in self.seen
return self.seen[ident]

method = f"_{key}"
method = f"load_{key}"
assert hasattr(self, method), f"Unknown object type {key}"
result = getattr(self, method)(value)
self.seen[ident] = result
Expand Down
4 changes: 4 additions & 0 deletions docs/persist/attr.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ex has missing False
ex has label True with value thing
ex has get_size True
result of calling method 5
13 changes: 13 additions & 0 deletions docs/persist/attr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Example:
def __init__(self, label):
self.label = label

def get_size(self):
return len(self.label)

ex = Example("thing")
print("ex has missing", hasattr(ex, "missing"))
print("ex has label", hasattr(ex, "label"), "with value", getattr(ex, "label"))
print("ex has get_size", hasattr(ex, "get_size"))
method = getattr(ex, "get_size")
print("result of calling method", method())
4 changes: 2 additions & 2 deletions docs/persist/concept_map.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 922a7d8

Please sign in to comment.