Skip to content

Commit 51476cb

Browse files
committed
doctest para EmbrulhoRestritor
1 parent ddb7c3b commit 51476cb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Martelli/embrulho.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
"""
2+
A classe EmbrulhoRestritor demonstra o uso de composição para limitar
3+
o acesso a atributos de instâncias de outra classe qualquer.
4+
5+
>>> rex = Cao()
6+
>>> rex.latir()
7+
Au!
8+
>>> rex.morder()
9+
Nhac!
10+
>>> rex2 = EmbrulhoRestritor(rex, ['morder'])
11+
>>> rex2.latir()
12+
Au!
13+
>>> rex2.morder()
14+
Traceback (most recent call last):
15+
...
16+
AttributeError: atributo bloqueado 'morder'
17+
18+
"""
19+
20+
121
class EmbrulhoRestritor:
222

323
def __init__(self, embrulhado, bloqueios):
@@ -6,7 +26,7 @@ def __init__(self, embrulhado, bloqueios):
626

727
def __getattr__(self, nome):
828
if nome in self._bloqueios:
9-
msg = 'atributo bloqueado: {!r}'.format(nome)
29+
msg = 'atributo bloqueado {!r}'.format(nome)
1030
raise AttributeError(msg)
1131
else:
1232
return getattr(self._embrulhado, nome)

0 commit comments

Comments
 (0)