Beispiel #1
0
 def testExample1(self):
     """Tests Example 1 from make_dafsa.py."""
     infile = ['%%', 'aa, 1', 'a, 2', '%%']
     bytes = [0x81, 0xE1, 0x02, 0x81, 0x82, 0x61, 0x81]
     outfile = make_dafsa.to_cxx(bytes)
     self.assertEqual(
         make_dafsa.words_to_cxx(make_dafsa.parse_gperf(infile)), outfile)
Beispiel #2
0
def main(output, effective_tld_filename, output_format="cxx"):
    """
  effective_tld_filename is the effective TLD file to parse.
  based on the output format, either a C++ array of a binary representation
  of a DAFSA representing the eTLD file is then printed to standard output
  or a binary file is written to disk.
  """
    def typeEnum(etld):
        """
    Maps the flags to the DAFSA's enum types.
    """
        if etld.exception():
            return 1
        elif etld.wild():
            return 2
        else:
            return 0

    def dafsa_words():
        """
    make_dafsa expects lines of the form "<domain_name><enum_value>"
    """
        for etld in getEffectiveTLDs(effective_tld_filename):
            yield "%s%d" % (etld.domain(), typeEnum(etld))

    """ words_to_bin() returns a bytes while words_to_cxx() returns string """
    if output_format == "bin":
        output.write(words_to_bin(dafsa_words()))
    else:
        output.write(words_to_cxx(dafsa_words()))
 def testExample1(self):
   """Tests Example 1 from make_dafsa.py."""
   infile = [ '%%', 'aa, 1', 'a, 2', '%%' ]
   bytes = [ 0x81, 0xE1, 0x02, 0x81, 0x82, 0x61, 0x81 ]
   outfile = make_dafsa.to_cxx(bytes)
   self.assertEqual(make_dafsa.words_to_cxx(make_dafsa.parse_gperf(infile)),
                     outfile)
Beispiel #4
0
def main(output, effective_tld_filename):
    """
  effective_tld_filename is the effective TLD file to parse.
  A C++ array of a binary representation of a DAFSA representing the
  eTLD file is then printed to output.
  """
    def typeEnum(etld):
        """
    Maps the flags to the DAFSA's enum types.
    """
        if etld.exception():
            return 1
        elif etld.wild():
            return 2
        else:
            return 0

    def dafsa_words():
        """
    make_dafsa expects lines of the form "<domain_name><enum_value>"
    """
        for etld in getEffectiveTLDs(effective_tld_filename):
            yield "%s%d" % (etld.domain(), typeEnum(etld))

    output.write(words_to_cxx(dafsa_words()))
 def testExample2(self):
     """Tests Example 2 from make_dafsa.py."""
     infile = ['%%', 'aa, 1', 'bbb, 2', 'baa, 1', '%%']
     bytes = [
         0x02, 0x83, 0xE2, 0x02, 0x83, 0x61, 0x61, 0x81, 0x62, 0x62, 0x82
     ]
     outfile = make_dafsa.to_cxx(bytes)
     self.assertEqual(
         make_dafsa.words_to_cxx(make_dafsa.parse_gperf(infile, False)),
         outfile)