<commit_before>module David
  class Server
    module Mapping
      include Constants

      HTTP_TO_COAP_CODES = {
        200 => 205,
        202 => 201,
        203 => 205,
        204 => 205,
        407 => 401,
        408 => 400,
        409 => 412,
        410 => 404,
        411 => 402,
        414 => 402,
        505 => 500,
        506 => 500,
        511 => 500,
      }.freeze

      protected
    
      def accept_to_http(request)
        if request.accept.nil?
          @default_format
        else
          CoAP::Registry.convert_content_format(request.accept)
        end
      end

      def body_to_cbor(body)
        JSON.parse(body).to_cbor
      end

      def code_to_coap(code)
        code = code.to_i
        code = HTTP_TO_COAP_CODES[code] if HTTP_TO_COAP_CODES[code]

        a = code / 100
        b = code - (a * 100)

        [a, b]
      end

      def etag_to_coap(headers, bytes = 8)
        etag = headers[HTTP_ETAG]

        if etag
          etag = etag.split('"')
          etag = etag[1] || etag[0]

          etag
            .bytes
            .first(bytes * 2)
            .pack('C*')
            .hex
        end
      end

      def location_to_coap(headers)
        l = headers[HTTP_LOCATION].split('/').reject(&:empty?)
        return l.empty? ? nil : l
      rescue NoMethodError
        nil
      end

      def max_age_to_coap(headers)
        headers[HTTP_CACHE_CONTROL][/max-age=([0-9]*)/, 1]
      rescue NoMethodError
        nil
      end

      def method_to_http(method)
        method.to_s.upcase
      end
    end
  end
end
<commit_msg>Map HTTP 304 to CoAP 2.03 for now.<commit_after>module David
  class Server
    module Mapping
      include Constants

      HTTP_TO_COAP_CODES = {
        200 => 205,
        202 => 201,
        203 => 205,
        204 => 205,
        304 => 203,
        407 => 401,
        408 => 400,
        409 => 412,
        410 => 404,
        411 => 402,
        414 => 402,
        505 => 500,
        506 => 500,
        511 => 500,
      }.freeze

      protected
    
      def accept_to_http(request)
        if request.accept.nil?
          @default_format
        else
          CoAP::Registry.convert_content_format(request.accept)
        end
      end

      def body_to_cbor(body)
        JSON.parse(body).to_cbor
      end

      def code_to_coap(code)
        code = code.to_i
        code = HTTP_TO_COAP_CODES[code] if HTTP_TO_COAP_CODES[code]

        a = code / 100
        b = code - (a * 100)

        [a, b]
      end

      def etag_to_coap(headers, bytes = 8)
        etag = headers[HTTP_ETAG]

        if etag
          etag = etag.split('"')
          etag = etag[1] || etag[0]

          etag
            .bytes
            .first(bytes * 2)
            .pack('C*')
            .hex
        end
      end

      def location_to_coap(headers)
        l = headers[HTTP_LOCATION].split('/').reject(&:empty?)
        return l.empty? ? nil : l
      rescue NoMethodError
        nil
      end

      def max_age_to_coap(headers)
        headers[HTTP_CACHE_CONTROL][/max-age=([0-9]*)/, 1]
      rescue NoMethodError
        nil
      end

      def method_to_http(method)
        method.to_s.upcase
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09916589434661724, 'fraction_numerical': 0.059932035835650294, 'mean_word_length': 1.3896678966789668, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6315327', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1058, 'n_words': 241}