Skip to content

Commit bea0a92

Browse files
committed
reorg
1 parent c5fff6e commit bea0a92

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed
249 KB
Loading
406 KB
Binary file not shown.

martelli/borg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Borg:
2+
3+
_estado_compartilhado = {}
4+
5+
def __new__(cls, *args, **kwargs):
6+
obj = super().__new__(cls, *args, **kwargs)
7+
obj.__dict__ = cls._estado_compartilhado
8+
return obj

martelli/embrulho.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class EmbrulhoRestritor:
2+
3+
def __init__(self, embrulhado, bloqueios):
4+
self._embrulhado = embrulhado
5+
self._bloqueios = bloqueios
6+
7+
def __getattr__(self, nome):
8+
if nome in self._bloqueios:
9+
msg = 'atributo bloqueado: {!r}'.format(nome)
10+
raise AttributeError(msg)
11+
else:
12+
return getattr(self._embrulhado, nome)
13+
14+
def exportar(self):
15+
return {'embrulhado': self._embrulhado,
16+
'bloqueios': self._bloqueios}
17+
18+
19+
class Cao:
20+
21+
def latir(self):
22+
print('Au!')
23+
24+
def morder(self):
25+
print('Nhac!')

martelli/singleton.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
class Singleton:
3+
4+
def __new__(cls, *args, **kwargs):
5+
if not hasattr(cls, '_a_instancia'):
6+
cls._a_instancia = super().__new__(cls, *args, **kwargs)
7+
return cls._a_instancia
8+

0 commit comments

Comments
 (0)