Browse Source

Your code is too weak for PEP8. You lack DISCIPLINE

Arnold Schwarzenegger 11 years ago
parent
commit
5d794ceecb
27 changed files with 83 additions and 15 deletions
  1. 1 1
      3-tier.py
  2. 5 0
      abstract_factory.py
  3. 6 0
      adapter.py
  4. 3 0
      bridge.py
  5. 6 1
      builder.py
  6. 1 0
      catalog.py
  7. 5 0
      chain.py
  8. 1 0
      command.py
  9. 2 0
      composite.py
  10. 3 0
      decorator.py
  11. 4 0
      facade.py
  12. 4 0
      factory_method.py
  13. 1 0
      flyweight.py
  14. 3 2
      graph_search.py
  15. 2 2
      iterator.py
  16. 5 1
      mediator.py
  17. 5 1
      memento.py
  18. 4 4
      mvc.py
  19. 1 0
      null.py
  20. 4 0
      observer.py
  21. 1 0
      pool.py
  22. 1 0
      prototype.py
  23. 2 0
      proxy.py
  24. 3 0
      publish_subscribe.py
  25. 5 0
      state.py
  26. 1 0
      strategy.py
  27. 4 3
      visitor.py

+ 1 - 1
3-tier.py

@@ -62,7 +62,7 @@ if __name__ == '__main__':
 # eggs
 # milk
 # cheese
-# 
+#
 # PRODUCT INFORMATION:
 # Name: Cheese, Price: 2.00, Quantity: 10
 # PRODUCT INFORMATION:

+ 5 - 0
abstract_factory.py

@@ -9,6 +9,7 @@ import random
 
 
 class PetShop:
+
     """A pet shop"""
 
     def __init__(self, animal_factory=None):
@@ -30,6 +31,7 @@ class PetShop:
 # Stuff that our factory makes
 
 class Dog:
+
     def speak(self):
         return "woof"
 
@@ -38,6 +40,7 @@ class Dog:
 
 
 class Cat:
+
     def speak(self):
         return "meow"
 
@@ -48,6 +51,7 @@ class Cat:
 # Factory classes
 
 class DogFactory:
+
     def get_pet(self):
         return Dog()
 
@@ -56,6 +60,7 @@ class DogFactory:
 
 
 class CatFactory:
+
     def get_pet(self):
         return Cat()
 

+ 6 - 0
adapter.py

@@ -7,6 +7,7 @@ import os
 
 
 class Dog(object):
+
     def __init__(self):
         self.name = "Dog"
 
@@ -15,6 +16,7 @@ class Dog(object):
 
 
 class Cat(object):
+
     def __init__(self):
         self.name = "Cat"
 
@@ -23,6 +25,7 @@ class Cat(object):
 
 
 class Human(object):
+
     def __init__(self):
         self.name = "Human"
 
@@ -31,6 +34,7 @@ class Human(object):
 
 
 class Car(object):
+
     def __init__(self):
         self.name = "Car"
 
@@ -39,6 +43,7 @@ class Car(object):
 
 
 class Adapter(object):
+
     """
     Adapts an object by replacing methods.
     Usage:
@@ -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

+ 3 - 0
bridge.py

@@ -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

+ 6 - 1
builder.py

@@ -9,6 +9,7 @@ https://gist.github.com/420905#file_builder_python.py
 
 # Director
 class Director(object):
+
     def __init__(self):
         self.builder = None
 
@@ -23,6 +24,7 @@ class Director(object):
 
 # Abstract Builder
 class Builder(object):
+
     def __init__(self):
         self.building = None
 
@@ -32,6 +34,7 @@ class Builder(object):
 
 # Concrete Builder
 class BuilderHouse(Builder):
+
     def build_floor(self):
         self.building.floor = 'One'
 
@@ -40,15 +43,17 @@ class BuilderHouse(Builder):
 
 
 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

+ 1 - 0
catalog.py

@@ -10,6 +10,7 @@ __gist__ = "<https://gist.github.com/diopib/7679559>"
 
 
 class Catalog():
+
     """
     catalog of multiple static methods that are executed depending on an init
     parameter

+ 5 - 0
chain.py

@@ -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))
@@ -18,6 +20,7 @@ class ConcreteHandler1(Handler):
 
 
 class ConcreteHandler2(Handler):
+
     def handle(self, request):
         if 10 < request <= 20:
             print('request {} handled in handler 2'.format(request))
@@ -26,6 +29,7 @@ class ConcreteHandler2(Handler):
 
 
 class ConcreteHandler3(Handler):
+
     def handle(self, request):
         if 20 < request <= 30:
             print('request {} handled in handler 3'.format(request))
@@ -34,6 +38,7 @@ class ConcreteHandler3(Handler):
 
 
 class Client:
+
     def __init__(self):
         h1 = ConcreteHandler1()
         h2 = ConcreteHandler2()

+ 1 - 0
command.py

@@ -5,6 +5,7 @@ import os
 
 
 class MoveFileCommand(object):
