Created
August 18, 2015 18:03
-
-
Save tacaswell/5f048fd5851781ea2baf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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