Ejemplo n.º 1
0
def time_file(fname):
  f = open(fname, 'rb')
  s = common.Sink()
  t = time.time()
  parse(f, s)
  t = time.time() - t
  print t
Ejemplo n.º 2
0
def time_file(fname):
    f = open(fname, 'rb')
    s = common.Sink()
    t = time.time()
    parse(f, s)
    t = time.time() - t
    print t
Ejemplo n.º 3
0
 def test_rsa_dict_to_key(self):
   data = open(KEY_FILE_PAIRS[0][0]).read()
   rsa_dict = top.parse(data)
   key = top.get_key(rsa_dict)
   self.assertTrue(key)
   self.assertTrue(key.e)
   self.assertTrue(key.d)
Ejemplo n.º 4
0
 def test_x509_dict_to_key(self):
   data = open(KEY_FILE_PAIRS[0][1]).read()
   x509_dict = top.parse(data)
   key = top.get_key(x509_dict)
   self.assertTrue(key)
   self.assertTrue(key.e)
   # "lambda" suppresses exception until called by the test handler
   self.assertRaises(AttributeError, lambda: key.d)
Ejemplo n.º 5
0
from __init__ import parse
from parse_rcs_file import LoggingSink

test_dir = os.path.join(script_dir, 'test-data')

filelist = glob.glob(os.path.join(test_dir, '*,v'))
filelist.sort()

all_tests_ok = 1

for filename in filelist:
    sys.stderr.write('%s: ' % (filename, ))
    f = StringIO()
    try:
        parse(open(filename, 'rb'), LoggingSink(f))
    except Exception, e:
        sys.stderr.write('Error parsing file: %s!\n' % (e, ))
        all_tests_ok = 0
    else:
        output = f.getvalue()

        expected_output_filename = filename[:-2] + '.out'
        expected_output = open(expected_output_filename, 'rb').read()

        if output == expected_output:
            sys.stderr.write('OK\n')
        else:
            sys.stderr.write('Output does not match expected output!\n')
            differ = Differ()
            for diffline in differ.compare(expected_output.splitlines(1),
Ejemplo n.º 6
0
def dump_file(fname):
  parse(open(fname, 'rb'), DumpSink())
Ejemplo n.º 7
0

class LoggingSink:
  def __init__(self, f):
    self.f = f

  def __getattr__(self, name):
    return Logger(self.f, name)


if __name__ == '__main__':
  # Since there is nontrivial logic in __init__.py, we have to import
  # parse() via that file.  First make sure that the directory
  # containing this script is in the path:
  sys.path.insert(0, os.path.dirname(sys.argv[0]))

  from __init__ import parse

  if sys.argv[1:]:
    for path in sys.argv[1:]:
      if os.path.isfile(path) and path.endswith(',v'):
        parse(
            open(path, 'rb'), LoggingSink(sys.stdout)
            )
      else:
        sys.stderr.write('%r is being ignored.\n' % path)
  else:
    parse(sys.stdin, LoggingSink(sys.stdout))


Ejemplo n.º 8
0
 def setUp(self):
   with open(KEY_FILE_PAIRS[0][1]) as pub:
     self.pubkey = top.get_key(top.parse(pub.read()))
   with open(KEY_FILE_PAIRS[0][0]) as priv:
     self.privkey = top.get_key(top.parse(priv.read()))
Ejemplo n.º 9
0
 def test_x509_parse(self):
   self.assertEqual(top.x509_parse, x509_pem.parse)
   with open(KEY_FILE_PAIRS[0][1]) as d:
     data = d.read()
   x509_dict = top.parse(data)
   self.assertTrue(x509_dict)
Ejemplo n.º 10
0
 def test_x509_parse(self):
   self.assertEqual(top.x509_parse, x509_pem.parse)
   data = open(KEY_FILE_PAIRS[0][1]).read()
   x509_dict = top.parse(data)
   self.assertTrue(x509_dict)
Ejemplo n.º 11
0
from __init__ import parse
from parse_rcs_file import LoggingSink


test_dir = os.path.join(script_dir, 'test-data')

filelist = glob.glob(os.path.join(test_dir, '*,v'))
filelist.sort()

all_tests_ok = 1

for filename in filelist:
    sys.stderr.write('%s: ' % (filename,))
    f = StringIO()
    try:
        parse(open(filename, 'rb'), LoggingSink(f))
    except Exception, e:
        sys.stderr.write('Error parsing file: %s!\n' % (e,))
        all_tests_ok = 0
    else:
        output = f.getvalue()

        expected_output_filename = filename[:-2] + '.out'
        expected_output = open(expected_output_filename, 'rb').read()

        if output == expected_output:
            sys.stderr.write('OK\n')
        else:
            sys.stderr.write('Output does not match expected output!\n')
            differ = Differ()
            for diffline in differ.compare(
Ejemplo n.º 12
0
        self.f.write('%s(%s)\n' % (
            self.name,
            ', '.join(['%r' % arg for arg in args]),
        ))


class LoggingSink:
    def __init__(self, f):
        self.f = f

    def __getattr__(self, name):
        return Logger(self.f, name)


if __name__ == '__main__':
    # Since there is nontrivial logic in __init__.py, we have to import
    # parse() via that file.  First make sure that the directory
    # containing this script is in the path:
    sys.path.insert(0, os.path.dirname(sys.argv[0]))

    from __init__ import parse

    if sys.argv[1:]:
        for path in sys.argv[1:]:
            if os.path.isfile(path) and path.endswith(',v'):
                parse(open(path, 'rb'), LoggingSink(sys.stdout))
            else:
                sys.stderr.write('%r is being ignored.\n' % path)
    else:
        parse(sys.stdin, LoggingSink(sys.stdout))
Ejemplo n.º 13
0
def dump_file(fname):
    parse(open(fname, "rb"), DumpSink())
Ejemplo n.º 14
0
 def setUp(self):
   self.pubkey = top.get_key(top.parse(open(KEY_FILE_PAIRS[0][1]).read()))
   self.privkey = top.get_key(top.parse(open(KEY_FILE_PAIRS[0][0]).read()))
Ejemplo n.º 15
0
def dump_file(fname):
    parse(open(fname, 'rb'), DumpSink())
Ejemplo n.º 16
0
 def test_rsa_parse(self):
   self.assertEqual(top.rsa_parse, rsa_pem.parse)
   with open(KEY_FILE_PAIRS[0][0]) as d:
     data = d.read()
   rsa_dict = top.parse(data)
   self.assertTrue(rsa_dict)
Ejemplo n.º 17
0
 def test_rsa_parse(self):
   self.assertEqual(top.rsa_parse, rsa_pem.parse)
   data = open(KEY_FILE_PAIRS[0][0]).read()
   rsa_dict = top.parse(data)
   self.assertTrue(rsa_dict)