# Path: pale/fields/base.py
# class BaseField(object):
#     """The base class for all Fields and Arguments.
# 
#     Field objects are used by Resources to define the data they return.
#     They include a name, a type, a short description, and a long
#     description.  Of these instance variables, only `name` is functionally
#     significant, as it's used as the key for the field's value in the
#     outgoing JSON.  The rest of the instance variables are used to generate
#     documentation.
# 
#     Argument objects inherit from Field, in that they share the same base set
#     of instance variables, but are used on the input side of the API, and
#     include validation functionality.
#     """
# 
#     value_type = 'base'
# 
#     def __init__(self,
#                  value_type,
#                  description,
#                  details=None,
#                  property_name=None,
#                  value=None):
#         self.value_type = value_type
#         self.description = description
#         self.details = details
#         self.property_name = property_name
#         self.value_lambda = value
# 
#         if self.value_lambda is not None:
#             assert isinstance(value, types.LambdaType), \
#                     "A Field's `value` parameter must be a lambda"
#             assert self.property_name is None, \
#                     ("Field does not support setting both `property_name` "
#                      "*AND* `value`.  Please pick one or the other")
# 
# 
#     def _fix_up(self, cls, code_name):
#         """Internal helper to name the field after its variable.
# 
#         This is called by _fix_up_fields, which is called by the MetaHasFields
#         metaclass when finishing the construction of a Resource subclass.
# 
#         The `code_name` passed in is the name of the python attribute that
#         the Field has been assigned to in the resource.
# 
#         Note that each BaseField instance must only be assigned to at most
#         one Resource class attribute.
#         """
#         self.name = code_name
# 
# 
#     def render(self, obj, name, context):
#         """The default field renderer.
# 
#         This basic renderer assumes that the object has an attribute with
#         the same name as the field, unless a different field is specified
#         as a `property_name`.
# 
#         The renderer is also passed the context so that it can be
#         propagated to the `_render_serializable` method of nested
#         resources (or, for example, if you decide to implement attribute
#         hiding at the field level instead of at the object level).
# 
#         Callable attributes of `obj` will be called to fetch value.
#         This is useful for fields computed from lambda functions
#         or instance methods.
#         """
#         if self.value_lambda is not None:
#             val = self.value_lambda(obj)
#         else:
#             attr_name = name
#             if self.property_name is not None:
#                 attr_name = self.property_name
#             if isinstance(obj, dict):
#                 val = obj.get(attr_name, None)
#             else:
#                 val = getattr(obj, attr_name, None)
# 
#         if callable(val):
#             try:
#                 val = val()
#             except:
#                 logging.exception("Attempted to call `%s` on obj of type %s.",
#                     attr_name, type(obj))
#                 raise
# 
#         return val
# 
# 
#     def doc_dict(self):
#         """Generate the documentation for this field."""
#         doc = {
#             'type': self.value_type,
#             'description': self.description,
#             'extended_description': self.details
#         }
#         return doc
# 
# Path: pale/meta.py
# class MetaHasFields(type):
#     """Metaclass for classes that support named field definitions.
# 
#     In Pale, this is particularly Endpoint and Resource.  This metaclass is
#     here to populate the developer-specified fields on the class so that
#     simple API definition like the following is possible:
# 
#         class MyEndpoint(Endpoint):
#             _method = 'GET'
#             _uri = '/hello'
# 
#             name = StringArgument(
#                 description="Who should we say Hello to?",
#                 default="World")
# 
#             _returns = RawStringResource("A 'Hello, world' string")
# 
#             def _handle(self, context):
#               return "Hello, %s" % context.args.name
# 
#     In the above case, this metaclass allows us to create a `_arguments` map
#     that would store {"name": MyEndpoint.name}.
#     """
# 
#     def __init__(cls, name, bases, classdict):
#         super(MetaHasFields, cls).__init__(name, bases, classdict)
#         cls._fix_up_fields()


import logging
import types
from pale.fields import BaseField
from pale.meta import MetaHasFields


class Resource(object):
    __metaclass__ = MetaHasFields

    _value_type = "Base Resource"

    _default_fields = None

    @classmethod

