Skip to content

Your code is too weak for PEP8. You lack DISCIPLINE #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 3-tier.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def main():
# eggs
# milk
# cheese
#
#
# PRODUCT INFORMATION:
# Name: Cheese, Price: 2.00, Quantity: 10
# PRODUCT INFORMATION:
Expand Down
5 changes: 5 additions & 0 deletions abstract_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


class PetShop:

"""A pet shop"""

def __init__(self, animal_factory=None):
Expand All @@ -30,6 +31,7 @@ def show_pet(self):
# Stuff that our factory makes

class Dog:

def speak(self):
return "woof"

Expand All @@ -38,6 +40,7 @@ def __str__(self):


class Cat:

def speak(self):
return "meow"

Expand All @@ -48,6 +51,7 @@ def __str__(self):
# Factory classes

class DogFactory:

def get_pet(self):
return Dog()

Expand All @@ -56,6 +60,7 @@ def get_food(self):


class CatFactory:

def get_pet(self):
return Cat()

Expand Down
6 changes: 6 additions & 0 deletions adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class Dog(object):

def __init__(self):
self.name = "Dog"

Expand All @@ -15,6 +16,7 @@ def bark(self):


class Cat(object):

def __init__(self):
self.name = "Cat"

Expand All @@ -23,6 +25,7 @@ def meow(self):


class Human(object):

def __init__(self):
self.name = "Human"

Expand All @@ -31,6 +34,7 @@ def speak(self):


class Car(object):

def __init__(self):
self.name = "Car"

Expand All @@ -39,6 +43,7 @@ def make_noise(self, octane_level):


class Adapter(object):

"""
Adapts an object by replacing methods.
Usage:
Expand All @@ -63,6 +68,7 @@ class Adapter(object):
A Human goes 'hello'
A Car goes vroom!!!
"""

def __init__(self, obj, adapted_methods):
"""We set the adapted methods in the object's dict"""
self.obj = obj
Expand Down
3 changes: 3 additions & 0 deletions bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@

# ConcreteImplementor 1/2
class DrawingAPI1(object):

def draw_circle(self, x, y, radius):
print('API1.circle at {}:{} radius {}'.format(x, y, radius))


# ConcreteImplementor 2/2
class DrawingAPI2(object):

def draw_circle(self, x, y, radius):
print('API2.circle at {}:{} radius {}'.format(x, y, radius))


# Refined Abstraction
class CircleShape(object):

def __init__(self, x, y, radius, drawing_api):
self._x = x
self._y = y
Expand Down
7 changes: 6 additions & 1 deletion builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# Director
class Director(object):

def __init__(self):
self.builder = None

Expand All @@ -23,6 +24,7 @@ def get_building(self):

# Abstract Builder
class Builder(object):

def __init__(self):
self.building = None

Expand All @@ -32,6 +34,7 @@ def new_building(self):

# Concrete Builder
class BuilderHouse(Builder):

def build_floor(self):
self.building.floor = 'One'

Expand All @@ -40,15 +43,17 @@ def build_size(self):


class BuilderFlat(Builder):

def build_floor(self):
self.building.floor = 'More than One'

def build_size(self):
self.building.size = 'Small'


# Product
class Building(object):

def __init__(self):
self.floor = None
self.size = None
Expand Down
1 change: 1 addition & 0 deletions catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


class Catalog():

