Exemple #1
0
 def visit_method(self, dirname, names):
     d = uri.URI.from_path(os.path.join(dirname, os.curdir))
     c = sys.getfilesystemencoding()
     for name in names:
         if name.startswith('??'):
             logging.warn("8-bit path tests limited to ASCII file names "
                          "by %s encoding", c)
             continue
         join_match = os.path.join(dirname, name)
         if type(name) is UnicodeType:
             seg_name = uri.escape_data(
                 name.encode('utf-8'), uri.is_path_segment_reserved)
         else:
             seg_name = uri.escape_data(name, uri.is_path_segment_reserved)
         u = uri.URI(seg_name)
         u = u.resolve(d)
         self.assertTrue(isinstance(u, uri.FileURL))
         joined = u.get_pathname()
         if type(join_match) is StringType and type(joined) is UnicodeType:
             # if we're walking in 8-bit mode we need to downgrade to
             # compare
             joined = joined.encode(c)
         self.assertTrue(joined == join_match,
                         "Joined pathnames mismatch:\n%s\n%s" %
                         (joined, join_match))
Exemple #2
0
 def visit_method(self, dirname, names):
     d = uri.URI.from_path(os.path.join(dirname, self.sys_path(os.curdir)))
     c = sys.getfilesystemencoding()
     for name in names:
         # on windows, c will be mbcs even if strings are unicode
         bname = name.encode(c) if is_unicode(name) else name
         if bname.startswith(b'??'):
             logging.warn("8-bit path tests limited to ASCII file names "
                          "by %s encoding", c)
             continue
         join_match = os.path.join(dirname, name)
         if is_unicode(name):
             seg_name = uri.escape_data(
                 name.encode(c), uri.is_path_segment_reserved)
         else:
             seg_name = uri.escape_data(name, uri.is_path_segment_reserved)
         u = uri.URI(seg_name)
         u = u.resolve(d)
         self.assertTrue(isinstance(u, uri.FileURL))
         joined = u.get_pathname()
         if isinstance(join_match, bytes) and is_unicode(joined):
             # if we're walking in 8-bit mode we need to downgrade to
             # compare
             joined = joined.encode(c)
         self.assertTrue(joined == join_match,
                         "Joined pathnames mismatch:\n%s\n%s" %
                         (joined, join_match))
Exemple #3
0
 def visit_method(self, dirname, names):
     d = uri.URI.from_path(os.path.join(dirname, os.curdir))
     c = sys.getfilesystemencoding()
     for name in names:
         if name.startswith('??'):
             logging.warn("8-bit path tests limited to ASCII file names "
                          "by %s encoding", c)
             continue
         join_match = os.path.join(dirname, name)
         if is_unicode(name):
             seg_name = uri.escape_data(
                 name.encode(c), uri.is_path_segment_reserved)
         else:
             seg_name = uri.escape_data(name, uri.is_path_segment_reserved)
         u = uri.URI(seg_name)
         u = u.resolve(d)
         self.assertTrue(isinstance(u, uri.FileURL))
         joined = u.get_pathname()
         if isinstance(join_match, bytes) and is_unicode(joined):
             # if we're walking in 8-bit mode we need to downgrade to
             # compare
             joined = joined.encode(c)
         self.assertTrue(joined == join_match,
                         "Joined pathnames mismatch:\n%s\n%s" %
                         (joined, join_match))
Exemple #4
0
 def test_escape(self):
     data = "\t\n\r !\"#$%&'()*+,-./0123456789:;<=>?@"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
     escaped_normal = "%09%0A%0D%20!%22%23%24%25%26'()*%2B%2C-.%2F"\
         "0123456789%3A%3B%3C%3D%3E%3F%40"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     escaped_max = "%09%0A%0D%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D"\
         "%2E%2F0123456789%3A%3B%3C%3D%3E%3F%40"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E%5F%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
     escaped_min = "%09%0A%0D%20!%22%23$%25&'()*+,-./0123456789:;%3C=%3E?@"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     self.compare_strings(
         escaped_normal, uri.escape_data(data), "Normal escaping")
     self.compare_strings(escaped_max, uri.escape_data(data,
                          lambda x: not uri.is_alpha_num(x)),
                          "Max escaping")
     self.compare_strings(
         escaped_min, uri.escape_data(data, lambda x: False),
         "Min escaping")
     self.compare_strings(data,
                          uri.unescape_data(uri.escape_data(data)),
                          "Round-trip escaping")
