From 2a745639cabfee0f366405c6332b410ce7de446f Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Tue, 22 Apr 2014 15:25:15 +0200 Subject: [PATCH] Fix PEP8 on timeside/ with autopep8 --- timeside/api.py | 12 ++++++++++-- timeside/component.py | 24 +++++++++++++++++++----- timeside/core.py | 37 +++++++++++++++++++++---------------- timeside/exceptions.py | 6 ++++++ timeside/metadata.py | 3 +-- 5 files changed, 57 insertions(+), 25 deletions(-) diff --git a/timeside/api.py b/timeside/api.py index b214023..97447fb 100644 --- a/timeside/api.py +++ b/timeside/api.py @@ -24,6 +24,7 @@ from timeside.component import Interface class IProcessor(Interface): + """Common processor interface""" @staticmethod @@ -102,6 +103,7 @@ class IProcessor(Interface): class IEncoder(IProcessor): + """Encoder driver interface. Each encoder is expected to support a specific format.""" @@ -114,7 +116,8 @@ class IEncoder(IProcessor): True when end-of-data is reached.""" # implementation: the constructor must always accept the output argument. It may - # accept extra arguments such as bitrate, depth, etc.., but these must be optionnal + # accept extra arguments such as bitrate, depth, etc.., but these must + # be optionnal @staticmethod def format(): @@ -149,6 +152,7 @@ class IEncoder(IProcessor): class IDecoder(IProcessor): + """Decoder driver interface. Decoders are different of encoders in that a given driver may support several input formats, hence this interface doesn't export any static method, all informations are dynamic.""" @@ -173,7 +177,9 @@ class IDecoder(IProcessor): def mime_type(): """Return the mime type corresponding to this decoded format""" + class IGrapher(IProcessor): + """Media item visualizer driver interface""" # implementation: graphers which need to know the total number of frames @@ -200,6 +206,7 @@ class IGrapher(IProcessor): class IAnalyzer(IProcessor): + """Media item analyzer driver interface. This interface is abstract, it doesn't describe a particular type of analyzer but is rather meant to group analyzers. In particular, the way the result is returned may greatly vary from sub-interface @@ -223,6 +230,7 @@ class IAnalyzer(IProcessor): class IValueAnalyzer(IAnalyzer): + """Interface for analyzers which return a single numeric value from result()""" def result(): @@ -239,6 +247,7 @@ class IValueAnalyzer(IAnalyzer): class IEffect(IProcessor): + """Effect processor interface""" def __init__(self): @@ -248,4 +257,3 @@ class IEffect(IProcessor): @staticmethod def name(): """Return the effect name""" - diff --git a/timeside/component.py b/timeside/component.py index d5daa3f..7f72852 100644 --- a/timeside/component.py +++ b/timeside/component.py @@ -45,18 +45,23 @@ __all__ = ['Component', 'MetaComponent', 'implements', 'abstract', 'interfacedoc', 'Interface', 'implementations', 'ComponentError'] + class Interface(object): + """Marker base class for interfaces.""" + def implements(*interfaces): """Registers the interfaces implemented by a component when placed in the class header""" MetaComponent.implements.extend(interfaces) + def abstract(): """Declare a component as abstract when placed in the class header""" MetaComponent.abstract = True + def implementations(interface, recurse=True, abstract=False): """Returns the components implementing interface, and if recurse, any of the descendants of interface. If abstract is True, also return the @@ -65,22 +70,26 @@ def implementations(interface, recurse=True, abstract=False): find_implementations(interface, recurse, abstract, result) return result + def interfacedoc(func): if isinstance(func, staticmethod): - raise ComponentError("@interfacedoc can't handle staticmethod (try to put @staticmethod above @interfacedoc)") + raise ComponentError( + "@interfacedoc can't handle staticmethod (try to put @staticmethod above @interfacedoc)") if not func.__doc__: func.__doc__ = "@interfacedoc" func._interfacedoc = True return func + class MetaComponent(type): + """Metaclass of the Component class, used mainly to register the interface declared to be implemented by a component.""" - implementations = [] - implements = [] - abstract = False + implementations = [] + implements = [] + abstract = False def __new__(cls, name, bases, d): new_class = type.__new__(cls, name, bases, d) @@ -110,14 +119,17 @@ class MetaComponent(type): member.__doc__ = if_member.__doc__ MetaComponent.implements = [] - MetaComponent.abstract = False + MetaComponent.abstract = False return new_class + class Component(object): + """Base class of all components""" __metaclass__ = MetaComponent + def extend_unique(list1, list2): """Extend list1 with list2 as list.extend(), but doesn't append duplicates to list1""" @@ -125,6 +137,7 @@ def extend_unique(list1, list2): if item not in list1: list1.append(item) + def find_implementations(interface, recurse, abstract, result): """Find implementations of an interface or of one of its descendants and extend result with the classes found.""" @@ -138,5 +151,6 @@ def find_implementations(interface, recurse, abstract, result): for i in subinterfaces: find_implementations(i, recurse, abstract, result) + class ComponentError(Exception): pass diff --git a/timeside/core.py b/timeside/core.py index b5317aa..6ef34f4 100644 --- a/timeside/core.py +++ b/timeside/core.py @@ -39,6 +39,7 @@ _processors = {} class MetaProcessor(MetaComponent): + """Metaclass of the Processor class, used mainly for ensuring that processor id's are wellformed and unique""" @@ -57,10 +58,10 @@ class MetaProcessor(MetaComponent): pass else: raise ApiError("%s and %s have the same id: '%s'" - % (new_class.__name__, _processors[id].__name__, id)) + % (new_class.__name__, _processors[id].__name__, id)) if not MetaProcessor.valid_id.match(id): raise ApiError("%s has a malformed id: '%s'" - % (new_class.__name__, id)) + % (new_class.__name__, id)) _processors[id] = new_class @@ -68,6 +69,7 @@ class MetaProcessor(MetaComponent): class Processor(Component): + """Base component class of all processors @@ -92,10 +94,10 @@ class Processor(Component): @interfacedoc def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None): - self.source_channels = channels - self.source_samplerate = samplerate - self.source_blocksize = blocksize - self.source_totalframes = totalframes + self.source_channels = channels + self.source_samplerate = samplerate + self.source_blocksize = blocksize + self.source_totalframes = totalframes # If empty Set default values for input_* attributes # may be setted by the processor during __init__() @@ -108,7 +110,6 @@ class Processor(Component): if not hasattr(self, 'input_stepsize'): self.input_stepsize = self.source_blocksize - # default channels(), samplerate() and blocksize() implementations returns # the source characteristics, but processors may change this behaviour by # overloading those methods @@ -156,6 +157,7 @@ class Processor(Component): class FixedSizeInputAdapter(object): + """Utility to make it easier to write processors which require fixed-sized input buffers.""" @@ -164,10 +166,10 @@ class FixedSizeInputAdapter(object): channels the number of channels, and pad indicates whether the last block should be padded with zeros.""" - self.buffer = numpy.empty((buffer_size, channels)) + self.buffer = numpy.empty((buffer_size, channels)) self.buffer_size = buffer_size - self.len = 0 - self.pad = pad + self.len = 0 + self.pad = pad def blocksize(self, input_totalframes): """Return the total number of frames that this adapter will output according to the @@ -190,9 +192,9 @@ class FixedSizeInputAdapter(object): remaining = len(frames) while remaining: - space = self.buffer_size - self.len + space = self.buffer_size - self.len copylen = remaining < space and remaining or space - src = frames[src_index:src_index + copylen] + src = frames[src_index:src_index + copylen] if self.len == 0 and copylen == self.buffer_size: # avoid unnecessary copy buffer = src @@ -202,7 +204,7 @@ class FixedSizeInputAdapter(object): remaining -= copylen src_index += copylen - self.len += copylen + self.len += copylen if self.len == self.buffer_size: yield buffer, (eod and not remaining) @@ -229,12 +231,13 @@ def get_processor(processor_id): """Return a processor by its id""" if not _processors.has_key(processor_id): raise Error("No processor registered with id: '%s'" - % processor_id) + % processor_id) return _processors[processor_id] class ProcessPipe(object): + """Handle a pipe of processors Attributes: @@ -269,7 +272,8 @@ class ProcessPipe(object): try: iter(other) except TypeError: - raise Error("Can not add this type of object to a pipe: %s", str(other)) + raise Error( + "Can not add this type of object to a pipe: %s", str(other)) for item in other: self |= item @@ -351,6 +355,7 @@ class ProcessPipe(object): import threading class PipeThread(threading.Thread): + def __init__(self, process_pipe): super(PipeThread, self).__init__(name='pipe_thread') self.process_pipe = process_pipe @@ -372,7 +377,7 @@ class ProcessPipe(object): raise TypeError('Function only available in streaming mode') while pipe_thread.is_alive(): - #yield count + # yield count chunk = self._streamer.get_stream_chunk() if chunk is not None: yield chunk diff --git a/timeside/exceptions.py b/timeside/exceptions.py index 40b4dcd..09a9fa2 100644 --- a/timeside/exceptions.py +++ b/timeside/exceptions.py @@ -17,13 +17,19 @@ # You should have received a copy of the GNU General Public License # along with TimeSide. If not, see . + class Error(Exception): + """Exception base class for errors in TimeSide.""" + class ApiError(Exception): + """Exception base class for errors in TimeSide.""" + class SubProcessError(Error): + """Exception for reporting errors from a subprocess""" def __init__(self, message, command, subprocess): diff --git a/timeside/metadata.py b/timeside/metadata.py index 86abf87..d3f1b41 100644 --- a/timeside/metadata.py +++ b/timeside/metadata.py @@ -19,7 +19,6 @@ # You should have received a copy of the GNU General Public License # along with TimeSide. If not, see . + class Metadata(object): pass - - -- 2.39.5