# Path: pale/fields/base.py
# class BaseField(object):
#     """The base class for all Fields and Arguments.
# 
#     Field objects are used by Resources to define the data they return.
#     They include a name, a type, a short description, and a long
#     description.  Of these instance variables, only `name` is functionally
#     significant, as it's used as the key for the field's value in the
#     outgoing JSON.  The rest of the instance variables are used to generate
#     documentation.
# 
#     Argument objects inherit from Field, in that they share the same base set
#     of instance variables, but are used on the input side of the API, and
#     include validation functionality.
#     """
# 
#     value_type = 'base'
# 
#     def __init__(self,
#                  value_type,
#                  description,
#                  details=None,
#                  property_name=None,
#                  value=None):
#         self.value_type = value_type
#         self.description = description
#         self.details = details
#         self.property_name = property_name
#         self.value_lambda = value
# 
#         if self.value_lambda is not None:
#             assert isinstance(value, types.LambdaType), \
#                     "A Field's `value` parameter must be a lambda"
#             assert self.property_name is None, \
#                     ("Field does not support setting both `property_name` "
#                      "*AND* `value`.  Please pick one or the other")
# 
# 
#     def _fix_up(self, cls, code_name):
#         """Internal helper to name the field after its variable.
# 
#         This is called by _fix_up_fields, which is called by the MetaHasFields
#         metaclass when finishing the construction of a Resource subclass.
# 
#         The `code_name` passed in is the name of the python attribute that
#         the Field has been assigned to in the resource.
# 
#         Note that each BaseField instance must only be assigned to at most
#         one Resource class attribute.
#         """
#         self.name = code_name
# 
# 
#     def render(self, obj, name, context):
#         """The default field renderer.
# 
#         This basic renderer assumes that the object has an attribute with
#         the same name as the field, unless a different field is specified
#         as a `property_name`.
# 
#         The renderer is also passed the context so that it can be
#         propagated to the `_render_serializable` method of nested
#         resources (or, for example, if you decide to implement attribute
#         hiding at the field level instead of at the object level).
# 
#         Callable attributes of `obj` will be called to fetch value.
#         This is useful for fields computed from lambda functions
#         or instance methods.
#         """
#         if self.value_lambda is not None:
#             val = self.value_lambda(obj)
#         else:
#             attr_name = name
#             if self.property_name is not None:
#                 attr_name = self.property_name
#             if isinstance(obj, dict):
#                 val = obj.get(attr_name, None)
#             else:
#                 val = getattr(obj, attr_name, None)
# 
#         if callable(val):
#             try:
#                 val = val()
#             except:
#                 logging.exception("Attempted to call `%s` on obj of type %s.",
#                     attr_name, type(obj))
#                 raise
# 
#         return val
# 
# 
#     def doc_dict(self):
#         """Generate the documentation for this field."""
#         doc = {
#             'type': self.value_type,
#             'description': self.description,
#             'extended_description': self.details
#         }
#         return doc
# 
# Path: pale/meta.py
# class MetaHasFields(type):
#     """Metaclass for classes that support named field definitions.
# 
#     In Pale, this is particularly Endpoint and Resource.  This metaclass is
#     here to populate the developer-specified fields on the class so that
#     simple API definition like the following is possible:
# 
#         class MyEndpoint(Endpoint):
#             _method = 'GET'
#             _uri = '/hello'
# 
#             name = StringArgument(
#                 description="Who should we say Hello to?",
#                 default="World")
# 
#             _returns = RawStringResource("A 'Hello, world' string")
# 
#             def _handle(self, context):
#               return "Hello, %s" % context.args.name
# 
#     In the above case, this metaclass allows us to create a `_arguments` map
#     that would store {"name": MyEndpoint.name}.
#     """
# 
#     def __init__(cls, name, bases, classdict):
#         super(MetaHasFields, cls).__init__(name, bases, classdict)
#         cls._fix_up_fields()


# Path: pale/resource.py
import logging
import types
from pale.fields import BaseField
from pale.meta import MetaHasFields



class Resource(object):
    __metaclass__ = MetaHasFields

    _value_type = "Base Resource"

    _default_fields = None

    @classmethod

    def _all_fields(cls):