From f5d11b750ecc982541d1f936488248f0b42d75d3 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 20:15:50 +0100 Subject: pep8 linting (whitespaces) W191 indentation contains tabs E221 multiple spaces before operator E222 multiple spaces after operator E225 missing whitespace around operator E271 multiple spaces after keyword W292 no newline at end of file W293 blank line contains whitespace W391 blank line at end of file --- git/objects/util.py | 86 ++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index cdf72bed..f9dffd81 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -40,9 +40,9 @@ def get_object_type_by_name(object_type_name): """ :return: type suitable to handle the given object type name. Use the type to create new instances. - + :param object_type_name: Member of TYPES - + :raise ValueError: In case object_type_name is unknown""" if object_type_name == "commit": import commit @@ -58,14 +58,14 @@ def get_object_type_by_name(object_type_name): return tree.Tree else: raise ValueError("Cannot handle unknown object type: %s" % object_type_name) - + def utctz_to_altz(utctz): """we convert utctz to the timezone in seconds, it is the format time.altzone returns. Git stores it as UTC timezone which has the opposite sign as well, which explains the -1 * ( that was made explicit here ) :param utctz: git utc timezone string, i.e. +0200""" return -1 * int(float(utctz)/100*3600) - + def altz_to_utctz_str(altz): """As above, but inverses the operation, returning a string that can be used in commit objects""" @@ -74,7 +74,7 @@ def altz_to_utctz_str(altz): utcs = "0"*(4-len(utcs)) + utcs prefix = (utci < 0 and '-') or '+' return prefix + utcs - + def verify_utctz(offset): """:raise ValueError: if offset is incorrect @@ -95,12 +95,12 @@ def verify_utctz(offset): def parse_date(string_date): """ Parse the given date as one of the following - + * Git internal format: timestamp offset * RFC 2822: Thu, 07 Apr 2005 22:13:13 +0200. * ISO 8601 2005-04-07T22:13:13 The T can be a space as well - + :return: Tuple(int(timestamp), int(offset)), both in seconds since epoch :raise ValueError: If the format could not be understood :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY""" @@ -116,7 +116,7 @@ def parse_date(string_date): offset = verify_utctz(string_date[-5:]) string_date = string_date[:-6] # skip space as well # END split timezone info - + # now figure out the date and time portion - split time date_formats = list() splitter = -1 @@ -129,22 +129,22 @@ def parse_date(string_date): date_formats.append("%Y.%m.%d") date_formats.append("%m/%d/%Y") date_formats.append("%d.%m.%Y") - + splitter = string_date.rfind('T') if splitter == -1: splitter = string_date.rfind(' ') # END handle 'T' and ' ' # END handle rfc or iso - + assert splitter > -1 - + # split date and time time_part = string_date[splitter+1:] # skip space date_part = string_date[:splitter] - + # parse time tstruct = time.strptime(time_part, "%H:%M:%S") - + for fmt in date_formats: try: dtstruct = time.strptime(date_part, fmt) @@ -156,7 +156,7 @@ def parse_date(string_date): continue # END exception handling # END for each fmt - + # still here ? fail raise ValueError("no format matched") # END handle format @@ -164,16 +164,16 @@ def parse_date(string_date): raise ValueError("Unsupported date format: %s" % string_date) # END handle exceptions - + # precompiled regex _re_actor_epoch = re.compile(r'^.+? (.*) (\d+) ([+-]\d+).*$') _re_only_actor = re.compile(r'^.+? (.*)$') def parse_actor_and_date(line): """Parse out the actor (author or committer) info from a line like:: - + author Tom Preston-Werner 1191999972 -0700 - + :return: [Actor, int_seconds_since_epoch, int_timezone_offset]""" actor, epoch, offset = '', 0, 0 m = _re_actor_epoch.search(line) @@ -188,10 +188,10 @@ def parse_actor_and_date(line): #{ Classes - + class ProcessStreamAdapter(object): """Class wireing all calls to the contained Process instance. - + Use this type to hide the underlying process to provide access only to a specified stream. The process is usually wrapped into an AutoInterrupt class to kill it if the instance goes out of scope.""" @@ -199,18 +199,18 @@ class ProcessStreamAdapter(object): def __init__(self, process, stream_name): self._proc = process self._stream = getattr(process, stream_name) - + def __getattr__(self, attr): return getattr(self._stream, attr) - - + + class Traversable(object): """Simple interface to perforam depth-first or breadth-first traversals into one direction. Subclasses only need to implement one function. Instances of the Subclass must be hashable""" __slots__ = tuple() - + @classmethod def _get_intermediate_items(cls, item): """ @@ -219,7 +219,7 @@ class Traversable(object): Must be implemented in subclass """ raise NotImplementedError("To be implemented in subclass") - + def list_traverse(self, *args, **kwargs): """ :return: IterableList with the results of the traversal as produced by @@ -227,36 +227,36 @@ class Traversable(object): out = IterableList(self._id_attribute_) out.extend(self.traverse(*args, **kwargs)) return out - + def traverse( self, predicate = lambda i,d: True, prune = lambda i,d: False, depth = -1, branch_first=True, visit_once = True, ignore_self=1, as_edge = False ): """:return: iterator yieling of items found when traversing self - + :param predicate: f(i,d) returns False if item i at depth d should not be included in the result - + :param prune: f(i,d) return True if the search should stop at item i at depth d. Item i will not be returned. - + :param depth: define at which level the iteration should not go deeper if -1, there is no limit if 0, you would effectively only get self, the root of the iteration i.e. if 1, you would only get the first level of predessessors/successors - + :param branch_first: if True, items will be returned branch first, otherwise depth first - + :param visit_once: if True, items will only be returned once, although they might be encountered several times. Loops are prevented that way. - + :param ignore_self: if True, self will be ignored and automatically pruned from the result. Otherwise it will be the first item to be returned. If as_edge is True, the source of the first edge is None - + :param as_edge: if True, return a pair of items, first being the source, second the destinatination, i.e. tuple(src, dest) with the edge spanning from @@ -264,7 +264,7 @@ class Traversable(object): visited = set() stack = Deque() stack.append( ( 0 ,self, None ) ) # self is always depth level 0 - + def addToStack( stack, item, branch_first, depth ): lst = self._get_intermediate_items( item ) if not lst: @@ -275,44 +275,44 @@ class Traversable(object): reviter = ( ( depth , lst[i], item ) for i in range( len( lst )-1,-1,-1) ) stack.extend( reviter ) # END addToStack local method - + while stack: d, item, src = stack.pop() # depth of item, item, item_source - + if visit_once and item in visited: continue - + if visit_once: visited.add(item) - + rval = ( as_edge and (src, item) ) or item if prune( rval, d ): continue - + skipStartItem = ignore_self and ( item is self ) if not skipStartItem and predicate( rval, d ): yield rval - + # only continue to next level if this is appropriate ! nd = d + 1 if depth > -1 and nd > depth: continue - + addToStack( stack, item, branch_first, nd ) # END for each item on work stack - + class Serializable(object): """Defines methods to serialize and deserialize objects from and into a data stream""" __slots__ = tuple() - + def _serialize(self, stream): """Serialize the data of this object into the given data stream :note: a serialized object would ``_deserialize`` into the same objet :param stream: a file-like object :return: self""" raise NotImplementedError("To be implemented in subclass") - + def _deserialize(self, stream): """Deserialize all information regarding this object from the stream :param stream: a file-like object -- cgit v1.2.3 From be34ec23c48d6d5d8fd2ef4491981f6fb4bab8e6 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 20:51:04 +0100 Subject: pep8 linting (blank lines expectations) E301 expected 1 blank line, found 0 E302 expected 2 blank lines, found 1 E303 too many blank lines (n) --- git/objects/util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index f9dffd81..9f947fcc 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -22,6 +22,7 @@ __all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date', #{ Functions + def mode_str_to_int(modestr): """ :param modestr: string like 755 or 644 or 100644 - only the last 6 chars will be used @@ -36,6 +37,7 @@ def mode_str_to_int(modestr): # END for each char return mode + def get_object_type_by_name(object_type_name): """ :return: type suitable to handle the given object type name. @@ -59,6 +61,7 @@ def get_object_type_by_name(object_type_name): else: raise ValueError("Cannot handle unknown object type: %s" % object_type_name) + def utctz_to_altz(utctz): """we convert utctz to the timezone in seconds, it is the format time.altzone returns. Git stores it as UTC timezone which has the opposite sign as well, @@ -66,6 +69,7 @@ def utctz_to_altz(utctz): :param utctz: git utc timezone string, i.e. +0200""" return -1 * int(float(utctz)/100*3600) + def altz_to_utctz_str(altz): """As above, but inverses the operation, returning a string that can be used in commit objects""" @@ -92,6 +96,7 @@ def verify_utctz(offset): # END for each char return offset + def parse_date(string_date): """ Parse the given date as one of the following @@ -169,6 +174,7 @@ def parse_date(string_date): _re_actor_epoch = re.compile(r'^.+? (.*) (\d+) ([+-]\d+).*$') _re_only_actor = re.compile(r'^.+? (.*)$') + def parse_actor_and_date(line): """Parse out the actor (author or committer) info from a line like:: @@ -190,12 +196,14 @@ def parse_actor_and_date(line): #{ Classes class ProcessStreamAdapter(object): + """Class wireing all calls to the contained Process instance. Use this type to hide the underlying process to provide access only to a specified stream. The process is usually wrapped into an AutoInterrupt class to kill it if the instance goes out of scope.""" __slots__ = ("_proc", "_stream") + def __init__(self, process, stream_name): self._proc = process self._stream = getattr(process, stream_name) @@ -205,6 +213,7 @@ class ProcessStreamAdapter(object): class Traversable(object): + """Simple interface to perforam depth-first or breadth-first traversals into one direction. Subclasses only need to implement one function. @@ -303,6 +312,7 @@ class Traversable(object): class Serializable(object): + """Defines methods to serialize and deserialize objects from and into a data stream""" __slots__ = tuple() -- cgit v1.2.3 From 614907b7445e2ed8584c1c37df7e466e3b56170f Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 20:56:53 +0100 Subject: pep8 linting (whitespace before/after) E201 whitespace after '(' E202 whitespace before ')' E203 whitespace before ':' E225 missing whitespace around operator E226 missing whitespace around arithmetic operator E227 missing whitespace around bitwise or shift operator E228 missing whitespace around modulo operator E231 missing whitespace after ',' E241 multiple spaces after ',' E251 unexpected spaces around keyword / parameter equals --- git/objects/util.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index 9f947fcc..6321399d 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -33,7 +33,7 @@ def mode_str_to_int(modestr): for example.""" mode = 0 for iteration, char in enumerate(reversed(modestr[-6:])): - mode += int(char) << iteration*3 + mode += int(char) << iteration * 3 # END for each char return mode @@ -67,15 +67,15 @@ def utctz_to_altz(utctz): returns. Git stores it as UTC timezone which has the opposite sign as well, which explains the -1 * ( that was made explicit here ) :param utctz: git utc timezone string, i.e. +0200""" - return -1 * int(float(utctz)/100*3600) + return -1 * int(float(utctz) / 100 * 3600) def altz_to_utctz_str(altz): """As above, but inverses the operation, returning a string that can be used in commit objects""" - utci = -1 * int((altz / 3600)*100) + utci = -1 * int((altz / 3600) * 100) utcs = str(abs(utci)) - utcs = "0"*(4-len(utcs)) + utcs + utcs = "0" * (4 - len(utcs)) + utcs prefix = (utci < 0 and '-') or '+' return prefix + utcs @@ -144,7 +144,7 @@ def parse_date(string_date): assert splitter > -1 # split date and time - time_part = string_date[splitter+1:] # skip space + time_part = string_date[splitter + 1:] # skip space date_part = string_date[:splitter] # parse time @@ -237,9 +237,9 @@ class Traversable(object): out.extend(self.traverse(*args, **kwargs)) return out - def traverse( self, predicate = lambda i,d: True, - prune = lambda i,d: False, depth = -1, branch_first=True, - visit_once = True, ignore_self=1, as_edge = False ): + def traverse(self, predicate=lambda i, d: True, + prune=lambda i, d: False, depth=-1, branch_first=True, + visit_once=True, ignore_self=1, as_edge=False): """:return: iterator yieling of items found when traversing self :param predicate: f(i,d) returns False if item i at depth d should not be included in the result @@ -272,17 +272,17 @@ class Traversable(object): source to destination""" visited = set() stack = Deque() - stack.append( ( 0 ,self, None ) ) # self is always depth level 0 + stack.append((0, self, None)) # self is always depth level 0 - def addToStack( stack, item, branch_first, depth ): - lst = self._get_intermediate_items( item ) + def addToStack(stack, item, branch_first, depth): + lst = self._get_intermediate_items(item) if not lst: return if branch_first: - stack.extendleft( ( depth , i, item ) for i in lst ) + stack.extendleft((depth, i, item) for i in lst) else: - reviter = ( ( depth , lst[i], item ) for i in range( len( lst )-1,-1,-1) ) - stack.extend( reviter ) + reviter = ((depth, lst[i], item) for i in range(len(lst) - 1, -1, -1)) + stack.extend(reviter) # END addToStack local method while stack: @@ -294,12 +294,12 @@ class Traversable(object): if visit_once: visited.add(item) - rval = ( as_edge and (src, item) ) or item - if prune( rval, d ): + rval = (as_edge and (src, item)) or item + if prune(rval, d): continue - skipStartItem = ignore_self and ( item is self ) - if not skipStartItem and predicate( rval, d ): + skipStartItem = ignore_self and (item is self) + if not skipStartItem and predicate(rval, d): yield rval # only continue to next level if this is appropriate ! @@ -307,7 +307,7 @@ class Traversable(object): if depth > -1 and nd > depth: continue - addToStack( stack, item, branch_first, nd ) + addToStack(stack, item, branch_first, nd) # END for each item on work stack -- cgit v1.2.3 From c8e70749887370a99adeda972cc3503397b5f9a7 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 21:09:47 +0100 Subject: pep8 linting (trailing whitespace) W291 trailing whitespace --- git/objects/util.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index 6321399d..f6daca0f 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -5,7 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php """Module for general utility functions""" from git.util import ( - IterableList, + IterableList, Actor ) @@ -16,8 +16,8 @@ from string import digits import time import os -__all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date', - 'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz', +__all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date', + 'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz', 'verify_utctz', 'Actor') #{ Functions @@ -27,8 +27,8 @@ def mode_str_to_int(modestr): """ :param modestr: string like 755 or 644 or 100644 - only the last 6 chars will be used :return: - String identifying a mode compatible to the mode methods ids of the - stat module regarding the rwx permissions for user, group and other, + String identifying a mode compatible to the mode methods ids of the + stat module regarding the rwx permissions for user, group and other, special flags and file system flags, i.e. whether it is a symlink for example.""" mode = 0 @@ -64,7 +64,7 @@ def get_object_type_by_name(object_type_name): def utctz_to_altz(utctz): """we convert utctz to the timezone in seconds, it is the format time.altzone - returns. Git stores it as UTC timezone which has the opposite sign as well, + returns. Git stores it as UTC timezone which has the opposite sign as well, which explains the -1 * ( that was made explicit here ) :param utctz: git utc timezone string, i.e. +0200""" return -1 * int(float(utctz) / 100 * 3600) @@ -102,7 +102,7 @@ def parse_date(string_date): Parse the given date as one of the following * Git internal format: timestamp offset - * RFC 2822: Thu, 07 Apr 2005 22:13:13 +0200. + * RFC 2822: Thu, 07 Apr 2005 22:13:13 +0200. * ISO 8601 2005-04-07T22:13:13 The T can be a space as well @@ -139,7 +139,7 @@ def parse_date(string_date): if splitter == -1: splitter = string_date.rfind(' ') # END handle 'T' and ' ' - # END handle rfc or iso + # END handle rfc or iso assert splitter > -1 @@ -153,7 +153,7 @@ def parse_date(string_date): for fmt in date_formats: try: dtstruct = time.strptime(date_part, fmt) - fstruct = time.struct_time((dtstruct.tm_year, dtstruct.tm_mon, dtstruct.tm_mday, + fstruct = time.struct_time((dtstruct.tm_year, dtstruct.tm_mon, dtstruct.tm_mday, tstruct.tm_hour, tstruct.tm_min, tstruct.tm_sec, dtstruct.tm_wday, dtstruct.tm_yday, tstruct.tm_isdst)) return int(time.mktime(fstruct)), utctz_to_altz(offset) @@ -166,7 +166,7 @@ def parse_date(string_date): raise ValueError("no format matched") # END handle format except Exception: - raise ValueError("Unsupported date format: %s" % string_date) + raise ValueError("Unsupported date format: %s" % string_date) # END handle exceptions @@ -193,14 +193,14 @@ def parse_actor_and_date(line): #} END functions -#{ Classes +#{ Classes class ProcessStreamAdapter(object): """Class wireing all calls to the contained Process instance. - Use this type to hide the underlying process to provide access only to a specified - stream. The process is usually wrapped into an AutoInterrupt class to kill + Use this type to hide the underlying process to provide access only to a specified + stream. The process is usually wrapped into an AutoInterrupt class to kill it if the instance goes out of scope.""" __slots__ = ("_proc", "_stream") @@ -214,7 +214,7 @@ class ProcessStreamAdapter(object): class Traversable(object): - """Simple interface to perforam depth-first or breadth-first traversals + """Simple interface to perforam depth-first or breadth-first traversals into one direction. Subclasses only need to implement one function. Instances of the Subclass must be hashable""" @@ -244,7 +244,7 @@ class Traversable(object): :param predicate: f(i,d) returns False if item i at depth d should not be included in the result - :param prune: + :param prune: f(i,d) return True if the search should stop at item i at depth d. Item i will not be returned. @@ -267,8 +267,8 @@ class Traversable(object): If as_edge is True, the source of the first edge is None :param as_edge: - if True, return a pair of items, first being the source, second the - destinatination, i.e. tuple(src, dest) with the edge spanning from + if True, return a pair of items, first being the source, second the + destinatination, i.e. tuple(src, dest) with the edge spanning from source to destination""" visited = set() stack = Deque() -- cgit v1.2.3