diff --git a/github3/structs.py b/github3/structs.py index fd76014f5..349e6c394 100644 --- a/github3/structs.py +++ b/github3/structs.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from collections import Iterator from github3.models import GitHubCore -from requests.compat import urlparse, urlencode +from requests.compat import is_py3, urlparse, urlencode class GitHubIterator(GitHubCore, Iterator): @@ -135,3 +135,48 @@ def _get_json(self, response): self.items = json.get('items', []) # If we return None then it will short-circuit the while loop. return json.get('items') + + +class NullObject(object): + def __init__(self, initializer=None): + self.__dict__['initializer'] = initializer + + def __str__(self): + return '' + + def __unicode__(self): + return '' if is_py3 else ''.decode() + + def __repr__(self): + return ''.format( + repr(self.__getattribute__('initializer')) + ) + + def __getitem__(self, index): + return self + + def __setitem__(self, index, value): + pass + + def __getattr__(self, attr): + return self + + def __setattr__(self, attr, value): + pass + + def __call__(self, *args, **kwargs): + return self + + def __contains__(self, other): + return False + + def __iter__(self): + yield self + + def __next__(self): + raise StopIteration + + next = __next__ + + def is_null(self): + return True