Exemple #5
0
 def test_escape(self):
     data = "\t\n\r !\"#$%&'()*+,-./0123456789:;<=>?@"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
     escaped_normal = "%09%0A%0D%20!%22%23%24%25%26'()*%2B%2C-.%2F"\
         "0123456789%3A%3B%3C%3D%3E%3F%40"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     escaped_max = "%09%0A%0D%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D"\
         "%2E%2F0123456789%3A%3B%3C%3D%3E%3F%40"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E%5F%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
     escaped_min = "%09%0A%0D%20!%22%23$%25&'()*+,-./0123456789:;%3C=%3E?@"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     self.compare_strings(escaped_normal, uri.escape_data(data),
                          "Normal escaping")
     self.compare_strings(
         escaped_max,
         uri.escape_data(data, lambda x: not uri.is_alpha_num(x)),
         "Max escaping")
     self.compare_strings(escaped_min,
                          uri.escape_data(data,
                                          lambda x: False), "Min escaping")
     self.compare_strings(data, uri.unescape_data(uri.escape_data(data)),
                          "Round-trip escaping")
Exemple #6
0
 def __init__(self, from_entity, name, **kwargs):
     if kwargs.pop('baseURI', None):
         logging.warn(
             'OData Client NavigationCollection ignored baseURI argument')
     navPath = uri.escape_data(name.encode('utf-8'))
     location = str(from_entity.get_location())
     super(NavigationCollection, self).__init__(
         from_entity=from_entity,
         name=name,
         baseURI=uri.URI.from_octets(location + "/" + navPath),
         **kwargs)
     self.isCollection = self.from_entity[name].isCollection
     self.linksURI = uri.URI.from_octets(location + "/$links/" + navPath)
Exemple #7
0
 def visit_method(self, dirname, names):
     # Make d a directory like path by adding an empty component at the end
     d = uri.URI.from_virtual_path(dirname.join(dirname.curdir))
     for name in names:
         if unicode(name).startswith('??'):
             logging.warn("8-bit path tests limited to ASCII file names")
             continue
         join_match = dirname.join(name)
         seg_name = uri.escape_data(
             unicode(name).encode('utf-8'), uri.is_path_segment_reserved)
         u = uri.URI(seg_name)
         u = u.resolve(d)
         self.assertTrue(isinstance(u, uri.FileURL))
         joined = u.get_virtual_file_path()
         self.assertTrue(joined == join_match,
                         "Joined pathnames mismatch:\n%s\n%s" %
                         (joined, join_match))
Exemple #8
0
 def visit_method(self, dirname, names):
     # Make d a directory like path by adding an empty component at the end
     d = uri.URI.from_virtual_path(dirname.join(dirname.curdir))
     for name in names:
         if unicode(name).startswith('??'):
             logging.warn("8-bit path tests limited to ASCII file names")
             continue
         join_match = dirname.join(name)
         seg_name = uri.escape_data(
             unicode(name).encode('utf-8'), uri.is_path_segment_reserved)
         u = uri.URI(seg_name)
         u = u.resolve(d)
         self.assertTrue(isinstance(u, uri.FileURL))
         joined = u.get_virtual_file_path()
         self.assertTrue(
             joined == join_match,
             "Joined pathnames mismatch:\n%s\n%s" % (joined, join_match))
