update from Atlas

This commit is contained in:
Luciano Ramalho 2015-04-02 10:34:57 -03:00
parent 573e1a94c4
commit cf96836b60
28 changed files with 8 additions and 59 deletions

View File

@ -1,16 +1,16 @@
"""
>>> bus1 = HountedBus(['Alice', 'Bill'])
>>> bus1 = HauntedBus(['Alice', 'Bill'])
>>> bus1.passengers
['Alice', 'Bill']
>>> bus1.pick('Charlie')
>>> bus1.drop('Alice')
>>> bus1.passengers
['Bill', 'Charlie']
>>> bus2 = HountedBus()
>>> bus2 = HauntedBus()
>>> bus2.pick('Carrie')
>>> bus2.passengers
['Carrie']
>>> bus3 = HountedBus()
>>> bus3 = HauntedBus()
>>> bus3.passengers
['Carrie']
>>> bus3.pick('Dave')
@ -22,18 +22,18 @@ True
['Bill', 'Charlie']
>>> dir(HountedBus.__init__) # doctest: +ELLIPSIS
>>> dir(HauntedBus.__init__) # doctest: +ELLIPSIS
['__annotations__', '__call__', ..., '__defaults__', ...]
>>> HountedBus.__init__.__defaults__
>>> HauntedBus.__init__.__defaults__
(['Carrie', 'Dave'],)
>>> HountedBus.__init__.__defaults__[0] is bus2.passengers
>>> HauntedBus.__init__.__defaults__[0] is bus2.passengers
True
"""
# BEGIN HAUNTED_BUS_CLASS
class HountedBus:
"""A bus model hounted by ghost passengers"""
class HauntedBus:
"""A bus model haunted by ghost passengers"""
def __init__(self, passengers=[]): # <1>
self.passengers = passengers # <2>

View File

@ -1,25 +0,0 @@
import java.lang.reflect.Field;
public class AcessaPrivado {
public static void main(String[] args) {
ObjetoSecreto oSecreto = new ObjetoSecreto("senha super secreta");
Field campoPrivado = null;
try {
campoPrivado = ObjetoSecreto.class.getDeclaredField("escondido");
}
catch (NoSuchFieldException e) {
System.err.println(e);
System.exit(1);
}
campoPrivado.setAccessible(true); // arrombamos a porta
try {
String tavaEscondido = (String) campoPrivado.get(oSecreto);
System.out.println("oSecreto.escondido = " + tavaEscondido);
}
catch (IllegalAccessException e) {
// esta exceção nao acontece porque fizemos setAcessible(true)
System.err.println(e);
}
}
}

View File

@ -1,9 +0,0 @@
public class ObjetoSecreto {
private String escondido = "";
private String oculto = "dado ultra secreto";
public ObjetoSecreto(String texto) {
this.escondido = texto;
}
}

View File

@ -1,6 +0,0 @@
import ObjetoSecreto
oSecreto = ObjetoSecreto('senha super secreta')
campoPrivado = ObjetoSecreto.getDeclaredField('escondido')
campoPrivado.setAccessible(True) # arrombamos a porta
print 'oSecreto.escondido =', campoPrivado.get(oSecreto)

View File

@ -1,11 +0,0 @@
from java.lang.reflect import Modifier
import ObjetoSecreto
oSecreto = ObjetoSecreto('senha super secreta')
campos = ObjetoSecreto.getDeclaredFields()
for campo in campos:
# so campos privados!
if Modifier.isPrivate(campo.getModifiers()):
print campo
campo.setAccessible(True) # arrombamos a porta
print '\t', campo.getName(), '=', campo.get(oSecreto)