Skip to content

Commit

Permalink
Merge pull request #70 from Kjwon15/default-session-name
Browse files Browse the repository at this point in the history
Add new method "Session.get_default_name()"
  • Loading branch information
dahlia committed Jul 9, 2015
2 parents 5144b34 + 5e0bc87 commit 003a993
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ To be released.
:class:`~libearth.feed.Text` type.
The :func:`~libearth.sanitizer.sanitize_html()` function became to
additionally require ``base_uri`` parameter.
- Added :meth:`~libearth.session.Session.get_default_name()` for default
session name.


Version 0.3.3
Expand Down
12 changes: 11 additions & 1 deletion libearth/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""
import collections
import datetime
import platform
import re
import uuid
import xml.sax
Expand Down Expand Up @@ -72,7 +73,7 @@ def __new__(cls, identifier=None):
if not (identifier is None or isinstance(identifier, string_type)):
raise TypeError('identifier must be a string, not ' +
repr(identifier))
identifier = str(identifier) if identifier else str(uuid.getnode())
identifier = str(identifier) if identifier else cls.get_default_name()
if not cls.IDENTIFIER_PATTERN.match(identifier):
raise ValueError('invalid identifier format: ' + repr(identifier))
try:
Expand All @@ -92,6 +93,15 @@ def __ne__(self, other):
def __hash__(self):
return hash(self.identifier)

@staticmethod
def get_default_name():
"""Create default session name.
:return: Default session name formatted as "Hostname-UUID".
:rtype: :class:`str`
"""
return '{0}-{1}'.format(platform.node(), uuid.getnode())

def revise(self, document):
"""Mark the given ``document`` as the latest revision of the current
session.
Expand Down

0 comments on commit 003a993

Please sign in to comment.