# Path: deluge/common.py
# def decode_string(s, encoding="utf8"):
#     """
#     Decodes a string and re-encodes it in utf8.  If it cannot decode using
#     `:param:encoding` then it will try to detect the string encoding and
#     decode it.
# 
#     :param s: string to decode
#     :type s: string
#     :keyword encoding: the encoding to use in the decoding
#     :type encoding: string
# 
#     """
# 
#     try:
#         s = s.decode(encoding).encode("utf8", "ignore")
#     except UnicodeDecodeError:
#         s = s.decode(chardet.detect(s)["encoding"], "ignore").encode("utf8", "ignore")
#     return s
# 
# def path_join(*parts):
#     """
#     An implementation of os.path.join that always uses / for the separator
#     to ensure that the correct paths are produced when working with internal
#     paths on Windows.
#     """
#     path = ''
#     for part in parts:
#         if not part:
#             continue
#         elif part[0] == '/':
#             path = part
#         elif not path:
#             path = part
#         else:
#             path += '/' + part
#     return path


import os
import sys
import urlparse
import locale
import deluge.configmanager
    from hashlib import sha1 as sha
    from sha import sha
from deluge import bencode
from deluge.common import decode_string, path_join
from deluge.log import LOG as log
                file_tree = FileTree(paths)
                file_tree.walk(walk)
            self.__m_files_tree = file_tree.get_tree()
        else:
            if filetree == 2:
                self.__m_files_tree = {
                    "contents": {
                        self.__m_name: {
                            "type": "file",
                            "index": 0,
                            "length": self.__m_metadata["info"]["length"],
                            "download": True
                        }
                    }
                }
            else:
                self.__m_files_tree = {
                    self.__m_name: (0, self.__m_metadata["info"]["length"], True)
                }

        self.__m_files = []
        if self.__m_metadata["info"].has_key("files"):
            prefix = ""
            if len(self.__m_metadata["info"]["files"]) > 1:
                prefix = self.__m_name

            for f in self.__m_metadata["info"]["files"]:
                if "path.utf-8" in f:
                    path = os.path.join(prefix, *f["path.utf-8"])
                else:

# Path: deluge/common.py
# def decode_string(s, encoding="utf8"):
#     """
#     Decodes a string and re-encodes it in utf8.  If it cannot decode using
#     `:param:encoding` then it will try to detect the string encoding and
#     decode it.
# 
#     :param s: string to decode
#     :type s: string
#     :keyword encoding: the encoding to use in the decoding
#     :type encoding: string
# 
#     """
# 
#     try:
#         s = s.decode(encoding).encode("utf8", "ignore")
#     except UnicodeDecodeError:
#         s = s.decode(chardet.detect(s)["encoding"], "ignore").encode("utf8", "ignore")
#     return s
# 
# def path_join(*parts):
#     """
#     An implementation of os.path.join that always uses / for the separator
#     to ensure that the correct paths are produced when working with internal
#     paths on Windows.
#     """
#     path = ''
#     for part in parts:
#         if not part:
#             continue
#         elif part[0] == '/':
#             path = part
#         elif not path:
#             path = part
#         else:
#             path += '/' + part
#     return path


# Path: deluge/ui/common.py
import os
import sys
import urlparse
import locale
import deluge.configmanager
    from hashlib import sha1 as sha
    from sha import sha
from deluge import bencode
from deluge.common import decode_string, path_join
from deluge.log import LOG as log

                file_tree = FileTree(paths)
                file_tree.walk(walk)
            self.__m_files_tree = file_tree.get_tree()
        else:
            if filetree == 2:
                self.__m_files_tree = {
                    "contents": {
                        self.__m_name: {
                            "type": "file",
                            "index": 0,
                            "length": self.__m_metadata["info"]["length"],
                            "download": True
                        }
                    }
                }
            else:
                self.__m_files_tree = {
                    self.__m_name: (0, self.__m_metadata["info"]["length"], True)
                }

        self.__m_files = []
        if self.__m_metadata["info"].has_key("files"):
            prefix = ""
            if len(self.__m_metadata["info"]["files"]) > 1:
                prefix = self.__m_name

            for f in self.__m_metadata["info"]["files"]:
                if "path.utf-8" in f:
                    path = os.path.join(prefix, *f["path.utf-8"])
                else:

                    path = decode_string(os.path.join(prefix, decode_string(os.path.join(*f["path"]), self.encoding)), self.encoding)