MediaWiki  1.23.12
cssjanus Namespace Reference

Classes

class  Tokenizer
 

Functions

def CalculateNewBackgroundPosition (m)
 
def CalculateNewBackgroundPositionX (m)
 
def ChangeLeftToRightToLeft (lines, swap_ltr_rtl_in_url=None, swap_left_right_in_url=None)
 
def FixBackgroundPosition (line)
 
def FixBodyDirectionLtrAndRtl (line)
 
def FixCursorProperties (line)
 
def FixFourPartNotation (line)
 
def FixLeftAndRight (line)
 
def FixLeftAndRightInUrl (line)
 
def FixLtrAndRtlInUrl (line)
 
def main (argv)
 
def setflags (opts)
 
def usage ()
 

Variables

string __author__ = 'elsigh@google.com (Lindsey Simon)'
 
string __version__ = '0.1'
 
 BG_HORIZONTAL_PERCENTAGE_RE
 
 BG_HORIZONTAL_PERCENTAGE_X_RE
 
 BODY_DIRECTION_LTR_RE
 
 BODY_DIRECTION_RTL_RE
 
string BODY_SELECTOR = r'body%s{%s' % (csslex.WHITESPACE, csslex.WHITESPACE)
 
string CHARS_WITHIN_SELECTOR = r'[^\}]*?'
 
string COLOR = r'(%s|%s)' % (csslex.NAME, csslex.HASH)
 
string COLOR_SPACE = r'%s%s' % (COLOR, csslex.SPACE)
 
 COMMENT_RE = re.compile('(%s)' % csslex.COMMENT, re.I)
 
 CURSOR_EAST_RE = re.compile(LOOKBEHIND_NOT_LETTER + '([ns]?)e-resize')
 
 CURSOR_WEST_RE = re.compile(LOOKBEHIND_NOT_LETTER + '([ns]?)w-resize')
 
 DIRECTION_LTR_RE = re.compile(r'%s(ltr)' % DIRECTION_RE)
 
string DIRECTION_RE = r'direction%s:%s' % (csslex.WHITESPACE, csslex.WHITESPACE)
 
 DIRECTION_RTL_RE = re.compile(r'%s(rtl)' % DIRECTION_RE)
 
dictionary FLAGS
 
 FOUR_NOTATION_COLOR_RE
 
 FOUR_NOTATION_QUANTITY_RE
 
string LEFT = 'left'
 
 LEFT_IN_URL_RE
 
 LEFT_RE
 
string LOOKAHEAD_FOR_CLOSING_PAREN
 
string LOOKAHEAD_NOT_CLOSING_PAREN
 
tuple LOOKAHEAD_NOT_OPEN_BRACE
 
string LOOKBEHIND_NOT_LETTER = r'(?<![a-zA-Z])'
 
string LTR = 'ltr'
 
 LTR_IN_URL_RE
 
string NOFLIP_ANNOTATION
 
 NOFLIP_CLASS_RE
 
 NOFLIP_SINGLE_RE
 
string NOFLIP_TOKEN = r'\@noflip'
 
string POSSIBLY_NEGATIVE_QUANTITY = r'((?:-?%s)|(?:inherit|auto))' % csslex.QUANTITY
 
string POSSIBLY_NEGATIVE_QUANTITY_SPACE
 
string RIGHT = 'right'
 
 RIGHT_IN_URL_RE
 
 RIGHT_RE
 
string RTL = 'rtl'
 
 RTL_IN_URL_RE
 
bool SWAP_LEFT_RIGHT_IN_URL_DEFAULT = False
 
bool SWAP_LTR_RTL_IN_URL_DEFAULT = False
 
string TMP_TOKEN = '%sTMP%s' % (TOKEN_DELIMITER, TOKEN_DELIMITER)
 
string TOKEN_DELIMITER = '~'
 
string TOKEN_LINES = '%sJ%s' % (TOKEN_DELIMITER, TOKEN_DELIMITER)
 
string VALID_AFTER_URI_CHARS = r'[\'\"]?%s' % csslex.WHITESPACE
 

Function Documentation

◆ CalculateNewBackgroundPosition()

def cssjanus.CalculateNewBackgroundPosition (   m)
Fixes horizontal background-position percentages.

This function should be used as an argument to re.sub since it needs to
perform replacement specific calculations.

Args:
  m: A match object.

Returns:
  A string with the horizontal background position percentage fixed.
  BG_HORIZONTAL_PERCENTAGE_RE.sub(FixBackgroundPosition,
                                  'background-position: 75% 50%')
  will return 'background-position: 25% 50%'.

Definition at line 400 of file cssjanus.py.

◆ CalculateNewBackgroundPositionX()

def cssjanus.CalculateNewBackgroundPositionX (   m)
Fixes percent based background-position-x.

This function should be used as an argument to re.sub since it needs to
perform replacement specific calculations.

Args:
  m: A match object.

Returns:
  A string with the background-position-x percentage fixed.
  BG_HORIZONTAL_PERCENTAGE_X_RE.sub(CalculateNewBackgroundPosition,
                                    'background-position-x: 75%')
  will return 'background-position-x: 25%'.

Definition at line 429 of file cssjanus.py.

◆ ChangeLeftToRightToLeft()

def cssjanus.ChangeLeftToRightToLeft (   lines,
  swap_ltr_rtl_in_url = None,
  swap_left_right_in_url = None 
)
Turns lines into a stream and runs the fixing functions against it.

Args:
  lines: An list of CSS lines.
  swap_ltr_rtl_in_url: Overrides this flag if param is set.
  swap_left_right_in_url: Overrides this flag if param is set.

Returns:
  The same lines, but with left and right fixes.

Definition at line 451 of file cssjanus.py.

References FixBackgroundPosition(), FixBodyDirectionLtrAndRtl(), FixCursorProperties(), FixFourPartNotation(), FixLeftAndRight(), FixLeftAndRightInUrl(), and FixLtrAndRtlInUrl().

Referenced by main().

◆ FixBackgroundPosition()

def cssjanus.FixBackgroundPosition (   line)
Fixes horizontal background percentage values in line.

Args:
  line: A string to fix horizontal background position values in.

Returns:
  line reformatted with the 4 part notations swapped.

Definition at line 384 of file cssjanus.py.

Referenced by ChangeLeftToRightToLeft().

◆ FixBodyDirectionLtrAndRtl()

def cssjanus.FixBodyDirectionLtrAndRtl (   line)
Replaces ltr with rtl and vice versa ONLY in the body direction.

Args:
  line: A string to replace instances of ltr with rtl.
Returns:
  line with direction: ltr and direction: rtl swapped only in body selector.
  line = FixBodyDirectionLtrAndRtl('body { direction:ltr }')
  line will now be 'body { direction:rtl }'.

Definition at line 273 of file cssjanus.py.

Referenced by ChangeLeftToRightToLeft().

◆ FixCursorProperties()

def cssjanus.FixCursorProperties (   line)
Fixes directional CSS cursor properties.

Args:
  line: A string to fix CSS cursor properties in.

Returns:
  line reformatted with the cursor properties substituted. For example:
  line = FixCursorProperties('cursor: ne-resize')
  line will now be 'cursor: nw-resize'.

Definition at line 348 of file cssjanus.py.

Referenced by ChangeLeftToRightToLeft().

◆ FixFourPartNotation()

def cssjanus.FixFourPartNotation (   line)
Fixes the second and fourth positions in 4 part CSS notation.

Args:
  line: A string to fix 4 part CSS notation in.

Returns:
  line reformatted with the 4 part notations swapped. For example:
  line = FixFourPartNotation('padding: 1px 2px 3px 4px')
  line will now be 'padding: 1px 4px 3px 2px'.

Definition at line 367 of file cssjanus.py.

Referenced by ChangeLeftToRightToLeft().

◆ FixLeftAndRight()

def cssjanus.FixLeftAndRight (   line)
Replaces left with right and vice versa in line.

Args:
  line: A string in which to perform the replacement.

Returns:
  line with left and right swapped. For example:
  line = FixLeftAndRight('padding-left: 2px; margin-right: 1px;')
  line will now be 'padding-right: 2px; margin-left: 1px;'.

Definition at line 291 of file cssjanus.py.

Referenced by ChangeLeftToRightToLeft().

◆ FixLeftAndRightInUrl()

def cssjanus.FixLeftAndRightInUrl (   line)
Replaces left with right and vice versa ONLY within background urls.

Args:
  line: A string in which to replace left with right and vice versa.

Returns:
  line with left and right swapped in the url string. For example:
  line = FixLeftAndRightInUrl('background:url(right.png)')
  line will now be 'background:url(left.png)'.

Definition at line 310 of file cssjanus.py.

Referenced by ChangeLeftToRightToLeft().

◆ FixLtrAndRtlInUrl()

def cssjanus.FixLtrAndRtlInUrl (   line)
Replaces ltr with rtl and vice versa ONLY within background urls.

Args:
  line: A string in which to replace ltr with rtl and vice versa.

