Skip to content

Commit

Permalink
Add NullObject
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmavirus24 committed Jan 21, 2014
1 parent 90edc12 commit 0d10740
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion 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):
Expand Down Expand Up @@ -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 '<NullObject({0})>'.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

0 comments on commit 0d10740

Please sign in to comment.