| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | |
|---|
| 4 | # Copyright (C) 2005 Insecure.Com LLC. |
|---|
| 5 | # |
|---|
| 6 | # Author: Adriano Monteiro Marques <py.adriano@gmail.com> |
|---|
| 7 | # |
|---|
| 8 | # This program is free software; you can redistribute it and/or modify |
|---|
| 9 | # it under the terms of the GNU General Public License as published by |
|---|
| 10 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | # (at your option) any later version. |
|---|
| 12 | # |
|---|
| 13 | # This program is distributed in the hope that it will be useful, |
|---|
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | # GNU General Public License for more details. |
|---|
| 17 | # |
|---|
| 18 | # You should have received a copy of the GNU General Public License |
|---|
| 19 | # along with this program; if not, write to the Free Software |
|---|
| 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | |
|---|
| 22 | from umitCore.Logging import log |
|---|
| 23 | import codecs |
|---|
| 24 | |
|---|
| 25 | import locale |
|---|
| 26 | LC_ALL = locale.setlocale(locale.LC_ALL, '') |
|---|
| 27 | LANG, ENC = locale.getdefaultlocale() |
|---|
| 28 | ERRORS = "ignore" |
|---|
| 29 | |
|---|
| 30 | # If not correct locale could be retrieved, set en_US.utf8 as default |
|---|
| 31 | if not ENC: |
|---|
| 32 | ENC = "utf8" |
|---|
| 33 | |
|---|
| 34 | if not LANG: |
|---|
| 35 | LANG = "en_US" |
|---|
| 36 | |
|---|
| 37 | try: |
|---|
| 38 | import gettext |
|---|
| 39 | from gettext import gettext as _ |
|---|
| 40 | |
|---|
| 41 | gettext.install('umit', unicode=True) |
|---|
| 42 | |
|---|
| 43 | except ImportError: |
|---|
| 44 | log.critical("You don't have gettext module, no \ |
|---|
| 45 | internationalization will be used.") |
|---|
| 46 | |
|---|
| 47 | # define _() so program will not fail |
|---|
| 48 | import __builtin__ |
|---|
| 49 | __builtin__.__dict__["_"] = str |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | def enc(string): |
|---|
| 53 | """Encoding conversion. This function is entended to receive a locale |
|---|
| 54 | created string with locale encoding and return an utf8 string. |
|---|
| 55 | """ |
|---|
| 56 | log.debug(">>> Converting '%s' from '%s' to unicode" % (string, ENC)) |
|---|
| 57 | string = unicode(string, ENC, ERRORS) |
|---|
| 58 | log.debug(">>> Converted to: '%s'" % string) |
|---|
| 59 | |
|---|
| 60 | return string |
|---|
| 61 | |
|---|
| 62 | def open(filename, mode): |
|---|
| 63 | return codecs.open(filename, "r", ENC, "ignore") |
|---|
| 64 | |
|---|
| 65 | def read_file(filename): |
|---|
| 66 | fp = open(filename, "r") |
|---|
| 67 | content = fp.read().lstrip(codecs.BOM_UTF8) |
|---|
| 68 | fp.close() |
|---|
| 69 | |
|---|
| 70 | return content |
|---|
| 71 | |
|---|
| 72 | if __name__ == '__main__': |
|---|
| 73 | print _('UMIT - The nmap frontend') |
|---|