# Path: zim/errors.py
# class Error(Exception):
# 	'''Base class for all errors in zim.
# 
# 	This class is intended for application and usage errors, these will
# 	be caught in the user interface and presented as error dialogs.
# 	In contrast and Exception that does I{not} derive from this base
# 	class will result in a "You found a bug" dialog. Do not use this
# 	class e.g. to catch programming errors.
# 
# 	Subclasses should define two attributes. The first is 'msg', which is
# 	the short description of the error. Typically this gives the specific
# 	input / page / ... which caused the error. In there should be an attribute
# 	'description' (either as class attribute or object attribute) with a verbose
# 	description. This description can be less specific but should explain
# 	the error in a user friendly way. The default behavior is to take 'msg' as
# 	the single argument for the constructor. So a minimal subclass only needs
# 	to define a class attribute 'description'.
# 
# 	For a typical error dialog in the Gtk interface the short string from 'msg'
# 	will be shown as the title in bold letters while the longer 'description'
# 	is shown below it in normal letters. As a guideline error classes that are
# 	used in the gui or that can be e.g. be raised on invalid input from the
# 	user should be translated.
# 	'''
# 
# 	description = ''
# 	msg = '<Unknown Error>'
# 		# in case subclass does not define instance attribute
# 
# 	def __init__(self, msg, description=None):
# 		self.msg = msg
# 		self.description = description or ''
# 
# 	def __str__(self):
# 		msg = self.__unicode__()
# 		return msg.encode('utf-8')
# 
# 	def __unicode__(self):
# 		msg = u'' + self.msg.strip()
# 		if self.description:
# 			msg += '\n\n' + self.description.strip() + '\n'
# 		return msg
# 
# 	def __repr__(self):
# 		return '<%s: %s>' % (self.__class__.__name__, self.msg)
# 
# class TrashNotSupportedError(Error):
# 	'''Error raised when trashing is not supported and delete should
# 	be used instead
# 	'''
# 	pass
# 
# class TrashCancelledError(Error):
# 	'''Error raised when a trashign operation is cancelled. (E.g. on
# 	windows the system will prompt the user with a confirmation
# 	dialog which has a Cancel button.)
# 	'''
# 	pass


import os
import re
import sys
import shutil
import errno
import codecs
import logging
import threading
	import gobject
	import gio
	import xdg.Mime as xdgmime
	import mimetypes
	import tempfile
	import hashlib
					import time
from zim.errors import Error, TrashNotSupportedError, TrashCancelledError
from zim.parsing import url_encode, url_decode, URL_ENCODE_READABLE
from zim.signals import SignalEmitter, SIGNAL_AFTER
	from zim.environ import environ
	this platform
	'''

	# TODO __signals__

	def __init__(self, path):
		'''Constructor

		@param path: an absolute file path, file URL, L{FilePath} object
		or a list of path elements. When a list is given, the first
		element is allowed to be an absolute path, URL or L{FilePath}
		object as well.
		'''
		self._serialized = None

		if isinstance(path, FilePath):
			self.path = path.path
			self.encodedpath = path.encodedpath
			return

		try:
			if isinstance(path, (list, tuple)):
				path = map(unicode, path)
					# Flatten objects - strings should be unicode or ascii already
				path = os.path.sep.join(path)
					# os.path.join is too intelligent for it's own good
					# just join with the path separator.
			else:
				path = unicode(path) # make sure we can decode
		except UnicodeDecodeError:

# Path: zim/errors.py
# class Error(Exception):
# 	'''Base class for all errors in zim.
# 
# 	This class is intended for application and usage errors, these will
# 	be caught in the user interface and presented as error dialogs.
# 	In contrast and Exception that does I{not} derive from this base
# 	class will result in a "You found a bug" dialog. Do not use this
# 	class e.g. to catch programming errors.
# 
# 	Subclasses should define two attributes. The first is 'msg', which is
# 	the short description of the error. Typically this gives the specific
# 	input / page / ... which caused the error. In there should be an attribute
# 	'description' (either as class attribute or object attribute) with a verbose
# 	description. This description can be less specific but should explain
# 	the error in a user friendly way. The default behavior is to take 'msg' as
# 	the single argument for the constructor. So a minimal subclass only needs
# 	to define a class attribute 'description'.
# 
# 	For a typical error dialog in the Gtk interface the short string from 'msg'
# 	will be shown as the title in bold letters while the longer 'description'
# 	is shown below it in normal letters. As a guideline error classes that are
# 	used in the gui or that can be e.g. be raised on invalid input from the
# 	user should be translated.
# 	'''
# 
# 	description = ''
# 	msg = '<Unknown Error>'
# 		# in case subclass does not define instance attribute
# 
# 	def __init__(self, msg, description=None):
# 		self.msg = msg
# 		self.description = description or ''
# 
# 	def __str__(self):
# 		msg = self.__unicode__()
# 		return msg.encode('utf-8')
# 
# 	def __unicode__(self):
# 		msg = u'' + self.msg.strip()
# 		if self.description:
# 			msg += '\n\n' + self.description.strip() + '\n'
# 		return msg
# 
# 	def __repr__(self):
# 		return '<%s: %s>' % (self.__class__.__name__, self.msg)
# 
# class TrashNotSupportedError(Error):
# 	'''Error raised when trashing is not supported and delete should
# 	be used instead
# 	'''
# 	pass
# 
# class TrashCancelledError(Error):
# 	'''Error raised when a trashign operation is cancelled. (E.g. on
# 	windows the system will prompt the user with a confirmation
# 	dialog which has a Cancel button.)
# 	'''
# 	pass


# Path: zim/fs.py
import os
import re
import sys
import shutil
import errno
import codecs
import logging
import threading
	import gobject
	import gio
	import xdg.Mime as xdgmime
	import mimetypes
	import tempfile
	import hashlib
					import time
from zim.errors import Error, TrashNotSupportedError, TrashCancelledError
from zim.parsing import url_encode, url_decode, URL_ENCODE_READABLE
from zim.signals import SignalEmitter, SIGNAL_AFTER
	from zim.environ import environ

	this platform
	'''

	# TODO __signals__

	def __init__(self, path):
		'''Constructor

		@param path: an absolute file path, file URL, L{FilePath} object
		or a list of path elements. When a list is given, the first
		element is allowed to be an absolute path, URL or L{FilePath}
		object as well.
		'''
		self._serialized = None

		if isinstance(path, FilePath):
			self.path = path.path
			self.encodedpath = path.encodedpath
			return

		try:
			if isinstance(path, (list, tuple)):
				path = map(unicode, path)
					# Flatten objects - strings should be unicode or ascii already
				path = os.path.sep.join(path)
					# os.path.join is too intelligent for it's own good
					# just join with the path separator.
			else:
				path = unicode(path) # make sure we can decode
		except UnicodeDecodeError:

			raise Error, 'BUG: invalid input, file names should be in ascii, or given as unicode'