Skip to content

Instantly share code, notes, and snippets.

@tacaswell
Created August 18, 2015 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacaswell/5f048fd5851781ea2baf to your computer and use it in GitHub Desktop.
Save tacaswell/5f048fd5851781ea2baf to your computer and use it in GitHub Desktop.
class Document(dict):
def __init__(self, name, *args, **kwargs):
self._name = name
super(Document, self).__init__(*args, **kwargs)
def __getattr__(self, key):
return self[key]
def __setattr__(self, key, value):
self[key] = value
def __iter__(self):
return (k for k in super(Document, self).__iter__()
if not (isinstance(k, six.string_types) and k.startswith('_')))
def items(self):
return ((k, v) for k, v in super(Document, self).items()
if not (isinstance(k, six.string_types) and k.startswith('_')))
def values(self):
return (v for k, v in super(Document, self).items()
if not (isinstance(k, six.string_types) and k.startswith('_')))
def keys(self):
return (k for k in super(Document, self).keys()
if not (isinstance(k, six.string_types) and k.startswith('_')))
def __contains__(self, k):
if isinstance(k, six.string_types) and k.startswith('_'):
return False
return super(Document, self).__contains(k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment