Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Markdown / inlinepatterns.pyc
Size: Mime:
ó
Âö™Wc@@sôdZddlmZddlmZddlmZddlmZddlZyddlm	Z	m
Z
Wn'ek
r•ddl	m	Z	m
Z
nXydd	lm
Z
Wnek
rÉddlZ
nXd
„ZdZded
deddedZdZdZdZdZdZdZdZdZdZeedZdedZeedZedZdedZdZ d Z!d!Z"d"Z#d#Z$d$Z%d%„Z&ej'd&ƒZ(d'„Z)d(e*fd)„ƒYZ+d*e+fd+„ƒYZ,d,e+fd-„ƒYZ-d.e+fd/„ƒYZ.d0e.fd1„ƒYZ/d2e+fd3„ƒYZ0d4e.fd5„ƒYZ1d6e+fd7„ƒYZ2d8e+fd9„ƒYZ3d:e3fd;„ƒYZ4d<e3fd=„ƒYZ5d>e5fd?„ƒYZ6d@e+fdA„ƒYZ7dBe+fdC„ƒYZ8dS(Duƒ
INLINE PATTERNS
=============================================================================

Inline patterns such as *emphasis* are handled by means of auxiliary
objects, one per pattern.  Pattern objects must be instances of classes
that extend markdown.Pattern.  Each pattern object uses a single regular
expression and needs support the following methods:

    pattern.getCompiledRegExp() # returns a regular expression

    pattern.handleMatch(m) # takes a match object and returns
                           # an ElementTree element or just plain text

All of python markdown's built-in patterns subclass from Pattern,
but you can add additional patterns that don't.

Also note that all the regular expressions used by inline must
capture the whole block.  For this reason, they all start with
'^(.*)' and end with '(.*)!'.  In case with built-in expression
Pattern takes care of adding the "^(.*)" and "(.*)!".

Finally, the order in which regular expressions are applied is very
important - e.g. if we first replace http://.../ links with <a> tags
and _then_ try to replace inline html, we would end up with a mess.
So, we apply the expressions in the following order:

* escape and backticks have to go before everything else, so
  that we can preempt any markdown patterns by escaping them.

* then we handle auto-links (must be done before inline html)

* then we handle inline HTML.  At this point we will simply
  replace all inline HTML strings with a placeholder and add
  the actual HTML to a hash.

* then inline images (must be done before links)

* then bracketed links, first regular then reference-style

