import sys import os import string import re import random def escape(s): """This is a utility function to escape and return a string.""" s = string.replace(s, '\t', '\\t') s = string.replace(s, '"', '\\"') s = string.replace(s, '\n', '\\n') s = string.replace(s, '\r', '\\r') s = string.replace(s, '\\', '\\\\') return s def unescape(s): """This is a utility function to unescape and return a string.""" s = string.replace(s, '\\t', '\t') s = string.replace(s, '\\"', '"') s = string.replace(s, '\\n', '\n') s = string.replace(s, '\\r', '\r') s = string.replace(s, '\\\\', '\\') return s def generatecontext(): """Generates an alphanum string with 351,964,250,202,852,352 combinations.""" anchrs, achrs = [], [] anstr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' astr = 'abcdefghijklmnopqrstuvwxyz' for c in anstr: anchrs.append(c) for c in astr: achrs.append(c) a = random.choice(achrs)+random.choice(anchrs)+random.choice(anchrs) b = random.choice(anchrs)+random.choice(anchrs)+random.choice(anchrs) c = random.choice(anchrs)+random.choice(anchrs)+random.choice(anchrs) d = random.choice(anchrs) return a+b+c+d # 10 characters, makes a valid bnode def generateint(): return str(random.randrange(0,9,1)) def uri2qname(s): # print str(s) if '#' in s: x = string.split(s, '#') # print str(x) return [x[0]+'#',x[1]] else: return [s[:-1],s[-1]]