+
     def __init__(self, src, dest):
         self.src = src
         self.dest = dest

+ 2 - 0
composite.py

@@ -37,6 +37,7 @@ def denormalize(val):
 
 
 class SpecialDict(dict):
+
     """ A dictionary type which allows direct attribute
     access to its keys """
 
@@ -71,6 +72,7 @@ class SpecialDict(dict):
 
 
 class CompositeDict(SpecialDict):
+
     """ A class which works like a hierarchical dictionary.
     This class is based on the Composite design-pattern """
 

+ 3 - 0
decorator.py

@@ -5,6 +5,7 @@
 
 
 class foo_decorator(object):
+
     def __init__(self, decoratee):
         self._decoratee = decoratee
 
@@ -17,6 +18,7 @@ class foo_decorator(object):
 
 
 class undecorated_foo(object):
+
     def f1(self):
         print("original f1")
 
@@ -26,6 +28,7 @@ class undecorated_foo(object):
 
 @foo_decorator
 class decorated_foo(object):
+
     def f1(self):
         print("original f1")
 

+ 4 - 0
facade.py

@@ -8,6 +8,7 @@ SLEEP = 0.5
 
 # Complex Parts
 class TC1:
+
     def run(self):
         print("###### In Test 1 ######")
         time.sleep(SLEEP)
@@ -21,6 +22,7 @@ class TC1:
 
 
 class TC2:
+
     def run(self):
         print("###### In Test 2 ######")
         time.sleep(SLEEP)
@@ -34,6 +36,7 @@ class TC2:
 
 
 class TC3:
+
     def run(self):
         print("###### In Test 3 ######")
         time.sleep(SLEEP)
@@ -48,6 +51,7 @@ class TC3:
 
 # Facade
 class TestRunner:
+
     def __init__(self):
         self.tc1 = TC1()
         self.tc2 = TC2()

+ 4 - 0
factory_method.py

@@ -5,7 +5,9 @@
 
 
 class GreekGetter:
+
     """A simple localizer a la gettext"""
+
     def __init__(self):
         self.trans = dict(dog="σκύλος", cat="γάτα")
 
@@ -18,7 +20,9 @@ class GreekGetter:
 
 
 class EnglishGetter:
+
     """Simply echoes the msg ids"""
+
     def get(self, msgid):
         return str(msgid)
 

+ 1 - 0
flyweight.py

@@ -7,6 +7,7 @@ import weakref
 
 
 class Card(object):
+
     """The object pool. Has builtin reference counting"""
     _CardPool = weakref.WeakValueDictionary()
 

+ 3 - 2
graph_search.py

@@ -3,6 +3,7 @@
 
 
 class GraphSearch:
+
     """Graph search emulation in python, from source
     http://www.python.org/doc/essays/graphs/"""
 
@@ -62,7 +63,7 @@ class GraphSearch:
                         shortest = newpath
         return shortest
 