* finally we apply strong and emphasis
i(tabsolute_import(tunicode_literalsi(tutil(todictN(turlparset
urlunparse(tentitiescK@s‘tjƒ}ttƒ|d<tt|ƒ|d<tt|ƒ|d<tt	|ƒ|d<t
t|ƒ|d<tt
|ƒ|d<tt|ƒ|d<tt|ƒ|d<tt|ƒ|d	<ttd
ƒ|d<|jdkrìtt|ƒ|d<ntt|ƒ|d
<ttƒ|d<ttdƒ|d<ttdƒ|d<ttdƒ|d<tt dƒ|d<|j!rztt"dƒ|d<ntt#dƒ|d<|S(u8 Build the default set of inline patterns for Markdown. ubacktickuescapeu	referenceulinku
image_linkuimage_referenceushort_referenceuautolinkuautomailubru	linebreakuhtmluentityu
not_strongu	strong,emu	em_strongu	em,strongu	strong_emustronguemuemphasisu	emphasis2($RtOrderedDicttBacktickPatterntBACKTICK_REt
EscapePatternt	ESCAPE_REtReferencePatterntREFERENCE_REtLinkPatterntLINK_REtImagePatternt
IMAGE_LINK_REtImageReferencePatterntIMAGE_REFERENCE_REtSHORT_REF_REtAutolinkPatterntAUTOLINK_REtAutomailPatterntAUTOMAIL_REtSubstituteTagPatternt
LINE_BREAK_REtsafeModetHtmlPatterntHTML_REt	ENTITY_REtSimpleTextPatternt
NOT_STRONG_REtDoubleTagPatterntEM_STRONG_REtSTRONG_EM_REtSimpleTagPatternt	STRONG_REtEMPHASIS_REtsmart_emphasistSMART_EMPHASIS_REt
EMPHASIS_2_RE(tmd_instancetkwargstinlinePatterns((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pytbuild_inlinepatterns;s2	u[^\]\[]*u\[(u(\[iu\])*u)\]u(?<!\!)u(?<!\\)(`+)(.+?)(?<!`)\2(?!`)u\\(.)u(\*)([^\*]+)\2u(\*{2}|_{2})(.+?)\2u(\*|_)\2{2}(.+?)\2(.*?)\2{2}u(\*|_)\2{2}(.+?)\2{2}(.*?)\2u"(?<!\w)(_)(?!_)(.+?)(?<!_)\2(?!\w)u
(_)(.+?)\2uA\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*?)\12\s*)?\)u\!u%\s*\((<.*?>|([^")]+"[^"]*"|[^\)]*))\)u\s?\[([^\]]*)\]u\[([^\]]+)\]u((^| )(\*|_)( |$))u*<((?:[Ff]|[Hh][Tt])[Tt][Pp][Ss]?://[^>]*)>u<([^> \!]*@[^> ]*)>u"(\<([a-zA-Z/][^\>]*?|\!--.*?--)\>)u(&[\#a-zA-Z0-9]*;)u  \ncC@sO|jdƒr|jdƒs<|jdƒrG|jdƒrG|dd!S|SdS(u#Remove quotes from around a string.u"u'iiÿÿÿÿN(t
startswithtendswith(tstring((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pytdequote£su\{@([^\}]*)=([^\}]*)}c@s‡fd†}tj||ƒS(uDSet values of an element based on attribute definitions ({@id=123}).c@s2ˆj|jdƒ|jdƒjddƒƒdS(Niiu
u (tsettgrouptreplace(tmatch(tparent(s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pytattributeCallback±s(tATTR_REtsub(ttextR6R7((R6s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pythandleAttributes¯stPatterncB@s>eZdZdd„Zd„Zd„Zd„Zd„ZRS(u*Base class that inline patterns subclass. cC@sK||_tjd|tjtjBƒ|_t|_|rG||_ndS(u–
        Create an instant of an inline pattern.

        Keyword arguments:

        * pattern: A regular expression that matches a pattern

        u
^(.*?)%s(.*)$N(	tpatterntretcompiletDOTALLtUNICODEtcompiled_retFalset	safe_modetmarkdown(tselfR=tmarkdown_instance((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyt__init__¿s		
	cC@s|jS(u' Return a compiled regular expression. (RB(RF((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pytgetCompiledRegExpÑscC@sdS(uÌReturn a ElementTree element from the given match.

        Subclasses should override this method.

        Keyword arguments:

        * m: A re match object containing a match of the pattern.

        N((RFtm((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pythandleMatchÕs
cC@s
|jjS(u+ Return class name, to define pattern type (t	__class__t__name__(RF((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyttypeásc@s`y|jjdj‰Wntk
r+|SX‡fd†‰‡‡fd†}tjj||ƒS(u> Return unescaped text given text with an inline placeholder. uinlinec3@s…|j}t|tjƒr,|dk	r,dS|jr@|jVnx>|D]6}xˆ|ƒD]}|VqZW|jrG|jVqGqGWdS(u8 Reimplement Element.itertext for older python versions N(ttagt
isinstanceRtstring_typetNoneR:ttail(telROtets(titertext(s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRWìs		
		c@sZ|jdƒ}|ˆkrVˆj|ƒ}t|tjƒr@|Sdjˆ|ƒƒSndS(Niu(R3tgetRPRRQtjoin(RJtidtvalue(RWtstash(s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyt	get_stashùs(REttreeprocessorst
stashed_nodestKeyErrorRtINLINE_PLACEHOLDER_RER9(RFR:R]((RWR\s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pytunescapeås

	N(	RMt
__module__t__doc__RRRHRIRKRNRb(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR<¼s			RcB@seZdZd„ZRS(u0 Return a simple text of group(2) of a Pattern. cC@s
|jdƒS(Ni(R3(RFRJ((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRKs(RMRcRdRK(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRsR
cB@seZdZd„ZRS(u Return an escaped character. cC@sF|jdƒ}||jjkr>dtjt|ƒtjfSdSdS(Niu%s%s%s(R3REt
ESCAPED_CHARSRtSTXtordtETXRR(RFRJtchar((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRKs(RMRcRdRK(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR
sR$cB@s eZdZd„Zd„ZRS(u[
    Return element of type `tag` with a text attribute of group(3)
    of a Pattern.

    cC@stj||ƒ||_dS(N(R<RHRO(RFR=RO((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRHscC@s+tjj|jƒ}|jdƒ|_|S(Ni(RtetreetElementROR3R:(RFRJRT((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRK s(RMRcRdRHRK(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR$s	RcB@seZdZd„ZRS(u3 Return an element of type `tag` with no children. cC@stjj|jƒS(N(RRjRkRO(RFRJ((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRK(s(RMRcRdRK(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR&sRcB@s eZdZd„Zd„ZRS(u9 Return a `<code>` element containing the matching text. cC@stj||ƒd|_dS(Nucode(R<RHRO(RFR=((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRH.scC@s:tjj|jƒ}tj|jdƒjƒƒ|_|S(Ni(RRjRkROtAtomicStringR3tstripR:(RFRJRT((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRK2s!(RMRcRdRHRK(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR,s	R!cB@seZdZd„ZRS(ufReturn a ElementTree element nested in tag2 nested in tag1.

    Useful for strong emphasis etc.

    cC@s‚|jjdƒ\}}tjj|ƒ}tjj||ƒ}|jdƒ|_t|j	ƒƒdkr~|jdƒ|_
n|S(Nu,iii(ROtsplitRRjRkt
SubElementR3R:tlentgroupsRS(RFRJttag1ttag2tel1tel2((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRK>s(RMRcRdRK(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR!8sRcB@s eZdZd„Zd„ZRS(u1 Store raw inline html and return a placeholder. cC@s1|j|jdƒƒ}|jjj|ƒ}|S(Ni(RbR3REt	htmlStashtstore(RFRJtrawhtmltplace_holder((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRKJsc@sQyˆjjdj‰Wntk
r+|SX‡‡fd†}tjj||ƒS(u> Return unescaped text given text with an inline placeholder. uinlinec@sT|jdƒ}ˆj|ƒ}|dk	rPyˆjj|ƒSWqPd|SXndS(Niu\%s(R3RXRRREt
serializer(RJRZR[(RFR\(s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR]Vs(RER^R_R`RRaR9(RFR:R]((RFR\s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRbOs
	(RMRcRdRKRb(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRHs	RcB@s eZdZd„Zd„ZRS(u- Return a link element from the given match. cC@sÕtjjdƒ}|jdƒ|_|jdƒ}|jdƒ}|r“|ddkrh|dd!}n|jd	|j|j|jƒƒƒƒn|jd	d
ƒ|rÑt	|j|ƒƒ}|jd|ƒn|S(Nuaii
i	iu<iiÿÿÿÿuhrefuutitle(
RRjRkR3R:R2tsanitize_urlRbRmR1(RFRJRTttitlethref((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRKds+cC@sË|jjs|Sy&t|ƒ\}}}}}}}Wntk
rJdSXdddg}|ddddg}	||	kr€dS|dkrœ||krœdSx"|dD]}
d	|
kr§dSq§Wt|ƒS(
ul
        Sanitize a url against xss attacks in "safe_mode".

        Rather than specifically blacklisting `javascript:alert("XSS")` and all
        its aliases (see <http://ha.ckers.org/xss.html>), we whitelist known
        safe url formats. Most urls contain a network location, however some
        are known not to (i.e.: mailto links). Script urls do not contain a
        location. Additionally, for `javascript:...`, the scheme would be
        "javascript" but some aliases will appear to `urlparse()` to have no
        scheme. On top of that relative links (i.e.: "foo/bar.html") have no
        scheme. Therefore we must check "path", "parameters", "query" and
        "fragment" for any literal colons. We don't check "scheme" for colons
        because it *should* never have any and "netloc" must allow the form:
        `username:password@host:port`.

        uumailtounewsuhttpuhttpsuftpuftpsiu:(RERRt
ValueErrorR(RFturltschemetnetloctpathtparamstquerytfragmenttlocless_schemestallowed_schemestpart((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR{vs &
(RMRcRdRKR{(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRbs	RcB@seZdZd„ZRS(u, Return a img element from the given match. cC@s0tjjdƒ}|jdƒjƒ}|rŒ|d}|ddkrg|ddkrg|dd!}n|jd|j|j|ƒƒƒn|jdd	ƒt|ƒdkrÝ|jd
t	|jdj
|dƒƒƒƒn|jjrt
|jdƒ|ƒ}n|jdƒ}|jd
|j|ƒƒ|S(Nuimgi	iu<iÿÿÿÿu>iusrcuutitleu iualt(RRjRkR3RnR2R{RbRpR1RYREtenable_attributesR;(RFRJRTt	src_partstsrcttruealt((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRK§s
 %/(RMRcRdRK(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR¥sRcB@s5eZdZejdejƒZd„Zd„ZRS(u6 Match to a stored reference and return link element. u[ ]?\ncC@s´y|jdƒjƒ}Wntk
r2d}nX|sQ|jdƒjƒ}n|jjd|ƒ}||jjkr|dS|jj|\}}|jdƒ}|j|||ƒS(Ni	iu (	R3tlowert
IndexErrorRRtNEWLINE_CLEANUP_RER9REt
referencestmakeTag(RFRJRZR}R|R:((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRKÂs

cC@sQtjjdƒ}|jd|j|ƒƒ|rD|jd|ƒn||_|S(Nuauhrefutitle(RRjRkR2R{R:(RFR}R|R:RT((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR‘Õs	(	RMRcRdR>R?t	MULTILINERRKR‘(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR½s	RcB@seZdZd„ZRS(u5 Match to a stored reference and return img element. cC@stjjdƒ}|jd|j|ƒƒ|rD|jd|ƒn|jjrbt||ƒ}n|jd|j|ƒƒ|S(Nuimgusrcutitleualt(	RRjRkR2R{RER‰R;Rb(RFR}R|R:RT((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR‘âs(RMRcRdR‘(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRàsRcB@seZdZd„ZRS(uC Return a link Element given an autolink (`<http://example/com>`). cC@sStjjdƒ}|jd|j|jdƒƒƒtj|jdƒƒ|_|S(Nuauhrefi(RRjRkR2RbR3RlR:(RFRJRT((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRKñs"(RMRcRdRK(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRïsRcB@seZdZd„ZRS(uT
    Return a mailto link Element given an automail link (`<foo@example.com>`).
    cC@sætjjdƒ}|j|jdƒƒ}|jdƒrL|tdƒ}nd„}g|D]}|t|ƒƒ^q\}tjdj	|ƒƒ|_
d|}dj	g|D]}tjdt|ƒ^q¬ƒ}|jd|ƒ|S(Nuaiumailto:cS@s>tjj|ƒ}|r)dtj|fSdtj|fSdS(u=Return entity definition by code, or the code if not defined.u%s%s;u%s#%d;N(Rtcodepoint2nameRXRtAMP_SUBSTITUTE(tcodetentity((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyR“suu#%d;uhref(
RRjRkRbR3R.RpRgRlRYR:R”R2(RFRJRTtemailR“tlettertletterstmailto((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRKüs	%
	*(RMRcRdRK(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyRøs(9Rdt
__future__RRtRRR>turllib.parseRRtImportErrorthtmlRthtmlentitydefsR-t	NOBRACKETtBRKtNOIMGR	RR&R%R"R#R(R)RRR
RRR RRRRRR1R?R8R;tobjectR<RR
R$RRR!RRRRRRR(((s5build/lib.linux-x86_64-2.7/markdown/inlinepatterns.pyt<module>*sl

	$&
			
IC#