signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def unwrap( <EOL>self, algorithm, wrapped_key, wrapped_key_algorithm, wrapped_key_type, additional_associated_data=None<EOL>):<EOL>
_raise_not_implemented("<STR_LIT>")<EOL>
Wrap content key. :param str algorithm: Text description of algorithm to use to unwrap key :param bytes content_key: Raw content key to wrap :param str wrapped_key_algorithm: Text description of algorithm for unwrapped key to use :param EncryptionKeyType wrapped_key_type: Type of key to...
f5643:c0:m6
def sign(self, algorithm, data): <EOL>
_raise_not_implemented("<STR_LIT>")<EOL>
Sign data. :param str algorithm: Text description of algorithm to use to sign data :param bytes data: Data to sign :returns: Signature value :rtype: bytes
f5643:c0:m7
def verify(self, algorithm, signature, data): <EOL>
_raise_not_implemented("<STR_LIT>")<EOL>
Sign data. :param str algorithm: Text description of algorithm to use to verify signature :param bytes signature: Signature to verify :param bytes data: Data over which to verify signature
f5643:c0:m8
def signing_algorithm(self): <EOL>
_raise_not_implemented("<STR_LIT>")<EOL>
Provide a description that can inform an appropriate cryptographic materials provider about how to build a :class:`DelegatedKey` for signature verification. If implemented, the return value of this method is included in the material description written to the encrypted item. :returns: S...
f5643:c0:m9
def read(*args):
return io.open(os.path.join(HERE, *args), encoding="<STR_LIT:utf-8>").read()<EOL>
Reads complete file contents.
f5644:m0
def get_version():
init = read("<STR_LIT:src>", "<STR_LIT>", "<STR_LIT>")<EOL>return VERSION_RE.search(init).group(<NUM_LIT:1>)<EOL>
Reads the version from this module.
f5644:m1
def get_requirements():
requirements = read("<STR_LIT>")<EOL>return [r for r in requirements.strip().splitlines()]<EOL>
Reads the requirements file.
f5644:m2
def get(self):
self.log.debug('<STR_LIT>')<EOL>if self.format == "<STR_LIT>":<EOL><INDENT>if self.urlOrPath[:<NUM_LIT:4>] == "<STR_LIT:http>" or self.urlOrPath[:<NUM_LIT:4>] == "<STR_LIT>":<EOL><INDENT>ebook = self._url_to_epub()<EOL><DEDENT>elif "<STR_LIT>" in self.urlOrPath:<EOL><INDENT>ebook = self._docx_to_epub()<EOL><DEDENT><DED...
*get the ebook object* **Return:** - ``ebook`` **Usage:** See class docstring for usage
f5650:c0:m1
def _url_to_epub(<EOL>self):
self.log.debug('<STR_LIT>')<EOL>from polyglot import htmlCleaner<EOL>cleaner = htmlCleaner(<EOL>log=self.log,<EOL>settings=self.settings,<EOL>url=self.urlOrPath,<EOL>outputDirectory=self.outputDirectory,<EOL>title=self.title, <EOL>style=False, <EOL>metadata=True, <EOL>h1=False <EOL>)<EOL>html = cleaner.clean()<EOL>...
*generate the epub book from a URL*
f5650:c0:m2
def _tmp_html_file(<EOL>self,<EOL>content):
self.log.debug('<STR_LIT>')<EOL>content =
*create a tmp html file with some content used for the header or footer of the ebook* **Key Arguments:** - ``content`` -- the content to include in the HTML file.
f5650:c0:m3
def _epub_to_mobi(<EOL>self,<EOL>epubPath,<EOL>deleteEpub=False):
self.log.debug('<STR_LIT>')<EOL>mobi = epubPath.replace("<STR_LIT>", "<STR_LIT>")<EOL>kindlegen = self.settings["<STR_LIT>"]["<STR_LIT>"]<EOL>cmd = """<STR_LIT>""" % locals(<EOL>)<EOL>p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)<EOL>stdout, stderr = p.communicate()<EOL>self.log.debug('<STR_LIT>' % locals())<EOL...
*convert the give epub to mobi format using kindlegen* **Key Arguments:** - ``epubPath`` -- path to the epub book - ``deleteEpub`` -- delete the epub when mobi is generated. Default *False* **Return:** - ``mobi`` -- the path to the generated mobi book
f5650:c0:m4
def _docx_to_epub(<EOL>self):
self.log.debug('<STR_LIT>')<EOL>if self.footer:<EOL><INDENT>footer = self._tmp_html_file(self.footer)<EOL>footer = '<STR_LIT>' % locals()<EOL><DEDENT>else:<EOL><INDENT>footer = "<STR_LIT>"<EOL><DEDENT>if self.header:<EOL><INDENT>header = self._tmp_html_file(self.header)<EOL>header = '<STR_LIT>' % locals()<EOL><DEDENT>e...
*convert docx file to epub*
f5650:c0:m5
def create(self, url, pathToWebarchive):
self.log.debug('<STR_LIT>')<EOL>from subprocess import Popen, PIPE, STDOUT<EOL>webarchiver = self.settings["<STR_LIT>"]["<STR_LIT>"]<EOL>cmd = """<STR_LIT>""" % locals()<EOL>p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)<EOL>stdout, stderr = p.communicate()<EOL>self.log.debug('<STR_LIT>' % locals())<EOL>if len(st...
*create the webarchive object* **Key Arguments:** - ``url`` -- the url of the webpage to generate the webarchive for - ``pathToWebarchive`` -- tthe path to output the the webarchive file to **Return:** - ``webarchive`` -- the path to the webarchive (or -1 if the generation fails) **Usage:** See cla...
f5651:c0:m1
def clean(<EOL>self):
self.log.debug('<STR_LIT>')<EOL>url = self.url<EOL>parser_response = self._request_parsed_article_from_mercury(url)<EOL>if "<STR_LIT>" in str(parser_response):<EOL><INDENT>return None<EOL><DEDENT>article = parser_response.json()<EOL>if not article:<EOL><INDENT>return None<EOL><DEDENT>if self.style:<EOL><INDENT>moduleDi...
*parse and clean the html document with Mercury Parser* **Return:** - ``filePath`` -- path to the cleaned HTML document **Usage:** See class usage
f5652:c0:m1
def _request_parsed_article_from_mercury(<EOL>self,<EOL>url):
self.log.debug(<EOL>'<STR_LIT>')<EOL>try:<EOL><INDENT>response = requests.get(<EOL>url="<STR_LIT>",<EOL>params={<EOL>"<STR_LIT:url>": url,<EOL>},<EOL>headers={<EOL>"<STR_LIT>": self.settings["<STR_LIT>"],<EOL>},<EOL>)<EOL><DEDENT>except requests.exceptions.RequestException:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>se...
* request parsed article from mercury* **Key Arguments:** - ``url`` -- the URL to the HTML page to parse and clean **Return:** - None **Usage:** .. todo:: - add usage info - create a sublime snippet for usage ...
f5652:c0:m2
def getpackagepath():
moduleDirectory = os.path.dirname(__file__)<EOL>packagePath = os.path.dirname(__file__) + "<STR_LIT>"<EOL>return packagePath<EOL>
*Get the root path for this python package* *Used in unit testing code*
f5653:m0
def main(arguments=None):
<EOL>su = tools(<EOL>arguments=arguments,<EOL>docString=__doc__,<EOL>logLevel="<STR_LIT>",<EOL>options_first=False,<EOL>projectName="<STR_LIT>"<EOL>)<EOL>arguments, settings, log, dbConn = su.setup()<EOL>for arg, val in arguments.iteritems():<EOL><INDENT>if arg[<NUM_LIT:0>] == "<STR_LIT:->":<EOL><INDENT>varname = arg.r...
*The main function used when ``cl_utils.py`` is run as a single script from the cl, or when installed as a cl command*
f5654:m0
def get(self):
self.log.debug('<STR_LIT>')<EOL>if not self.append:<EOL><INDENT>self.append = "<STR_LIT>"<EOL><DEDENT>if not self.readability:<EOL><INDENT>pdfPath = self._print_original_webpage()<EOL><DEDENT>else:<EOL><INDENT>pdfPath = self._print_parsed_webpage()<EOL><DEDENT>tag(<EOL>log=self.log,<EOL>filepath=pdfPath,<EOL>tags="<STR...
*get the PDF* **Return:** - ``pdfPath`` -- the path to the generated PDF
f5655:c0:m1
def _print_original_webpage(<EOL>self):
self.log.debug('<STR_LIT>')<EOL>if not self.title:<EOL><INDENT>r = requests.get(self.url)<EOL>title = bs4.BeautifulSoup(r.text).title.text<EOL>print(title)<EOL><DEDENT>else:<EOL><INDENT>title = self.title<EOL><DEDENT>url = self.url<EOL>pdfPath = self.folderpath + "<STR_LIT:/>" + title + self.append + "<STR_LIT>"<EOL>el...
*print the original webpage* **Return:** - ``pdfPath`` -- the path to the generated PDF
f5655:c0:m2
def _print_parsed_webpage(<EOL>self):
self.log.debug('<STR_LIT>')<EOL>from polyglot import htmlCleaner<EOL>cleaner = htmlCleaner(<EOL>log=self.log,<EOL>settings=self.settings,<EOL>url=self.url,<EOL>outputDirectory=self.folderpath,<EOL>title=self.title, <EOL>style=True, <EOL>metadata=True, <EOL>h1=True <EOL>)<EOL>htmlFile = cleaner.clean()<EOL>if not ht...
*print the parsed/cleaned webpage* **Return:** - ``pdfPath`` -- the path to the generated PDF
f5655:c0:m3
def send(<EOL>self):
self.log.debug('<STR_LIT>')<EOL>if self.urlOrPath.split("<STR_LIT:.>")[-<NUM_LIT:1>] == "<STR_LIT>":<EOL><INDENT>if self.title:<EOL><INDENT>pathToMobi = self.outputDirectory + "<STR_LIT:/>" + self.title + "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>pathToMobi = self.outputDirectory + "<STR_LIT:/>" +os.path.basename(self....
*send the mobi book generated to kindle email address(es)* **Return:** - ``success`` -- True or False depending on the success/failure of sending the email to the kindle email address(es).
f5659:c0:m1
def get_attachment(self, file_path):
try:<EOL><INDENT>file_ = open(file_path, '<STR_LIT:rb>')<EOL>attachment = MIMEBase('<STR_LIT>', '<STR_LIT>')<EOL>attachment.set_payload(file_.read())<EOL>file_.close()<EOL>encoders.encode_base64(attachment)<EOL>attachment.add_header('<STR_LIT>', '<STR_LIT>',<EOL>filename=os.path.basename(file_path))<EOL>return attachme...
Get file as MIMEBase message
f5659:c0:m2
def convert(self):
self.log.debug('<STR_LIT>')<EOL>import codecs<EOL>pathToReadFile = self.kindleExportPath<EOL>try:<EOL><INDENT>self.log.debug("<STR_LIT>" %<EOL>(pathToReadFile,))<EOL>readFile = codecs.open(pathToReadFile, encoding='<STR_LIT:utf-8>', mode='<STR_LIT:r>')<EOL>annotations = readFile.read()<EOL>readFile.close()<EOL><DEDENT>...
*convert the kindle_notebook object* **Return:** - ``kindle_notebook`` **Usage:** .. todo:: - add usage info - create a sublime snippet for usage - update the package tutorial if needed .. code-block:: python usage code
f5660:c0:m1
def bold(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT>", "<STR_LIT>")<EOL>
*convert plain-text to MMD bolded text* **Key Arguments:** - ``text`` -- the text to convert to MMD bold **Return:** - ``text`` -- the bolded text **Usage:** To convert a text block to bolded text: .. code-block:: python text ...
f5664:c0:m1
def em(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT:_>", "<STR_LIT:_>")<EOL>
*convert plain-text to MMD italicised text* **Key Arguments:** - ``text`` -- the text to convert to MMD italics **Return:** - ``text`` -- the emphasised text **Usage:** To convert a text block to emphasised text: .. code-block:: python ...
f5664:c0:m2
def underline(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT>", "<STR_LIT>")<EOL>
*convert plain-text to HTML underline text* **Key Arguments:** - ``text`` -- the text to convert to HTML underlined **Return:** - ``text`` -- the underlined text **Usage:** To convert a text block to underlined text: .. code-block:: python ...
f5664:c0:m3
def strike(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT>", "<STR_LIT>")<EOL>
*convert plain-text to HTML strike-through text* **Key Arguments:** - ``text`` -- the text to convert to HTML strike-through **Return:** - ``text`` -- the strike-through text **Usage:** To convert a text block to strike-through text: .. code-b...
f5664:c0:m4
def hl(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT>", "<STR_LIT>")<EOL>
*convert plain-text to MMD critical markup highlighted text* **Key Arguments:** - ``text`` -- the text to convert to MMD highlighted text **Return:** - ``text`` -- the highlighted text **Usage:** To convert a text block to highlighted text: .....
f5664:c0:m5
def code(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT>", "<STR_LIT>")<EOL>
*convert plain-text to MMD inline-code text* **Key Arguments:** - ``text`` -- the text to convert to MMD inline-code text **Return:** - ``text`` -- the inline-code text **Usage:** To convert a text block to inline-code text: .. code-block:: py...
f5664:c0:m6
def comment(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT>", "<STR_LIT>")<EOL>
*convert plain-text to MMD comment* **Key Arguments:** - ``text`` -- the text to convert to MMD comment **Return:** - ``text`` -- the comment text **Usage:** To convert a text block to comment text: .. code-block:: python text...
f5664:c0:m7
def footnote(<EOL>self,<EOL>text):
rand = str(randint(<NUM_LIT:0>, <NUM_LIT>))<EOL>now = datetime.now()<EOL>now = now.strftime("<STR_LIT>") + rand<EOL>text = text.strip()<EOL>regex = re.compile(r'<STR_LIT>')<EOL>text = regex.sub("<STR_LIT>", text)<EOL>return "<STR_LIT>" % locals()<EOL>
*convert plain-text to MMD footnote* **Key Arguments:** - ``text`` -- the text to convert to MMD footnote **Return:** - ``text`` -- the footnote text **Usage:** To convert a text block to footnote text: .. code-block:: python ...
f5664:c0:m8
def glossary(<EOL>self,<EOL>term,<EOL>definition):
term = term.strip()<EOL>term = term.lower()<EOL>title = term.title()<EOL>definition = definition.strip()<EOL>regex = re.compile(r'<STR_LIT>')<EOL>definition = regex.sub("<STR_LIT>", definition)<EOL>return "<STR_LIT>" % locals()<EOL>
*genarate a MMD glossary* **Key Arguments:** - ``term`` -- the term to add as a glossary item - ``definition`` -- the definition of the glossary term **Return:** - ``glossary`` -- the glossary text **Usage:** To genarate a glossary item: ...
f5664:c0:m9
def cite(<EOL>self,<EOL>title,<EOL>author=False,<EOL>year=False,<EOL>url=False,<EOL>publisher=False,<EOL>mediaKind=False,<EOL>linkedText=False,<EOL>nocite=False):
rand = str(randint(<NUM_LIT:0>, <NUM_LIT:100>))<EOL>anchor = title.replace("<STR_LIT:U+0020>", "<STR_LIT>").lower()<EOL>title = title.title()<EOL>citation = "<STR_LIT>"<EOL>if author:<EOL><INDENT>author = author.title() + "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>author = "<STR_LIT>"<EOL><DEDENT>if title[-<NUM_LIT:1>] ...
*generate a MMD citation* **Key Arguments:** - ``title`` -- the citation title - ``author`` -- the author. Default *False* - ``year`` -- year published. Default *False* - ``url`` -- url to the media. Default *False* - ``publisher`` -- the publisher of...
f5664:c0:m10
def url(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT:<>", "<STR_LIT:>>")<EOL>
*convert plain-text to MMD clickable URL* **Key Arguments:** - ``text`` -- the text to convert to MMD clickable URL **Return:** - ``text`` -- the URL text **Usage:** To convert a text block to MMD clickable URL: .. code-block:: python ...
f5664:c0:m11
def math_inline(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT:$>", "<STR_LIT:$>")<EOL>
*convert plain-text to MMD inline math* **Key Arguments:** - ``text`` -- the text to convert to MMD inline math **Return:** - ``math`` -- the inline math text **Usage:** To convert a text to MMD inline math: .. code-block:: python ...
f5664:c0:m12
def math_block(<EOL>self,<EOL>text):
return self._surround(text, "<STR_LIT>", "<STR_LIT>")<EOL>
*convert plain-text to MMD math block* **Key Arguments:** - ``text`` -- the text to convert to MMD math block **Return:** - ``math`` -- the math block text **Usage:** To convert a text to MMD math block: .. code-block:: python ...
f5664:c0:m13
def header(<EOL>self,<EOL>text,<EOL>level):
m = self.reWS.match(text)<EOL>prefix = m.group(<NUM_LIT:1>)<EOL>text = m.group(<NUM_LIT:2>)<EOL>suffix = m.group(<NUM_LIT:3>)<EOL>return "<STR_LIT:#>" * level + "<STR_LIT>" % locals()<EOL>
*convert plain-text to MMD header* **Key Arguments:** - ``text`` -- the text to convert to MMD header - ``level`` -- the header level to convert the text to **Return:** - ``header`` -- the MMD header **Usage:** To convert a text MMD header: ...
f5664:c0:m14
def definition(<EOL>self,<EOL>text,<EOL>definition):
text = text.strip()<EOL>definition = definition.strip()<EOL>regex = re.compile(r'<STR_LIT>')<EOL>definition = regex.sub("<STR_LIT>", definition)<EOL>return "<STR_LIT>" % locals()<EOL>
*genarate a MMD definition* **Key Arguments:** - ``text`` -- the text to define - ``definition`` -- the definition **Return:** - ``definition`` -- the MMD style definition **Usage:** To genarate a MMD definition: .. code-block:: py...
f5664:c0:m15
def headerLink(<EOL>self,<EOL>headerText,<EOL>text=False):
headerText = headerText.strip()<EOL>if text:<EOL><INDENT>return self._surround(text, "<STR_LIT:[>", "<STR_LIT>" % locals())<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>" % locals()<EOL><DEDENT>
*generate a link to a MMD header* **Key Arguments:** - ``headerText`` -- the header text (or anchor tag) - ``text`` -- the doc text to link. Default *False* **Return:** - ``link`` -- the link to the header **Usage:** To generate a MMD header li...
f5664:c0:m16
def image(<EOL>self,<EOL>url,<EOL>title="<STR_LIT>",<EOL>width=<NUM_LIT>):
title = title.strip()<EOL>caption = title<EOL>now = datetime.now()<EOL>figId = now.strftime("<STR_LIT>")<EOL>if len(title):<EOL><INDENT>figId = "<STR_LIT>" % locals()<EOL><DEDENT>imageLink = """<STR_LIT>""" % locals()<EOL>return imageLink<EOL>
*create MMD image link* **Key Arguments:** - ``title`` -- the title for the image - ``url`` -- the image URL - ``width`` -- the width in pixels of the image. Default *800* **Return:** - ``imageLink`` -- the MMD image link **Usage:** ...
f5664:c0:m17
def blockquote(<EOL>self,<EOL>text):
m = self.reWS.match(text)<EOL>return "<STR_LIT>" + ("<STR_LIT>").join(m.group(<NUM_LIT:2>).split("<STR_LIT:\n>")) + "<STR_LIT>"<EOL>
*convert plain-text to MMD blockquote* **Key Arguments:** - ``text`` -- the text to convert to MMD blockquote **Return:** - ``blockquote`` -- the MMD blockquote **Usage:** To convert a text to a MMD blockquote: .. code-block:: python ...
f5664:c0:m18
def ul(<EOL>self,<EOL>text):
m = self.reWS.match(text)<EOL>ul = []<EOL>for l in m.group(<NUM_LIT:2>).split("<STR_LIT:\n>"):<EOL><INDENT>prefix, text, suffix = self._snip_whitespace(l)<EOL>ul.append("<STR_LIT>" % locals())<EOL><DEDENT>return ("<STR_LIT:\n>").join(ul) + "<STR_LIT>"<EOL>
*convert plain-text to MMD unordered list* **Key Arguments:** - ``text`` -- the text to convert to MMD unordered list **Return:** - ``ul`` -- the MMD unordered list **Usage:** To convert text to a MMD unordered list: .. code-block:: python ...
f5664:c0:m19
def ol(<EOL>self,<EOL>text):
m = self.reWS.match(text)<EOL>ol = []<EOL>for thisIndex, l in enumerate(m.group(<NUM_LIT:2>).split("<STR_LIT:\n>")):<EOL><INDENT>thisIndex += <NUM_LIT:1><EOL>prefix, text, suffix = self._snip_whitespace(l)<EOL>ol.append("<STR_LIT>" % locals())<EOL><DEDENT>return ("<STR_LIT:\n>").join(ol) + "<STR_LIT>"<EOL>
*convert plain-text to MMD ordered list* **Key Arguments:** - ``text`` -- the text to convert to MMD ordered list **Return:** - ``ol`` -- the MMD ordered list **Usage:** To convert text to MMD ordered list: .. code-block:: python ...
f5664:c0:m20
def codeblock(<EOL>self,<EOL>text,<EOL>lang="<STR_LIT>"):
reRemoveNewline = re.compile(r'<STR_LIT>', re.S)<EOL>m = reRemoveNewline.match(text)<EOL>text = m.group(<NUM_LIT:2>)<EOL>return "<STR_LIT>" % locals()<EOL>
*convert plain-text to MMD fenced codeblock* **Key Arguments:** - ``text`` -- the text to convert to MMD fenced codeblock - ``lang`` -- the code language for syntax highlighting. Default *''* **Return:** - ``text`` -- the MMD fenced codeblock **Usage:** ...
f5664:c0:m21
def inline_link(<EOL>self,<EOL>text,<EOL>url):
m = self.reWS.match(text)<EOL>prefix = m.group(<NUM_LIT:1>)<EOL>text = m.group(<NUM_LIT:2>)<EOL>suffix = m.group(<NUM_LIT:3>)<EOL>url = url.strip()<EOL>return "<STR_LIT>" % locals()<EOL>
*generate a MMD sytle link* **Key Arguments:** - ``text`` -- the text to link from - ``url`` -- the url to link to **Return:** - ``text`` -- the linked text **Usage:** To convert a text and url to MMD link: .. code-block:: python ...
f5664:c0:m22
def _snip_whitespace(<EOL>self,<EOL>text):
self.log.debug('<STR_LIT>')<EOL>m = self.reWS.match(text)<EOL>prefix = m.group(<NUM_LIT:1>)<EOL>text = m.group(<NUM_LIT:2>)<EOL>suffix = m.group(<NUM_LIT:3>)<EOL>self.log.debug('<STR_LIT>')<EOL>return prefix, text, suffix<EOL>
*snip the whitespace at the start and end of the text* **Key Arguments:** - ``text`` -- the text to snip **Return:** - ``prefix``, ``text``, ``suffix`` -- the starting whitespace, text and endding whitespace
f5664:c0:m23
def _surround(<EOL>self,<EOL>text,<EOL>left,<EOL>right):
self.log.debug('<STR_LIT>')<EOL>prefix, text, suffix = self._snip_whitespace(text)<EOL>text = text.replace("<STR_LIT>", "<STR_LIT>").replace("<STR_LIT>", "<STR_LIT>").replace(<EOL>"<STR_LIT>", "<STR_LIT>").replace("<STR_LIT>", "<STR_LIT>").replace("<STR_LIT>", "<STR_LIT>" % locals())<EOL>text = """<STR_LIT>""" % locals...
*surround text with given characters* **Key Arguments:** - ``text`` -- the text to surround. - ``left`` -- characters to the left of text - ``right`` -- characters to the right of text **Return:** - ``text`` -- the surronded text
f5664:c0:m24
def get_object(model, cid, engine_name=None, connection=None):
from uliweb import settings<EOL>if not id:<EOL><INDENT>return <EOL><DEDENT>if not check_enable():<EOL><INDENT>return<EOL><DEDENT>redis = get_redis()<EOL>if not redis: return<EOL>tablename = model._alias or model.tablename<EOL>info = settings.get_var('<STR_LIT>' % tablename, {})<EOL>if info is None:<EOL><INDENT>return<E...
Get cached object from redis if id is None then return None:
f5705:m5
def set_object(model, instance, fields=None, engine_name=None):
from uliweb import settings<EOL>if not check_enable():<EOL><INDENT>return<EOL><DEDENT>redis = get_redis()<EOL>if not redis: return<EOL>tablename = model._alias or model.tablename<EOL>exclude = []<EOL>if not fields:<EOL><INDENT>fields, exclude = get_fields(tablename)<EOL><DEDENT>v = instance.dump(fields, exclude=exclude...
Only support simple condition, for example: Model.c.id == n if not id provided, then use instance.id
f5705:m6
def is_allowed(self, filename):
return True<EOL>
Subclasses can override this method to disallow the access to certain files. However by providing `disallow` in the constructor this method is overwritten.
f5709:c0:m1
def get_redis(**options):
from uliweb import settings<EOL>from uliweb.utils.common import log<EOL>import redis<EOL>options = (options or {})<EOL>options.update(settings.REDIS)<EOL>if '<STR_LIT>' in options:<EOL><INDENT>client = redis.Redis(unix_socket_path=options['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>global __connection_pool__<EOL>if not...
if no options defined, then it'll use settings options #unix_socket_path = '/tmp/redis.sock' connection_pool = {'host':'localhost', 'port':6379} #if test after created redis client object test_first = False
f5712:m0
def get_lock(key, value=None, expiry_time=<NUM_LIT>):
from uliweb.utils.common import get_uuid<EOL>redis = get_redis()<EOL>value = value or get_uuid()<EOL>return redis.set(key, value, ex=expiry_time, nx=True)<EOL>
Get a distribute lock
f5712:m1
def set_lock(key, value=None, expiry_time=<NUM_LIT>):
from uliweb.utils.common import get_uuid<EOL>redis = get_redis()<EOL>value = value or get_uuid()<EOL>return redis.set(key, value, ex=expiry_time, xx=True)<EOL>
Force to set a distribute lock
f5712:m2
def after_init_apps(sender):
from uliweb import settings<EOL>from uliweb.utils.common import log<EOL>check = settings.get_var('<STR_LIT>')<EOL>if check:<EOL><INDENT>client = get_redis()<EOL>try:<EOL><INDENT>info = client.info()<EOL><DEDENT>except Exception as e:<EOL><INDENT>log.exception(e)<EOL>log.error('<STR_LIT>')<EOL>return<EOL><DEDENT>redis_v...
Check redis version
f5712:m3
def cal_position(self, text, has_toplinks, has_bottomlinks, head_len, head_start):
if head_len == <NUM_LIT:0>:<EOL><INDENT>top_start = top_end = bottom_start = bottom_end = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>top_start = top_end = head_start + <NUM_LIT:6><EOL>bottom_start = bottom_end = head_start + head_len - <NUM_LIT:7><EOL><DEDENT>if has_toplinks:<EOL><INDENT>t = r_top.search(text)<EOL>if t:...
Calculate the position of toplinks and bottomlinks, if there is not toplinks and bottomlinks then toplinks position will be the position after <head> and if there is no bottomlinks, the bottomlinks position will be the position before </head>.
f5713:c2:m4
def init_static_combine():
from uliweb import settings<EOL>from hashlib import md5<EOL>import os<EOL>d = {}<EOL>if settings.get_var('<STR_LIT>', False):<EOL><INDENT>for k, v in settings.get('<STR_LIT>', {}).items():<EOL><INDENT>key = '<STR_LIT>'+md5('<STR_LIT>'.join(v)).hexdigest()+os.path.splitext(v[<NUM_LIT:0>])[<NUM_LIT:1>]<EOL>d[key] = v<EOL...
Process static combine, create md5 key according each static filename
f5714:m1
def csrf_token():
from uliweb import request, settings<EOL>from uliweb.utils.common import safe_str<EOL>v = {}<EOL>token_name = settings.CSRF.cookie_token_name<EOL>if not request.session.deleted and request.session.get(token_name):<EOL><INDENT>v = request.session[token_name]<EOL>if time.time() >= v['<STR_LIT>'] + v['<STR_LIT>']:<EOL><IN...
Get csrf token or create new one
f5717:m0
def check_csrf_token():
from uliweb import request, settings<EOL>token = (request.params.get(settings.CSRF.form_token_name, None) or<EOL>request.headers.get("<STR_LIT>") or<EOL>request.headers.get("<STR_LIT>"))<EOL>if not token:<EOL><INDENT>raise Forbidden("<STR_LIT>")<EOL><DEDENT>if csrf_token() != token:<EOL><INDENT>raise Forbidden("<STR_LI...
Check token
f5717:m1
def startup_installed(sender):
import os<EOL>from uliweb.core.SimpleFrame import get_app_dir<EOL>from uliweb.i18n import install, set_default_language<EOL>from uliweb.utils.common import pkg, expand_path<EOL>path = pkg.resource_filename('<STR_LIT>', '<STR_LIT>')<EOL>_dirs = []<EOL>for d in sender.settings.get_var('<STR_LIT>', []):<EOL><INDENT>_dirs....
@LANGUAGE_CODE
f5719:m0
def parse_accept_lang_header(lang_string):
result = []<EOL>pieces = accept_language_re.split(lang_string)<EOL>if pieces[-<NUM_LIT:1>]:<EOL><INDENT>return []<EOL><DEDENT>for i in range(<NUM_LIT:0>, len(pieces) - <NUM_LIT:1>, <NUM_LIT:3>):<EOL><INDENT>first, lang, priority = pieces[i : i + <NUM_LIT:3>]<EOL>if first:<EOL><INDENT>return []<EOL><DEDENT>priority = pr...
Parses the lang_string, which is the body of an HTTP Accept-Language header, and returns a list of (lang, q-value), ordered by 'q' values. Any format errors in lang_string results in an empty list being returned.
f5720:m1
def process_exception(self, request, e):
if isinstance(e, RedirectException):<EOL><INDENT>response = e.get_response()<EOL>self.process_response(request, response)<EOL><DEDENT>
Still process session data when specially Exception
f5727:c0:m3
def get_cipher(key=None, keyfile=None):
des_func = import_attr(settings.SECRETKEY.CIPHER_CLS)<EOL>kwargs = settings.SECRETKEY.CIPHER_ARGS<EOL>if not key:<EOL><INDENT>key = functions.get_cipher_key(keyfile)<EOL><DEDENT>cipher = des_func(key, **kwargs)<EOL>return cipher<EOL>
Get cipher object, and then you can invoke: des = get_cipher() d = des.encrpy('Hello') print des.descrpy(d)
f5733:m0
def encrypt(v, key=None, keyfile=None):
cipher = functions.get_cipher(key, keyfile)<EOL>return cipher.encrypt(v)<EOL>
Encrypt an string
f5733:m1
def decrypt(v, key=None, keyfile=None):
cipher = functions.get_cipher(key, keyfile)<EOL>return cipher.decrypt(v)<EOL>
Encrypt an string
f5733:m2
def get_key(keyfile=None):
keyfile = keyfile or application_path(settings.SECRETKEY.SECRET_FILE)<EOL>with file(keyfile, '<STR_LIT:rb>') as f:<EOL><INDENT>return f.read()<EOL><DEDENT>
Read the key content from secret_file
f5733:m3
def get_cipher_key(keyfile=None):
_key = get_key(keyfile)<EOL>_k = md5(_key).hexdigest()<EOL>key = xor(_k[:<NUM_LIT:8>], _k[<NUM_LIT:8>:<NUM_LIT:16>], _k[<NUM_LIT:16>:<NUM_LIT>], _k[<NUM_LIT>:])<EOL>return key<EOL>
Create key which will be used in des, because des need 8bytes chars
f5733:m4
def show_table(name, table, i, total):
return '<STR_LIT>' % (i+<NUM_LIT:1>, total, table.__appname__, name)<EOL>
Display table info, name is tablename table is table object i is current Index total is total of tables
f5738:m7
def handle(self, options, global_options, *args):
from uliweb.orm.graph import generate_dot, generate_file<EOL>from uliweb.utils.common import get_tempfilename, get_tempfilename2<EOL>engine = get_engine(options, global_options)<EOL>if args:<EOL><INDENT>apps = args<EOL><DEDENT>else:<EOL><INDENT>apps = self.get_apps(global_options)<EOL><DEDENT>if not options.tables:<EOL...
For Chinese Font name: 新細明體:PMingLiU 細明體:MingLiU 標楷體:DFKai-SB 黑体:SimHei 宋体:SimSun 新宋体:NSimSun 仿宋:FangSong 楷体:KaiTi 仿宋_GB2312:FangSong_GB2312 楷体_GB2312:KaiTi_GB2312 微軟正黑體:Microsoft JhengHei 微软雅黑体:Microsoft YaHei
f5738:c14:m0
def run_migrations_offline():
url = config.get_main_option("<STR_LIT>")<EOL>context.configure(url=url)<EOL>with context.begin_transaction():<EOL><INDENT>context.run_migrations()<EOL><DEDENT>
Run migrations in 'offline' mode. This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don't even need a DBAPI to be available. Calls to context.execute() here emit the given string to the script output.
f5739:m0
def run_migrations_online():
from uliweb.manage import make_simple_application<EOL>from uliweb import orm, settings<EOL><INDENT>engine = engine_from_config(<EOL>config.get_section(config.config_ini_section), <EOL>prefix='<STR_LIT>', <EOL>poolclass=pool.NullPool)<EOL><DEDENT>name = config.get_main_option("<STR_LIT>")<EOL>make_simple_application(pro...
Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context.
f5739:m3
def get_form(formcls):
from uliweb.form import Form<EOL>import inspect<EOL>if inspect.isclass(formcls) and issubclass(formcls, Form):<EOL><INDENT>return formcls<EOL><DEDENT>elif isinstance(formcls, (str, unicode)):<EOL><INDENT>path = settings.FORMS.get(formcls)<EOL>if path:<EOL><INDENT>_cls = import_attr(path)<EOL>return _cls<EOL><DEDENT>els...
get form class according form class path or form class object
f5745:m0
def get_filename(self, filename, filesystem=False, convert=False, subpath='<STR_LIT>'):
from uliweb.utils.common import safe_unicode<EOL>s = settings.GLOBAL<EOL>if convert:<EOL><INDENT>_p, _f = os.path.split(filename)<EOL>_filename = os.path.join(_p, self.filename_convert(_f))<EOL><DEDENT>else:<EOL><INDENT>_filename = filename<EOL><DEDENT>nfile = safe_unicode(_filename, s.HTMLPAGE_ENCODING)<EOL>if subpath...
Get the filename according to self.to_path, and if filesystem is False then return unicode filename, otherwise return filesystem encoded filename @param filename: relative filename, it'll be combine with self.to_path @param filesystem: if True, then encoding the filename to filesystem @param convert: if True, then con...
f5746:c3:m2
def download(self, filename, action='<STR_LIT>', x_filename='<STR_LIT>', x_sendfile=None, real_filename='<STR_LIT>'):
from uliweb import request<EOL>from uliweb.utils.common import safe_str<EOL>from uliweb.utils.filedown import filedown<EOL>s = settings.GLOBAL<EOL>action = request.GET.get('<STR_LIT:action>', action)<EOL>if not real_filename:<EOL><INDENT>real_filename = self.get_filename(filename, True, convert=False)<EOL><DEDENT>else:...
action will be "download", "inline" and if the request.GET has 'action', then the action will be replaced by it.
f5746:c3:m3
def get_url(self, filename, query_para=None, **url_args):
from uliweb.core.html import Tag<EOL>title = url_args.pop('<STR_LIT:title>', filename)<EOL>text = url_args.pop('<STR_LIT:text>', title)<EOL>query_para = query_para or {}<EOL>return str(Tag('<STR_LIT:a>', title, href=self.get_href(filename, **query_para), **url_args))<EOL>
Return <a href="filename" title="filename"> tag You should pass title and text to url_args, if not pass, then using filename
f5746:c3:m9
def find_model(sender, model_name):
MC = get_mc()<EOL>model = MC.get((MC.c.model_name==model_name) & (MC.c.uuid!='<STR_LIT>'))<EOL>if model:<EOL><INDENT>model_inst = model.get_instance()<EOL>orm.set_model(model_name, model_inst.table_name, appname=__name__, model_path='<STR_LIT>')<EOL>return orm.__models__.get(model_name)<EOL><DEDENT>
Register new model to ORM
f5749:m1
def get_model(sender, model_name, model_inst, model_info, model_config):
MC = get_mc()<EOL>if MC:<EOL><INDENT>model = MC.get((MC.c.model_name==model_name) & (MC.c.uuid!='<STR_LIT>'))<EOL>if model:<EOL><INDENT>cached_inst = __cache__.get(model_name)<EOL>if not cached_inst or (cached_inst and cached_inst[<NUM_LIT:1>]!=model.uuid):<EOL><INDENT>model_inst = model.get_instance()<EOL>M = orm.crea...
#todo Add objcache support
f5749:m3
def get_model_fields(model, add_reserver_flag=True):
import uliweb.orm as orm<EOL>fields = []<EOL>m = {'<STR_LIT:type>':'<STR_LIT>', '<STR_LIT>':'<STR_LIT>',<EOL>'<STR_LIT:default>':'<STR_LIT:default>', '<STR_LIT>':'<STR_LIT>'}<EOL>m1 = {'<STR_LIT:index>':'<STR_LIT:index>', '<STR_LIT>':'<STR_LIT>'}<EOL>for name, prop in model.properties.items():<EOL><INDENT>if name == '<...
Creating fields suit for model_config , id will be skipped.
f5749:m4
def get_model_indexes(model, add_reserver_flag=True):
import uliweb.orm as orm<EOL>from sqlalchemy.engine.reflection import Inspector<EOL>indexes = []<EOL>engine = model.get_engine().engine<EOL>insp = Inspector.from_engine(engine)<EOL>for index in insp.get_indexes(model.tablename):<EOL><INDENT>d = {}<EOL>d['<STR_LIT:name>'] = index['<STR_LIT:name>']<EOL>d['<STR_LIT>'] = i...
Creating indexes suit for model_config.
f5749:m5
def process_permission_roles(perm, v):
if isinstance(v, (tuple, list)):<EOL><INDENT>roles = v<EOL><DEDENT>else:<EOL><INDENT>roles = [v]<EOL><DEDENT>for r in roles:<EOL><INDENT>if isinstance(r, (tuple, list)):<EOL><INDENT>role_name, role_props = r<EOL><DEDENT>else:<EOL><INDENT>role_name, role_props = r, '<STR_LIT>'<EOL><DEDENT>role = Role.get(Role.c.name == ...
v is roles
f5759:m0
def add_role_func(name, func):
global __role_funcs__<EOL>__role_funcs__[name] = func<EOL>
Role_func should have 'user' parameter
f5760:m5
def has_role(user, *roles, **kwargs):
Role = get_model('<STR_LIT>')<EOL>if isinstance(user, str):<EOL><INDENT>User = get_model('<STR_LIT:user>')<EOL>user = User.get(User.c.username==user)<EOL><DEDENT>for role in roles:<EOL><INDENT>if isinstance(role, str):<EOL><INDENT>role = Role.get(Role.c.name==role)<EOL>if not role:<EOL><INDENT>continue<EOL><DEDENT><DED...
Judge is the user belongs to the role, and if does, then return the role object if not then return False. kwargs will be passed to role_func.
f5760:m6
def has_permission(user, *permissions, **role_kwargs):
Role = get_model('<STR_LIT>')<EOL>Perm = get_model('<STR_LIT>')<EOL>if isinstance(user, str):<EOL><INDENT>User = get_model('<STR_LIT:user>')<EOL>user = User.get(User.c.username==user)<EOL><DEDENT>for name in permissions:<EOL><INDENT>perm = Perm.get(Perm.c.name==name)<EOL>if not perm:<EOL><INDENT>continue<EOL><DEDENT>fl...
Judge if an user has permission, and if it does return role object, and if it doesn't return False. role_kwargs will be passed to role functions. With role object, you can use role.relation to get Role_Perm_Rel object.
f5760:m7
def check_role(*roles, **args_map):
def f1(func, roles=roles):<EOL><INDENT>@wraps(func)<EOL>def f2(*args, **kwargs):<EOL><INDENT>from uliweb import request, error<EOL>arguments = {}<EOL>for k, v in list(args_map.items()):<EOL><INDENT>if v in kwargs:<EOL><INDENT>arguments[k] = kwargs[v]<EOL><DEDENT><DEDENT>if not has_role(request.user, *roles, **arguments...
It's just like has_role, but it's a decorator. And it'll check request.user
f5760:m8
def check_permission(*permissions, **args_map):
def f1(func, permissions=permissions):<EOL><INDENT>@wraps(func)<EOL>def f2(*args, **kwargs):<EOL><INDENT>from uliweb import request, error<EOL>arguments = {}<EOL>for k, v in list(args_map.items()):<EOL><INDENT>if v in kwargs:<EOL><INDENT>arguments[k] = kwargs[v]<EOL><DEDENT><DEDENT>if not has_permission(request.user, *...
It's just like has_role, but it's a decorator. And it'll check request.user
f5760:m9
def _read(self, ddfile):
import csv<EOL>d = {}<EOL>with open(ddfile) as f:<EOL><INDENT>reader = csv.DictReader(f)<EOL>for row in reader:<EOL><INDENT>key = row['<STR_LIT:name>']<EOL>if key.startswith('<STR_LIT:#>'):<EOL><INDENT>key = key[<NUM_LIT:1>:]<EOL>deprecated = True<EOL><DEDENT>else:<EOL><INDENT>deprecated = False<EOL><DEDENT>value = d.s...
Import index just like: {'key':['value', 'value'], ...}
f5762:c0:m2
def _parse_prop(self, dd, row):
key = row['<STR_LIT:name>']<EOL>if key.startswith('<STR_LIT:#>'):<EOL><INDENT>deprecated = True<EOL><DEDENT>else:<EOL><INDENT>deprecated = False<EOL><DEDENT>v = dd.get(key)<EOL>_value = self._get_value(row)<EOL>if not v:<EOL><INDENT>v = dd.setdefault(key, {})<EOL>v[_value] = deprecated<EOL><DEDENT>else:<EOL><INDENT>if ...
:param dd: datadict :param _row: (tablename, row) :return:
f5762:c0:m4
def soap(func=None, name=None, returns=None, args=None, doc=None, target='<STR_LIT>'):
global __soap_functions__<EOL>returns = _fix_soap_kwargs(returns)<EOL>args = _fix_soap_kwargs(args)<EOL>if isinstance(func, str) and not name:<EOL><INDENT>return partial(soap, name=func, returns=returns, args=args, doc=doc, target=target)<EOL><DEDENT>if not func:<EOL><INDENT>return partial(soap, name=name, returns=retu...
soap supports multiple SOAP function collections, it'll save functions to target dict, and you can give other target, but it should be keep up with SoapView.target definition.
f5769:m1
def _process_fields_convert_map(self, parameters, download=False):
if '<STR_LIT>' in parameters:<EOL><INDENT>_f = parameters.get('<STR_LIT>') or []<EOL>parameters['<STR_LIT>'] = self._get_fields_convert_map(_f, download)<EOL><DEDENT>
process fields_convert_map, ListView doesn't support list type but dict fields_convert_map should be define as list or dict for list, it can be: [name, name, ...] [(name, func), (name, func), ...] if func is str, it'll be the property name of class for dict, it can be: {'name':func, ...} :param model: mode...
f5772:c1:m0
def _get_fields_convert_map(self, fields, download=False):
_f = fields<EOL>t = {}<EOL>def _get(name):<EOL><INDENT>_name = '<STR_LIT>'.format(name)<EOL>if download and hasattr(self, _name):<EOL><INDENT>return getattr(self, _name)<EOL><DEDENT>return getattr(self, '<STR_LIT>'.format(name))<EOL><DEDENT>if isinstance(_f, list):<EOL><INDENT>for k in _f:<EOL><INDENT>if isinstance(k, ...
process fields_convert_map, ListView doesn't support list type but dict fields_convert_map should be define as list or dict for list, it can be: [name, name, ...] [(name, func), (name, func), ...] if func is str, it'll be the property name of class for dict, it can be: {'name':func, ...} :param model: mode...
f5772:c1:m1
def _list_view(self, model, **kwargs):
from uliweb import request<EOL>fields = kwargs.pop('<STR_LIT>', None)<EOL>meta = kwargs.pop('<STR_LIT>', '<STR_LIT>')<EOL>if '<STR_LIT>' in request.GET:<EOL><INDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>fields = kwargs.pop('<STR_LIT>', fields)<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>meta = kwargs.pop('<STR_LI...
:param model: :param fields_convert_map: it's different from ListView :param kwargs: :return:
f5772:c1:m2
def _query_view(self, model, **kwargs):
QueryForm = functions.get_form('<STR_LIT>')<EOL>if '<STR_LIT>' not in kwargs:<EOL><INDENT>kwargs['<STR_LIT>'] = QueryForm<EOL><DEDENT>query = functions.QueryView(model, **kwargs)<EOL>return query<EOL>
:param model: :return: (query, condition) Default use QueryForm
f5772:c1:m3
def _parse_download_args(self, kwargs, fields):
downloads = {}<EOL>downloads['<STR_LIT:filename>'] = kwargs.pop('<STR_LIT>', '<STR_LIT>')<EOL>downloads['<STR_LIT:action>'] = kwargs.pop('<STR_LIT>', '<STR_LIT>')<EOL>downloads['<STR_LIT>'] = kwargs.pop('<STR_LIT>',<EOL>fields)<EOL>downloads['<STR_LIT>'] = kwargs.pop('<STR_LIT>', '<STR_LIT>')<EOL>downloads['<STR_LIT>']...
Parse download parameters from kwargs :return: parsed data
f5772:c1:m4
def _select_list_view(self, model, **kwargs):
from uliweb import request<EOL>fields = kwargs.pop('<STR_LIT>', None)<EOL>meta = kwargs.pop('<STR_LIT>', '<STR_LIT>')<EOL>if '<STR_LIT>' in request.GET:<EOL><INDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>fields = kwargs.pop('<STR_LIT>', fields)<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>meta = kwargs.pop('<STR_LI...
:param model: :param fields_convert_map: it's different from ListView :param kwargs: :return:
f5772:c1:m10
def _select_list(self, model=None, queryview=None, queryform=None,<EOL>auto_condition=True,<EOL>post_view=None, post_run=None, **kwargs):
from uliweb import request, json<EOL>from uliweb.utils.generic import get_sort_field<EOL>import copy<EOL>condition = None<EOL>if queryview and auto_condition:<EOL><INDENT>queryview.run()<EOL>if hasattr(queryview, '<STR_LIT>'):<EOL><INDENT>condition = queryview.get_condition()<EOL><DEDENT><DEDENT>if '<STR_LIT>' in kwarg...
SelectListView wrap method :param auto_condition: if using queryview to create condition
f5772:c1:m11
def _search(self, model, condition=None, search_field='<STR_LIT:name>',<EOL>value_field='<STR_LIT:id>', label_field=None, pagination=True):
from uliweb import json, request<EOL>name = request.GET.get('<STR_LIT>', '<STR_LIT>')<EOL>M = functions.get_model(model)<EOL>def _v(label_field):<EOL><INDENT>if label_field:<EOL><INDENT>return lambda x: getattr(x, label_field)<EOL><DEDENT>else:<EOL><INDENT>return lambda x: unicode(x)<EOL><DEDENT><DEDENT>v_field = reque...
Default search function :param search_field: Used for search field, default is 'name' :param value_field: Used for id field, default is id :param label_field: Used for label field, default is None, then it'll use unicode() function
f5772:c1:m12
def get_relation_condition(key):
global __relations__<EOL>return __relations__.get_condition(key)<EOL>
Get relation condition :param key: should be (schema_a, schema_b) :return:
f5774:m2
def query(d):
q = Query(d)<EOL>return q.run()<EOL>
Query schema :param d: dict options :return:
f5774:m4
def __eq__(self, key):
return key in self.relation_key<EOL>
:param key: (schema_a, schema_b) :return:
f5774:c6:m3
def add(self, relation):
r = Relation(relation)<EOL>key = r.relation_key[<NUM_LIT:0>]<EOL>if key not in self.relations:<EOL><INDENT>self.relations[key] = r<EOL>self.relations[r.relation_key[<NUM_LIT:1>]]= r<EOL><DEDENT>
relation is a string list, just like: ['User.id = Group.user', 'User.username = Group.username'] :param relation: :return:
f5774:c7:m1
def get_condition(self, relation):
condition = None<EOL>r = self.relations.get(relation)<EOL>if r:<EOL><INDENT>condition = r.get_condition(relation)<EOL><DEDENT>return condition<EOL>
:param relation: (schema_a, schema_b) :return:
f5774:c7:m2