Package libxyz :: Package core :: Package plugins :: Module ns |
[hide private]
[frames] | no frames]

# Source Code for Module libxyz.core.plugins.ns

     1  #-*- coding: utf8 -*
     2  #
     3  # Max E. Kuznecov ~syhpoon <syhpoon@syhpoon.name> 2008
     4  #
     5  # This file is part of XYZCommander.
     6  # XYZCommander is free software: you can redistribute it and/or modify
     7  # it under the terms of the GNU Lesser Public License as published by
     8  # the Free Software Foundation, either version 3 of the License, or
     9  # (at your option) any later version.
    10  # XYZCommander is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  # GNU Lesser Public License for more details.
    14  # You should have received a copy of the GNU Lesser Public License
    15  # along with XYZCommander. If not, see <http://www.gnu.org/licenses/>.
    16
    17  from libxyz.exceptions import XYZValueError
    18
    19 -class Namespace(object):
    20      """
    21      Plugin namespace abstraction
    22      """
    23
    24      # All wildcard
    25      ALL = u"*"
    26
    27 -    def __init__(self, path):
    28          _path = path
    29
    30          if not path.startswith(u":"):
    31              raise XYZValueError(_(u"Invalid plugin path: %s" % path))
    32          else:
    33              _path = path[1:]
    34
    35          _raw = _path.split(u":")
    36          _len = len(_raw)
    37
    38          if _len < 2 or _len > 3:
    39              raise XYZValueError(_(u"Invalid plugin path: %s" % path))
    40
    41          # Full namespace path
    42          self.full = path
    43          # Full plugin path without method name
    44          self.pfull = ":".join(("", _raw[0], _raw[1]))
    45          # Namespace part
    46          self.ns = _raw[0]
    47          # Plugin name
    48          self.plugin = _raw[1]
    49          # Method name
    50          self.method = None
    51
    52          # Internal representation
    53          self.internal = self._make_intern(self.full)
    54
    55          if _len == 3:
    56              self.method = _raw[2]
    57
    58      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    59
    60 -    def set_method(self, method):
    61          """
    62          Add method name to namespace
    63          """
    64
    65          self.method = method
    66          self.full += u":%s" % method
    67          self.internal = self._make_intern(self.full)
    68
    69      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    70
    71 -    def _make_intern(self, full):
    72          return full.replace(u":", u".")[1:]
    73
    74      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    75
    76 -    def __str__(self):
    77          return self.full
    78
    79      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    80
    81 -    def __repr__(self):
    82          return self.__str__()
    83
    84      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    85
    86 -    def __unicode__(self):
    87          return self.__str__()
    88
    89      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    90
    91 -    def __cmp__(self, other):
    92          return cmp(self.full, other)
    93
    94      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    95
    96 -    def __len__(self):
    97          return len(self.full)
    98