-#example of graph usage
+# example of graph usage
 graph = {'A': ['B', 'C'],
          'B': ['C', 'D'],
          'C': ['D'],
@@ -71,7 +72,7 @@ graph = {'A': ['B', 'C'],
          'F': ['C']
          }
 
-#initialization of new graph search object
+# initialization of new graph search object
 graph1 = GraphSearch(graph)
 
 

+ 2 - 2
iterator.py

@@ -32,6 +32,6 @@ print()
 
 ### OUTPUT ###
 # Counting to two...
-# one two 
+# one two
 # Counting to five...
-# one two three four five 
+# one two three four five

+ 5 - 1
mediator.py

@@ -8,6 +8,7 @@ import time
 
 
 class TC:
+
     def __init__(self):
         self._tm = None
         self._bProblem = 0
@@ -40,6 +41,7 @@ class TC:
 
 
 class Reporter:
+
     def __init__(self):
         self._tm = None
 
@@ -56,13 +58,14 @@ class Reporter:
 
 
 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
 
@@ -75,6 +78,7 @@ class DB:
 
 
 class TestManager:
+
     def __init__(self):
         self._reporter = None
         self._db = None

+ 5 - 1
memento.py

@@ -16,6 +16,7 @@ def Memento(obj, deep=False):
 
 
 class Transaction:
+
     """A transaction guard. This is really just
       syntactic suggar arount a memento closure.
       """
@@ -34,9 +35,11 @@ class Transaction:
 
 
 class transactional(object):
+
     """Adds transactional semantics to methods. Methods decorated  with
     @transactional will rollback to entry state upon exceptions.
     """
+
     def __init__(self, method):
         self.method = method
 
@@ -52,6 +55,7 @@ class transactional(object):
 
 
 class NumObj(object):
+
     def __init__(self, value):
         self.value = value
 
@@ -116,7 +120,7 @@ if __name__ == '__main__':
 #   File "memento.py", line 47, in transaction
 #     return self.method(obj, *args, **kwargs)
 #   File "memento.py", line 67, in DoStuff
-#     self.Increment()     # <- will fail and rollback
+# self.Increment()     # <- will fail and rollback
 #   File "memento.py", line 62, in Increment
 #     self.value += 1
 # TypeError: Can't convert 'int' object to str implicitly

+ 4 - 4
mvc.py

@@ -61,14 +61,14 @@ if __name__ == '__main__':
 # cheese
 # eggs
 # milk
-# 
+#
 # PRODUCT INFORMATION:
 # Name: Cheese, Price: 2.00, Quantity: 10
-# 
+#
 # PRODUCT INFORMATION:
 # Name: Eggs, Price: 0.20, Quantity: 100
-# 
+#
 # PRODUCT INFORMATION:
 # Name: Milk, Price: 1.50, Quantity: 10
-# 
+#
 # That product "arepas" does not exist in the records

+ 1 - 0
null.py

@@ -5,6 +5,7 @@
 
 
 class Null:
+
     def __init__(self, *args, **kwargs):
         """Ignore parameters."""
         return None

+ 4 - 0
observer.py

@@ -5,6 +5,7 @@
 
 
 class Subject(object):
+
     def __init__(self):
         self._observers = []
 
@@ -26,6 +27,7 @@ class Subject(object):
 
 # Example usage
 class Data(Subject):
+
     def __init__(self, name=''):
         Subject.__init__(self)
         self.name = name
@@ -42,12 +44,14 @@ class Data(Subject):
 
 
 class HexViewer:
+
     def update(self, subject):
         print('HexViewer: Subject %s has data 0x%x' %
               (subject.name, subject.data))
 
 
 class DecimalViewer:
+
     def update(self, subject):
         print('DecimalViewer: Subject %s has data %d' %
               (subject.name, subject.data))

+ 1 - 0
pool.py

@@ -5,6 +5,7 @@
 
 
 class QueueObject():
+
     def __init__(self, queue, auto_get=False):
         self._queue = queue
         self.object = self._queue.get() if auto_get else None

+ 1 - 0
prototype.py

@@ -5,6 +5,7 @@ import copy
 
 
 class Prototype:
+
     def __init__(self):
         self._objects = {}
 

+ 2 - 0
proxy.py

@@ -5,6 +5,7 @@ import time
 
 
 class SalesManager:
+
     def work(self):
         print("Sales Manager working...")
 
@@ -13,6 +14,7 @@ class SalesManager:
 
 
 class Proxy:
+
     def __init__(self):
         self.busy = 'No'
         self.sales = None

+ 3 - 0
publish_subscribe.py

@@ -8,6 +8,7 @@ Author: https://github.com/HanWenfang
 
 
 class Provider:
+
     def __init__(self):
         self.msg_queue = []
         self.subscribers = {}
@@ -34,6 +35,7 @@ class Provider:
 
 
 class Publisher:
+
     def __init__(self, msg_center):
         self.provider = msg_center
 
@@ -42,6 +44,7 @@ class Publisher:
 
 
 class Subscriber:
+
     def __init__(self, name, msg_center):
         self.name = name
         self.provider = msg_center

+ 5 - 0
state.py

@@ -4,6 +4,7 @@
 
 
 class State(object):
+
     """Base state. This is to share functionality"""
 
     def scan(self):
@@ -15,6 +16,7 @@ class State(object):
 
 
 class AmState(State):
+
     def __init__(self, radio):
         self.radio = radio
         self.stations = ["1250", "1380", "1510"]
@@ -27,6 +29,7 @@ class AmState(State):
 
 
 class FmState(State):
+
     def __init__(self, radio):
         self.radio = radio
         self.stations = ["81.3", "89.1", "103.9"]
@@ -39,7 +42,9 @@ class FmState(State):
 
 
 class Radio(object):
+
     """A radio.     It has a scan button, and an AM/FM toggle switch."""
+
     def __init__(self):
         """We have an AM state and an FM state"""
         self.amstate = AmState(self)

+ 1 - 0
strategy.py

@@ -12,6 +12,7 @@ import types
 
 
 class StrategyExample:
+
     def __init__(self, func=None):
         self.name = 'Strategy Example 0'
         if func is not None:

+ 4 - 3
visitor.py

@@ -18,10 +18,11 @@ class C(A, B):
 
 
 class Visitor(object):
+
     def visit(self, node, *args, **kwargs):
         meth = None
         for cls in node.__class__.__mro__:
-            meth_name = 'visit_'+cls.__name__
+            meth_name = 'visit_' + cls.__name__
             meth = getattr(self, meth_name, None)
             if meth:
                 break
@@ -31,10 +32,10 @@ class Visitor(object):
         return meth(node, *args, **kwargs)
 
     def generic_visit(self, node, *args, **kwargs):
-        print('generic_visit '+node.__class__.__name__)
+        print('generic_visit ' + node.__class__.__name__)
 
     def visit_B(self, node, *args, **kwargs):
-        print('visit_B '+node.__class__.__name__)
+        print('visit_B ' + node.__class__.__name__)
 
 
 a = A()