File: BNode.py

package info (click to toggle)
python-feedvalidator 0~svn1022-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 652 kB
  • ctags: 2,452
  • sloc: python: 9,481; makefile: 27; sh: 8
file content (25 lines) | stat: -rwxr-xr-x 639 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from string import ascii_letters
from random import choice

from rdflib.Identifier import Identifier
from rdflib.Literal import Literal

# Create a (hopefully) unique prefix so that BNode values do not
# collide with ones created with a different instance of this module.
prefix = ""
for i in xrange(0,8):
    prefix += choice(ascii_letters)

node_id = 0
class BNode(Identifier):
    def __new__(cls, value=None):
        if value==None:
            global node_id
            node_id += 1
            value = "_:%s%s" % (prefix, node_id)
        return Identifier.__new__(cls, value)
        
    def n3(self):
        return str(self)