Returns:
  line with left and right swapped. For example:
  line = FixLtrAndRtlInUrl('background:url(rtl.png)')
  line will now be 'background:url(ltr.png)'.

Definition at line 329 of file cssjanus.py.

Referenced by ChangeLeftToRightToLeft().

◆ main()

def cssjanus.main (   argv)
Sends stdin lines to ChangeLeftToRightToLeft and writes to stdout.

Definition at line 554 of file cssjanus.py.

References ChangeLeftToRightToLeft(), setflags(), and usage().

Referenced by ModernTemplate.execute().

◆ setflags()

def cssjanus.setflags (   opts)
Parse the passed in command line arguments and set the FLAGS global.

Args:
  opts: getopt iterable intercepted from argv.

Definition at line 531 of file cssjanus.py.

References usage().

Referenced by main().

◆ usage()

def cssjanus.usage ( )
Prints out usage information.

Definition at line 520 of file cssjanus.py.

Referenced by main(), setflags(), and UserOptions.showUsageAndExit().

Variable Documentation

◆ __author__

string cssjanus.__author__ = 'elsigh@google.com (Lindsey Simon)'
private

Definition at line 17 of file cssjanus.py.

◆ __version__

string cssjanus.__version__ = '0.1'
private

Definition at line 18 of file cssjanus.py.

◆ BG_HORIZONTAL_PERCENTAGE_RE

cssjanus.BG_HORIZONTAL_PERCENTAGE_RE
Initial value:
1 = re.compile(r'background(-position)?(%s:%s)'
2  '([^%%]*?)(%s)%%'
3  '(%s(?:%s|%s))' % (csslex.WHITESPACE,
4  csslex.WHITESPACE,
5  csslex.NUM,
6  csslex.WHITESPACE,
7  csslex.QUANTITY,
8  csslex.IDENT))

Definition at line 107 of file cssjanus.py.

◆ BG_HORIZONTAL_PERCENTAGE_X_RE

cssjanus.BG_HORIZONTAL_PERCENTAGE_X_RE
Initial value:
1 = re.compile(r'background-position-x(%s:%s)'
2  '(%s)%%' % (csslex.WHITESPACE,
3  csslex.WHITESPACE,
4  csslex.NUM))

Definition at line 116 of file cssjanus.py.

◆ BODY_DIRECTION_LTR_RE

cssjanus.BODY_DIRECTION_LTR_RE
Initial value:
1 = re.compile(r'(%s)(%s)(%s)(ltr)' %
2  (BODY_SELECTOR, CHARS_WITHIN_SELECTOR,
3  DIRECTION_RE),
4  re.I)

Definition at line 132 of file cssjanus.py.

◆ BODY_DIRECTION_RTL_RE

cssjanus.BODY_DIRECTION_RTL_RE
Initial value:
1 = re.compile(r'(%s)(%s)(%s)(rtl)' %
2  (BODY_SELECTOR, CHARS_WITHIN_SELECTOR,
3  DIRECTION_RE),
4  re.I)

Definition at line 136 of file cssjanus.py.

◆ BODY_SELECTOR

string cssjanus.BODY_SELECTOR = r'body%s{%s' % (csslex.WHITESPACE, csslex.WHITESPACE)

Definition at line 122 of file cssjanus.py.

◆ CHARS_WITHIN_SELECTOR

string cssjanus.CHARS_WITHIN_SELECTOR = r'[^\}]*?'

Definition at line 125 of file cssjanus.py.

◆ COLOR

string cssjanus.COLOR = r'(%s|%s)' % (csslex.NAME, csslex.HASH)

Definition at line 87 of file cssjanus.py.

◆ COLOR_SPACE

string cssjanus.COLOR_SPACE = r'%s%s' % (COLOR, csslex.SPACE)

Definition at line 88 of file cssjanus.py.

◆ COMMENT_RE

cssjanus.COMMENT_RE = re.compile('(%s)' % csslex.COMMENT, re.I)

Definition at line 179 of file cssjanus.py.

◆ CURSOR_EAST_RE

cssjanus.CURSOR_EAST_RE = re.compile(LOOKBEHIND_NOT_LETTER + '([ns]?)e-resize')

Definition at line 99 of file cssjanus.py.

◆ CURSOR_WEST_RE

cssjanus.CURSOR_WEST_RE = re.compile(LOOKBEHIND_NOT_LETTER + '([ns]?)w-resize')

Definition at line 100 of file cssjanus.py.

◆ DIRECTION_LTR_RE

cssjanus.DIRECTION_LTR_RE = re.compile(r'%s(ltr)' % DIRECTION_RE)

