]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | # Licensed to the Apache Software Foundation (ASF) under one |
2 | # or more contributor license agreements. See the NOTICE file | |
3 | # distributed with this work for additional information | |
4 | # regarding copyright ownership. The ASF licenses this file | |
5 | # to you under the Apache License, Version 2.0 (the | |
6 | # "License"); you may not use this file except in compliance | |
7 | # with the License. You may obtain a copy of the License at | |
8 | # | |
9 | # http://www.apache.org/licenses/LICENSE-2.0 | |
10 | # | |
11 | # Unless required by applicable law or agreed to in writing, | |
12 | # software distributed under the License is distributed on an | |
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | # KIND, either express or implied. See the License for the | |
15 | # specific language governing permissions and limitations | |
16 | # under the License. | |
17 | ||
18 | import sys | |
19 | ||
20 | ||
21 | def encode_file_path(path): | |
22 | if isinstance(path, str): | |
23 | # POSIX systems can handle utf-8. UTF8 is converted to utf16-le in | |
24 | # libarrow | |
25 | encoded_path = path.encode('utf-8') | |
26 | else: | |
27 | encoded_path = path | |
28 | ||
29 | # Windows file system requires utf-16le for file names; Arrow C++ libraries | |
30 | # will convert utf8 to utf16 | |
31 | return encoded_path | |
32 | ||
33 | ||
34 | if sys.version_info >= (3, 7): | |
35 | # Starting with Python 3.7, dicts are guaranteed to be insertion-ordered. | |
36 | ordered_dict = dict | |
37 | else: | |
38 | import collections | |
39 | ordered_dict = collections.OrderedDict | |
40 | ||
41 | ||
42 | try: | |
43 | import pickle5 as builtin_pickle | |
44 | except ImportError: | |
45 | import pickle as builtin_pickle | |
46 | ||
47 | ||
48 | try: | |
49 | import cloudpickle as pickle | |
50 | except ImportError: | |
51 | pickle = builtin_pickle | |
52 | ||
53 | ||
54 | def tobytes(o): | |
55 | if isinstance(o, str): | |
56 | return o.encode('utf8') | |
57 | else: | |
58 | return o | |
59 | ||
60 | ||
61 | def frombytes(o, *, safe=False): | |
62 | if safe: | |
63 | return o.decode('utf8', errors='replace') | |
64 | else: | |
65 | return o.decode('utf8') |