def resource(self,
                 parent,
                 table,
                 record,
                 alias=None,
                 fields=[],
                 url=None,
                 lazy=None,
                 postprocess=None):
        """
            Creates a <resource> element from a record

            @param parent: the parent element in the document tree
            @param table: the database table
            @param record: the record
            @param alias: the resource alias (for disambiguation of components)
            @param fields: list of field names to include
            @param url: URL of the record
            @param lazy: lazy representation map
            @param postprocess: post-process hook (xml_post_render)
        """

        SubElement = etree.SubElement

        UID = self.UID
        MCI = self.MCI
        DELETED = self.DELETED

        TAG = self.TAG
        RESOURCE = TAG["resource"]
        DATA = TAG["data"]

        ATTRIBUTE = self.ATTRIBUTE
        NAME = ATTRIBUTE["name"]
        ALIAS = ATTRIBUTE["alias"]
        FIELD = ATTRIBUTE["field"]
        VALUE = ATTRIBUTE["value"]
        FILEURL = ATTRIBUTE["url"]

        tablename = table._tablename
        deleted = False

        download_url = current.response.s3.download_url or ""
        auth_group = current.auth.settings.table_group_name

        # Create the element
        if parent is not None:
            elem = SubElement(parent, RESOURCE)
        else:
            elem = etree.Element(RESOURCE)

        attrib = elem.attrib

        attrib[NAME] = tablename
        if alias:
            attrib[ALIAS] = alias

        # UID
        if UID in table.fields and UID in record:
            uid = record[UID]
            uid = str(table[UID].formatter(uid)).decode("utf-8")
            if tablename != auth_group:
                attrib[UID] = self.export_uid(uid)
            else:
                attrib[UID] = uid

        # DELETED
        if DELETED in record and record[DELETED]:
            deleted = True
            attrib[DELETED] = "True"
            # export only MTIME with deleted records
            fields = [self.MTIME]

        # Fields
        FIELDS_TO_ATTRIBUTES = self.FIELDS_TO_ATTRIBUTES

        _repr = self.represent
        to_json = json.dumps

        for f in fields:

            if f == DELETED:
                continue

            v = record.get(f, None)

            if f == MCI:
                if v is None:
                    v = 0
                attrib[MCI] = str(int(v) + 1)
                continue

            if v is None or not hasattr(table, f):
                continue

            dbfield = ogetattr(table, f)
            fieldtype = str(dbfield.type)
            formatter = dbfield.formatter
            represent = dbfield.represent
            value = None

            if fieldtype == "datetime":
                value = s3_encode_iso_datetime(v).decode("utf-8")
            elif ("date", "time") in fieldtype or \
                 fieldtype[:7] == "decimal":
                value = str(formatter(v)).decode("utf-8")

            # Get the representation
            is_lazy = False
            if fieldtype not in ("upload", "password", "blob"):
                if represent is not None and \
                   fieldtype != "id" and \
                   f not in ("created_on", "modified_on"):
                    if lazy is not None and hasattr(represent, "bulk"):
                        is_lazy = True
                        text = S3RepresentLazy(v, represent)
                    else:
                        text = _repr(table, f, v)

                elif value is not None:
                    text = value
                else:
                    text = s3_unicode(formatter(v))
            else:
                text = None

            if f in FIELDS_TO_ATTRIBUTES:
                if text is not None:
                    if is_lazy:
                        lazy.append((text, None, attrib, f))
                    else:
                        attrib[f] = s3_unicode(text)

            elif fieldtype == "upload":
                if v:
                    fileurl = None

                    # Retrieve the file properties
                    if dbfield.custom_retrieve_file_properties:
                        prop = dbfield.custom_retrieve_file_properties(v)
                    else:
                        prop = dbfield.retrieve_file_properties(v)
                    filename = prop["filename"]

                    # File in static (e.g. GIS marker image)?
                    folder = prop["path"]
                    if folder:
                        path = os.path.relpath(folder, current.request.folder) \
                                      .split(os.sep)
                        if path[0] == "static" and len(path) > 1:
                            path.append(filename)
                            fileurl = URL(c=path[0], f=path[1], args=path[2:])

                    # If not static - construct default download URL
                    if fileurl is None:
                        fileurl = "%s/%s" % (download_url, v)

                    data = SubElement(elem, DATA)
                    attr = data.attrib
                    attr[FIELD] = f
                    attr[FILEURL] = fileurl
                    attr[ATTRIBUTE.filename] = filename

            elif fieldtype == "password":
                data = SubElement(elem, DATA)
                data.attrib[FIELD] = f
                data.text = v

            elif fieldtype == "blob":
                # Not implemented - skip
                continue

            else:
                # Create a <data> element
                data = SubElement(elem, DATA)
                attr = data.attrib
                attr[FIELD] = f
                if represent or fieldtype not in ("string", "text"):
                    if value is None:
                        value = to_json(v).decode("utf-8")
                    attr[VALUE] = value
                if is_lazy:
                    lazy.append((text, data, None, None))
                else:
                    data.text = text

        if url and not deleted:
            attrib[FILEURL] = url

        if postprocess:
            postprocess(elem, record)

        return elem

    # Data import =============================================================
    #
dataset/ETHPy150Open sahana/eden/modules/s3/s3xml.py/S3XML.resource/swapped operands of `in`