code: def _parseAtMedia(self, src):
          
          ctxsrc = src
          src = src[len('@media '):].lstrip()
          mediums = []
          while src and src[0] != '{':
              medium, src = self._getIdent(src)
              if medium is None:
                  raise self.ParseError('@media rule expected media identifier', src, ctxsrc)
              # make "and ... {" work
              if medium == 'and':
                  # strip up to curly bracket
                  pattern = re.compile('.*({.*)')
                  match = re.match(pattern, src)
                  src = src[match.end()-1:]
                  break
              mediums.append(medium)
              if src[0] == ',':
                  src = src[1:].lstrip()
              else:
                  src = src.lstrip()
  
          if not src.startswith('{'):
              raise self.ParseError('Ruleset opening \'{\' not found', src, ctxsrc)
          src = src[1:].lstrip()
  
          stylesheetElements = []
          #while src and not src.startswith('}'):
          #    src, ruleset = self._parseRuleset(src)
          #    stylesheetElements.append(ruleset)
          #    src = src.lstrip()
  
          # Containing @ where not found and parsed
          while src and not src.startswith('}'):
              if src.startswith('@'):
                  # @media, @page, @font-face
                  src, atResults = self._parseAtKeyword(src)
                  if atResults is not None:
                      stylesheetElements.extend(atResults)
              else:
                  # ruleset
                  src, ruleset = self._parseRuleset(src)
                  stylesheetElements.append(ruleset)
              src = src.lstrip()
  
          if not src.startswith('}'):
              raise self.ParseError('Ruleset closing \'}\' not found', src, ctxsrc)
          else:
              src = src[1:].lstrip()
  
          result = self.cssBuilder.atMedia(mediums, stylesheetElements)
          return src, result
docs: media
          : MEDIA_SYM S* medium [ ',' S* medium ]* '{' S* ruleset* '}' S*
          ;