"""
catalog of multiple static methods that are executed depending on an init
parameter
Expand Down
5 changes: 5 additions & 0 deletions chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@


class Handler:

def successor(self, successor):
self.successor = successor


class ConcreteHandler1(Handler):

def handle(self, request):
if 0 < request <= 10:
print('request {} handled in handler 1'.format(request))
Expand All @@ -18,6 +20,7 @@ def handle(self, request):


class ConcreteHandler2(Handler):

def handle(self, request):
if 10 < request <= 20:
print('request {} handled in handler 2'.format(request))
Expand All @@ -26,6 +29,7 @@ def handle(self, request):


class ConcreteHandler3(Handler):

def handle(self, request):
if 20 < request <= 30:
print('request {} handled in handler 3'.format(request))
Expand All @@ -34,6 +38,7 @@ def handle(self, request):


class Client:

def __init__(self):
h1 = ConcreteHandler1()
h2 = ConcreteHandler2()
Expand Down
1 change: 1 addition & 0 deletions command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


class MoveFileCommand(object):

def __init__(self, src, dest):
self.src = src
self.dest = dest
Expand Down
2 changes: 2 additions & 0 deletions composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def denormalize(val):


class SpecialDict(dict):

""" A dictionary type which allows direct attribute
access to its keys """

Expand Down Expand Up @@ -71,6 +72,7 @@ def __setattr__(self, name, value):


class CompositeDict(SpecialDict):

""" A class which works like a hierarchical dictionary.
This class is based on the Composite design-pattern """

Expand Down
3 changes: 3 additions & 0 deletions decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


class foo_decorator(object):

def __init__(self, decoratee):
self._decoratee = decoratee

Expand All @@ -17,6 +18,7 @@ def __getattr__(self, name):


class undecorated_foo(object):

def f1(self):
print("original f1")

Expand All @@ -26,6 +28,7 @@ def f2(self):

@foo_decorator
class decorated_foo(object):

def f1(self):
print("original f1")

Expand Down
4 changes: 4 additions & 0 deletions facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Complex Parts
class TC1:

def run(self):
print("###### In Test 1 ######")
time.sleep(SLEEP)
Expand All @@ -21,6 +22,7 @@ def run(self):


class TC2:

def run(self):
print("###### In Test 2 ######")
time.sleep(SLEEP)
Expand All @@ -34,6 +36,7 @@ def run(self):


class TC3:

def run(self):
print("###### In Test 3 ######")
time.sleep(SLEEP)
Expand All @@ -48,6 +51,7 @@ def run(self):

# Facade
class TestRunner:

def __init__(self):
self.tc1 = TC1()
self.tc2 = TC2()
Expand Down
4 changes: 4 additions & 0 deletions factory_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@


class GreekGetter:

"""A simple localizer a la gettext"""

def __init__(self):
self.trans = dict(dog="σκύλος", cat="γάτα")

Expand All @@ -18,7 +20,9 @@ def get(self, msgid):


class EnglishGetter:

"""Simply echoes the msg ids"""

def get(self, msgid):
return str(msgid)

Expand Down
1 change: 1 addition & 0 deletions flyweight.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class Card(object):

"""The object pool. Has builtin reference counting"""
_CardPool = weakref.WeakValueDictionary()

Expand Down
5 changes: 3 additions & 2 deletions graph_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


class GraphSearch:

"""Graph search emulation in python, from source
http://www.python.org/doc/essays/graphs/"""

Expand Down Expand Up @@ -62,7 +63,7 @@ def find_shortest_path(self, start, end, path=[]):
shortest = newpath
return shortest

#example of graph usage
# example of graph usage
graph = {'A': ['B', 'C'],
'B': ['C', 'D'],
'C': ['D'],
Expand All @@ -71,7 +72,7 @@ def find_shortest_path(self, start, end, path=[]):
'F': ['C']
}

#initialization of new graph search object
# initialization of new graph search object
graph1 = GraphSearch(graph)


Expand Down
4 changes: 2 additions & 2 deletions iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def count_to(count):

### OUTPUT ###
# Counting to two...
# one two
# one two
# Counting to five...
# one two three four five
# one two three four five
6 changes: 5 additions & 1 deletion mediator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


class TC:

def __init__(self):
self._tm = None
self._bProblem = 0
Expand Down Expand Up @@ -40,6 +41,7 @@ def setProblem(self, value):


class Reporter:

def __init__(self):
self._tm = None

Expand All @@ -56,13 +58,14 @@ def setTM(self, tm):


class DB:

def __init__(self):
self._tm = None

def insert(self):
print("Inserting the execution begin status in the Database")
time.sleep(0.1)
#Following code is to simulate a communication from DB to TC
# Following code is to simulate a communication from DB to TC
if random.randrange(1, 4) == 3:
return -1

Expand All @@ -75,6 +78,7 @@ def setTM(self, tm):


class TestManager:

def __init__(self):
self._reporter = None
self._db = None
Expand Down
Loading