1111import os
1212
1313from . import exc , formats
14- from .common import EnvironmentMixin , TmuxRelationalObject , tmux_cmd
14+ from .common import EnvironmentMixin , TmuxRelationalObject , tmux_cmd , \
15+ session_check_name
1516from .session import Session
1617
1718logger = logging .getLogger (__name__ )
@@ -318,10 +319,13 @@ def has_session(self, target_session):
318319 """Return True if session exists. ``$ tmux has-session``.
319320
320321 :param: target_session: str of session name.
322+ :raises: :exc:`exc.BadSessionName`
321323 :rtype: bool
322324
323325 """
324326
327+ session_check_name (target_session )
328+
325329 proc = self .cmd ('has-session' , '-t%s' % target_session )
326330
327331 if not proc .stdout :
@@ -335,6 +339,8 @@ def has_session(self, target_session):
335339 return False
336340 elif 'can\' t find session' in proc .stdout : # tmux 2.1
337341 return False
342+ elif 'bad session name' in proc .stdout : # tmux >= 1.9
343+ return False
338344 elif 'session not found' in proc .stdout :
339345 return False
340346 else :
@@ -349,10 +355,12 @@ def kill_session(self, target_session=None):
349355
350356 :param: target_session: str. note this accepts ``fnmatch(3)``. 'asdf'
351357 will kill 'asdfasd'.
352-
358+ :raises: :exc:`exc.BadSessionName`
353359 :rtype: :class:`Server`
354360
355361 """
362+ session_check_name (target_session )
363+
356364 proc = self .cmd ('kill-session' , '-t%s' % target_session )
357365
358366 if proc .stderr :
@@ -364,8 +372,9 @@ def switch_client(self, target_session):
364372 """``$ tmux switch-client``.
365373
366374 :param: target_session: str. name of the session. fnmatch(3) works.
367-
375+ :raises: :exc:`exc.BadSessionName`
368376 """
377+ session_check_name (target_session )
369378
370379 proc = self .cmd ('switch-client' , '-t%s' % target_session )
371380
@@ -376,8 +385,10 @@ def attach_session(self, target_session=None):
376385 """``$ tmux attach-session`` aka alias: ``$ tmux attach``.
377386
378387 :param: target_session: str. name of the session. fnmatch(3) works.
379-
388+ :raises: :exc:`exc.BadSessionName`
380389 """
390+ session_check_name (target_session )
391+
381392 tmux_args = tuple ()
382393 if target_session :
383394 tmux_args += ('-t%s' % target_session ,)
@@ -418,9 +429,11 @@ def new_session(self,
418429 :param kill_session: Kill current session if ``$ tmux has-session``
419430 Useful for testing workspaces.
420431 :type kill_session: bool
432+ :raises: :exc:`exc.BadSessionName`
421433 :rtype: :class:`Session`
422434
423435 """
436+ session_check_name (session_name )
424437
425438 if self .has_session (session_name ):
426439 if kill_session :
0 commit comments