Definition at line 144 of file cssjanus.py.

◆ DIRECTION_RE

string cssjanus.DIRECTION_RE = r'direction%s:%s' % (csslex.WHITESPACE, csslex.WHITESPACE)

Definition at line 128 of file cssjanus.py.

◆ DIRECTION_RTL_RE

cssjanus.DIRECTION_RTL_RE = re.compile(r'%s(rtl)' % DIRECTION_RE)

Definition at line 145 of file cssjanus.py.

◆ FLAGS

dictionary cssjanus.FLAGS
Initial value:
1 = {'swap_ltr_rtl_in_url': SWAP_LTR_RTL_IN_URL_DEFAULT,
2  'swap_left_right_in_url': SWAP_LEFT_RIGHT_IN_URL_DEFAULT}

Definition at line 33 of file cssjanus.py.

◆ FOUR_NOTATION_COLOR_RE

cssjanus.FOUR_NOTATION_COLOR_RE
Initial value:
1 = re.compile(r'(-color%s:%s)%s%s%s(%s)' %
2  (csslex.WHITESPACE,
3  csslex.WHITESPACE,
4  COLOR_SPACE,
5  COLOR_SPACE,
6  COLOR_SPACE,
7  COLOR),
8  re.I)

Definition at line 89 of file cssjanus.py.

◆ FOUR_NOTATION_QUANTITY_RE

cssjanus.FOUR_NOTATION_QUANTITY_RE
Initial value:
1 = re.compile(r'%s%s%s%s' %
2  (POSSIBLY_NEGATIVE_QUANTITY_SPACE,
3  POSSIBLY_NEGATIVE_QUANTITY_SPACE,
4  POSSIBLY_NEGATIVE_QUANTITY_SPACE,
5  POSSIBLY_NEGATIVE_QUANTITY),
6  re.I)

Definition at line 81 of file cssjanus.py.

◆ LEFT

string cssjanus.LEFT = 'left'

Definition at line 48 of file cssjanus.py.

Referenced by PostgresField.fromText(), and Language.getDirMark().

◆ LEFT_IN_URL_RE

cssjanus.LEFT_IN_URL_RE
Initial value:
1 = re.compile('%s(%s)%s' % (LOOKBEHIND_NOT_LETTER,
2  LEFT,
3  LOOKAHEAD_FOR_CLOSING_PAREN),
4  re.I)

Definition at line 162 of file cssjanus.py.

◆ LEFT_RE

cssjanus.LEFT_RE
Initial value:
1 = re.compile('%s(%s)%s%s' % (LOOKBEHIND_NOT_LETTER,
2  LEFT,
3  LOOKAHEAD_NOT_CLOSING_PAREN,
4  LOOKAHEAD_NOT_OPEN_BRACE),
5  re.I)

Definition at line 152 of file cssjanus.py.

◆ LOOKAHEAD_FOR_CLOSING_PAREN

string cssjanus.LOOKAHEAD_FOR_CLOSING_PAREN
Initial value:
1 = r'(?=%s?%s\))' % (csslex.URL_CHARS,
2  VALID_AFTER_URI_CHARS)

Definition at line 71 of file cssjanus.py.

◆ LOOKAHEAD_NOT_CLOSING_PAREN

string cssjanus.LOOKAHEAD_NOT_CLOSING_PAREN
Initial value:
1 = r'(?!%s?%s\))' % (csslex.URL_CHARS,
2  VALID_AFTER_URI_CHARS)

Definition at line 69 of file cssjanus.py.

◆ LOOKAHEAD_NOT_OPEN_BRACE

tuple cssjanus.LOOKAHEAD_NOT_OPEN_BRACE
Initial value:
1 = (r'(?!(?:%s|%s|%s|#|\:|\.|\,|\+|>)*?{)' %
2  (csslex.NMCHAR, TOKEN_LINES, csslex.SPACE))

Definition at line 61 of file cssjanus.py.

◆ LOOKBEHIND_NOT_LETTER

string cssjanus.LOOKBEHIND_NOT_LETTER = r'(?<![a-zA-Z])'

Definition at line 54 of file cssjanus.py.

◆ LTR

string cssjanus.LTR = 'ltr'

Definition at line 46 of file cssjanus.py.

◆ LTR_IN_URL_RE

cssjanus.LTR_IN_URL_RE
Initial value:
1 = re.compile('%s(%s)%s' % (LOOKBEHIND_NOT_LETTER,
2  LTR,
3  LOOKAHEAD_FOR_CLOSING_PAREN),
4  re.I)

