<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def content_val(self, ymldata=None, messages=None):
 """Validates the Telemetry Dictionary to ensure the contents for each of the fields meets specific criteria regarding the expected types, byte ranges, etc."""


        # Turn off the YAML Processor
        log.debug("BEGIN: Content-based validation of Telemetry dictionary")
        if ymldata is not None:
            tlmdict = ymldata
        else:
            tlmdict = tlm.TlmDict(self._ymlfile)

        try:
            # instantiate the document number. this will increment in order to
            # track the line numbers and section where validation fails
            docnum = 0

            # boolean to hold argument validity
            fldsvalid = True

            # list of rules to validate against
            rules = []

            ### set the packet rules
            #
            # set uniqueness rule for packet names
            rules.append(UniquenessRule('name', "Duplicate packet name: %s", messages))

            ###
            # Loop through the keys and check each PacketDefinition
            for key in tlmdict.keys():
                pktdefn = tlmdict[key]
                # check the telemetry packet rules
                for rule in rules:
                    rule.check(pktdefn)

                # list of field rules to validate against
                fldrules = []

                ### set rules for telemetry fields
                #
                # set uniqueness rule for field name
                fldrules.append(UniquenessRule('name', "Duplicate field name: " + pktdefn.name + ".%s", messages))

                # set type rule for field.type
                fldrules.append(TypeRule('type', "Invalid field type for field: " + pktdefn.name + ".%s", messages))

                # set field size rule for field.type.nbytes
                fldrules.append(TypeSizeRule('nbytes', "Invalid field size for field: " + pktdefn.name + ".%s", messages))

                # set field enumerations rule to check no enumerations contain un-quoted YAML special variables
                fldrules.append(EnumRule('enum', "Invalid enum value for field: " + pktdefn.name + ".%s", messages))
                #
                ###

                flddefns = pktdefn.fields
                for fld in flddefns:
                    # check field rules
                    for rule in fldrules:
                        rule.check(fld)

                # check if field rule failed, if so set the validity to False
                if not all(r.valid is True for r in fldrules):
                    fldsvalid = False

            log.debug("END: Content-based validation complete for '%s'", self._ymlfile)

            # check validity of all packet rules and field validity
            return all(rule.valid is True for rule in rules) and fldsvalid

        except util.YAMLValidationError, e:
            # Display the error message
            if messages is not None:
                if len(e.message) < 128:
                    msg = "Validation Failed for YAML file '" + self._ymlfile + "': '" + str(e.message) + "'"
                else:
                    msg = "Validation Failed for YAML file '" + self._ymlfile + "'"

                log.error(msg)
                self.ehandler.process(self.ehandler.doclines, e, messages)
                return False