Пример #1
0
    def test_fileencoding(self):
        tests = [
            ("foo_bar", True), ("1234.txt", True), ("xYz.DAT", True),
            ("foo/bar.txt", False), ("foo/bar+bas-xyz.txt", False),
            (u"foo\u1234-bar\u4321", False),
            ("foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar",
             u"foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar\u2026"
             )
        ]
        for name, expect_identical in tests:
            path = common.filename_encode(name)
            if expect_identical == True:
                self.assertEqual(
                    path, name, "Encoding '%s' shouldn't change string" % name)
            else:
                self.assertTrue(
                    re.match(r"^[\w\.\-]*$", path),
                    "Encoding '%s' should replace all special characters" %
                    name)

            if isinstance(expect_identical, basestring):
                self.assertEqual(
                    common.filename_decode(path), expect_identical,
                    "Encoding and decoding '%s' should produce a truncated string as result"
                    % name)
            else:
                self.assertEqual(
                    common.filename_decode(path), name,
                    "Encoding and decoding '%s' should produce the original string"
                    % name)
def get_names(dir, needdirectories):
    for file in os.listdir(dir):
        path = os.path.join(dir, file)
        if (needdirectories
                and os.path.isdir(path)) or (not needdirectories
                                             and os.path.isfile(path)):
            yield common.filename_decode(file), path
Пример #3
0
  def test_fileencoding(self):
    tests = [
      ("foo_bar", True),
      ("1234.txt", True),
      ("xYz.DAT", True),
      ("foo/bar.txt", False),
      ("foo/bar+bas-xyz.txt", False),
      (u"foo\u1234-bar\u4321", False),
      ("foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar", u"foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar\u2026")
    ]
    for name, expect_identical in tests:
      path = common.filename_encode(name)
      if expect_identical == True:
        self.assertEqual(path, name, "Encoding '%s' shouldn't change string" % name)
      else:
        self.assertTrue(re.match(r"^[\w\.\-]*$", path), "Encoding '%s' should replace all special characters" % name)

      if isinstance(expect_identical, basestring):
        self.assertEqual(common.filename_decode(path), expect_identical, "Encoding and decoding '%s' should produce a truncated string as result" % name)
      else:
        self.assertEqual(common.filename_decode(path), name, "Encoding and decoding '%s' should produce the original string" % name)
Пример #4
0
def get_names(dir, needdirectories):
    for file in os.listdir(dir):
        path = os.path.join(dir, file)
        if (needdirectories and os.path.isdir(path)) or (not needdirectories and os.path.isfile(path)):
            yield common.filename_decode(file), path