def samefile(self, other_path): """Return whether `other_file` is the same or not as this file. (as returned by os.path.samefile(file, other_file)). """ if hasattr(os.path, "samestat"): st = self.stat() try: other_st = other_path.stat() except AttributeError: other_st = os.stat(other_path) return os.path.samestat(st, other_st) else: filename1 = six.text_type(self) filename2 = six.text_type(other_path) st1 = _win32_get_unique_path_id(filename1) st2 = _win32_get_unique_path_id(filename2) return st1 == st2
def recurse(tree, path=[]): if isinstance(tree, dict): for key, val in six.iteritems(tree): for x in recurse(val, path + [key]): yield x elif isinstance(tree, (list, tuple)): for i, val in enumerate(tree): for x in recurse(val, path + [i]): yield x elif tree is not None: yield (str('.'.join(six.text_type(x) for x in path)), tree)
def recurse(tree, path=[]): if isinstance(tree, dict): for key, val in six.iteritems(tree): for x in recurse(val, path + [key]): yield x elif isinstance(tree, (list, tuple)): for i, val in enumerate(tree): for x in recurse(val, path + [i]): yield x elif tree is not None: yield ('.'.join(six.text_type(x) for x in path), tree)
def _get_indexed_keyword(keyword, i): for (sub, max, r) in _keyword_indices: if sub in keyword: if i >= max: raise ValueError( "Too many entries for given keyword '{0}'".format(keyword)) if r is None: val = six.text_type(i) else: val = r[i] keyword = keyword.replace(sub, val) return keyword
def uri(self): """ The URI pointing to the result """ # TODO: use a async job base class instead of hasattr for inspection if hasattr(self._content, "result_uri"): self._content.raise_if_error() uri = self._content.result_uri else: uri = six.text_type(self._content) return uri
def main_from_args(args): parser, subparsers = make_argparser() args = parser.parse_args(args) # Only needed for Python 3, apparently, but can't hurt if not hasattr(args, 'func'): parser.print_help() return 2 try: result = args.func(args) except RuntimeError as e: log.error(six.text_type(e)) return 1 except IOError as e: log.error(six.text_type(e)) return e.errno if result is None: result = 0 return result
def main_from_args(args): parser, subparsers = make_argparser() args = parser.parse_args(args) if not hasattr(args, 'func'): parser.print_help() return 1 try: result = args.func(args) except RuntimeError as e: log.error(six.text_type(e)) return 1 sys.stdout.write('\n') if result is None: result = 0 return result
def describe(self, width=None): """ Print a summary description of this service. This includes the interface capabilities, and the content description if it doesn't contains multiple data collections (in other words, it is not a TAP service). """ if len(self.tables) == 1: description = next(self.tables.values()).description if width: description = para_format_desc(description, width) print(description) print() capabilities = filter( lambda x: not six.text_type(x.standardid).startswith( 'ivo://ivoa.net/std/VOSI'), self.capabilities) for cap in capabilities: cap.describe() print()
def convert_datetimes(node, json_id): if isinstance(node, datetime.datetime): node = time.Time(node) if isinstance(node, time.Time): node = six.text_type(time.Time(node, format='iso')) return node
def to_tree(cls, node, ctx): return six.text_type(node)