Definition at line 170 of file cssjanus.py.

◆ NOFLIP_ANNOTATION

string cssjanus.NOFLIP_ANNOTATION
Initial value:
1 = r'/\*%s%s%s\*/' % (csslex.WHITESPACE,
2  NOFLIP_TOKEN,
3  csslex. WHITESPACE)

Definition at line 185 of file cssjanus.py.

◆ NOFLIP_CLASS_RE

cssjanus.NOFLIP_CLASS_RE
Initial value:
1 = re.compile(r'(%s%s})' % (NOFLIP_ANNOTATION,
2  CHARS_WITHIN_SELECTOR),
3  re.I)

Definition at line 200 of file cssjanus.py.

◆ NOFLIP_SINGLE_RE

cssjanus.NOFLIP_SINGLE_RE
Initial value:
1 = re.compile(r'(%s%s[^;}]+;?)' % (NOFLIP_ANNOTATION,
2  LOOKAHEAD_NOT_OPEN_BRACE),
3  re.I)

Definition at line 193 of file cssjanus.py.

◆ NOFLIP_TOKEN

string cssjanus.NOFLIP_TOKEN = r'\@noflip'

Definition at line 181 of file cssjanus.py.

◆ POSSIBLY_NEGATIVE_QUANTITY

string cssjanus.POSSIBLY_NEGATIVE_QUANTITY = r'((?:-?%s)|(?:inherit|auto))' % csslex.QUANTITY

Definition at line 77 of file cssjanus.py.

◆ POSSIBLY_NEGATIVE_QUANTITY_SPACE

string cssjanus.POSSIBLY_NEGATIVE_QUANTITY_SPACE
Initial value:
1 = r'%s%s%s' % (POSSIBLY_NEGATIVE_QUANTITY,
2  csslex.SPACE,
3  csslex.WHITESPACE)

Definition at line 78 of file cssjanus.py.

◆ RIGHT

string cssjanus.RIGHT = 'right'

Definition at line 49 of file cssjanus.py.

Referenced by Language.getDirMark().

◆ RIGHT_IN_URL_RE

cssjanus.RIGHT_IN_URL_RE
Initial value:
1 = re.compile('%s(%s)%s' % (LOOKBEHIND_NOT_LETTER,
2  RIGHT,
3  LOOKAHEAD_FOR_CLOSING_PAREN),
4  re.I)

Definition at line 166 of file cssjanus.py.

◆ RIGHT_RE

cssjanus.RIGHT_RE
Initial value:
1 = re.compile('%s(%s)%s%s' % (LOOKBEHIND_NOT_LETTER,
2  RIGHT,
3  LOOKAHEAD_NOT_CLOSING_PAREN,
4  LOOKAHEAD_NOT_OPEN_BRACE),
5  re.I)

Definition at line 157 of file cssjanus.py.

◆ RTL

string cssjanus.RTL = 'rtl'

Definition at line 47 of file cssjanus.py.

◆ RTL_IN_URL_RE

cssjanus.RTL_IN_URL_RE
Initial value:
1 = re.compile('%s(%s)%s' % (LOOKBEHIND_NOT_LETTER,
2  RTL,
3  LOOKAHEAD_FOR_CLOSING_PAREN),
4  re.I)

Definition at line 174 of file cssjanus.py.

◆ SWAP_LEFT_RIGHT_IN_URL_DEFAULT

bool cssjanus.SWAP_LEFT_RIGHT_IN_URL_DEFAULT = False

Definition at line 32 of file cssjanus.py.

◆ SWAP_LTR_RTL_IN_URL_DEFAULT

bool cssjanus.SWAP_LTR_RTL_IN_URL_DEFAULT = False

Definition at line 31 of file cssjanus.py.

◆ TMP_TOKEN

string cssjanus.TMP_TOKEN = '%sTMP%s' % (TOKEN_DELIMITER, TOKEN_DELIMITER)

Definition at line 40 of file cssjanus.py.

◆ TOKEN_DELIMITER

string cssjanus.TOKEN_DELIMITER = '~'

Definition at line 37 of file cssjanus.py.

◆ TOKEN_LINES

string cssjanus.TOKEN_LINES = '%sJ%s' % (TOKEN_DELIMITER, TOKEN_DELIMITER)

Definition at line 43 of file cssjanus.py.

◆ VALID_AFTER_URI_CHARS

string cssjanus.VALID_AFTER_URI_CHARS = r'[\'\"]?%s' % csslex.WHITESPACE

Definition at line 68 of file cssjanus.py.