Exemple #9
0
 def __init__(self, from_entity, name, **kwargs):
     if kwargs.pop('baseURI', None):
         logging.warn(
             'OData Client NavigationCollection ignored baseURI argument')
     navPath = uri.escape_data(name.encode('utf-8'))
     location = str(from_entity.get_location())
     super(
         NavigationCollection,
         self).__init__(
         from_entity=from_entity,
         name=name,
         baseURI=uri.URI.from_octets(
             location +
             "/" +
             navPath),
         **kwargs)
     self.isCollection = self.from_entity[name].isCollection
     self.linksURI = uri.URI.from_octets(location + "/$links/" + navPath)
Exemple #10
0
 def test_escape(self):
     data = "\t\n\r !\"#$%&'()*+,-./0123456789:;<=>?@"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
     escaped_normal = "%09%0A%0D%20!%22%23%24%25%26'()*%2B%2C-.%2F"\
         "0123456789%3A%3B%3C%3D%3E%3F%40"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     escaped_max = "%09%0A%0D%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D"\
         "%2E%2F0123456789%3A%3B%3C%3D%3E%3F%40"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E%5F%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
     escaped_min = "%09%0A%0D%20!%22%23$%25&'()*+,-./0123456789:;%3C=%3E?@"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ[%5C]%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     escaped_min_2396 = "%09%0A%0D%20!%22%23$%25&'()*+,-./0123456789:;%3C"\
         "=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     self.compare_strings(escaped_normal, uri.escape_data(data),
                          "Normal escaping")
     self.compare_strings(
         escaped_max, uri.escape_data(data,
                                      lambda x: not uri.is_alphanum(x)),
         "Max escaping")
     self.compare_strings(escaped_min,
                          uri.escape_data(data,
                                          lambda x: False), "Min escaping")
     self.compare_strings(
         escaped_min_2396,
         uri.escape_data(data,
                         lambda x: False,
                         allowed_test=uri.is_allowed_2396), "Min escaping")
     self.compare_strings(
         data,
         uri.unescape_data(uri.escape_data(data)).decode('ascii'),
         "Round-trip escaping")
     try:
         uri.escape_data(ul('Caf\xe9'))
         self.fail("non-ASCII character for escaping")
     except UnicodeEncodeError:
         pass
     # byte strings can contain any data, no UTF-8 encoding is done
     self.assertTrue(uri.escape_data(b'Caf\xe9') == "Caf%E9")
Exemple #11
0
 def test_escape(self):
     data = "\t\n\r !\"#$%&'()*+,-./0123456789:;<=>?@"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
     escaped_normal = "%09%0A%0D%20!%22%23%24%25%26'()*%2B%2C-.%2F"\
         "0123456789%3A%3B%3C%3D%3E%3F%40"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     escaped_max = "%09%0A%0D%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D"\
         "%2E%2F0123456789%3A%3B%3C%3D%3E%3F%40"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E%5F%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
     escaped_min = "%09%0A%0D%20!%22%23$%25&'()*+,-./0123456789:;%3C=%3E?@"\
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ[%5C]%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     escaped_min_2396 = "%09%0A%0D%20!%22%23$%25&'()*+,-./0123456789:;%3C"\
         "=%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60"\
         "abcdefghijklmnopqrstuvwxyz%7B%7C%7D~"
     self.compare_strings(
         escaped_normal, uri.escape_data(data), "Normal escaping")
     self.compare_strings(escaped_max, uri.escape_data(data,
                          lambda x: not uri.is_alphanum(x)),
                          "Max escaping")
     self.compare_strings(
         escaped_min, uri.escape_data(data, lambda x: False),
         "Min escaping")
     self.compare_strings(
         escaped_min_2396, uri.escape_data(
             data, lambda x: False, allowed_test=uri.is_allowed_2396),
         "Min escaping")
     self.compare_strings(
         data, uri.unescape_data(uri.escape_data(data)).decode('ascii'),
         "Round-trip escaping")
     try:
         uri.escape_data(ul('Caf\xe9'))
         self.fail("non-ASCII character for escaping")
     except UnicodeEncodeError:
         pass
     # byte strings can contain any data, no UTF-8 encoding is done
     self.assertTrue(uri.escape_data(b'Caf\xe9') == "Caf%E9")